Build a model/pipeline to convert an informal sentence into a formal one and vice versa.
- T5 Fine-tuned Model:
prithivida/informal_to_formal_styletransferfrom Hugging Face Transformers for informal-to-formal conversion. - gpt-4o-mini: Use prompting with gpt-4o-mini for sentence style transfer.
Clone or download this repository to your local machine.
Navigate to the project directory and run:
python3 -m venv venv
source venv/bin/activateWith the virtual environment activated, install all required packages:
pip install --upgrade pip
pip install torch transformers openai python-dotenv nltk streamlitCreate a .env file in the project root with the following content:
OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Replace xxxxxxxx... with your actual OpenAI API key.
Open sentence_style_transfer.ipynb in Jupyter or VS Code. Make sure the kernel/interpreter is set to the Python from your venv (see VS Code's top-right kernel picker).
Run all cells sequentially. The notebook will:
- Import libraries
- Load the T5 model
- Provide an inference pipeline
- Evaluate BLEU score
- Allow you to test custom sentences
To launch the web interface:
streamlit run style_transfer_streamlit.pyThe app will open in your browser at http://localhost:8501
- Python 3.8+
transformers,datasets,torch,evaluate,pandas,numpy
Run the UI script for a simple web interface:
python style_transfer_ui.py