Fine-tunes DistilGPT-2 on a conversation dataset and compares base vs fine-tuned text generation.
This project fine-tunes a DistilGPT-2 language model on the HuggingFace UltraFeedback dataset and compares text generation between the original base model and the fine-tuned version. The script first trains the model for 3 epochs on 10 000 prompts, saves the checkpoint, then reloads both models to ensure a fair comparison. Task 1 generates 5 alternative completions per prompt using both models side by side. Task 2 uses a HuggingFace pipeline with the fine-tuned model to produce ranked completions.
- Python 3.8+
- transformers >= 4.30
- datasets >= 2.12
- tensorflow >= 2.12
pip install -r requirements.txtdistilgpt2-text-generation/
├── generate_text.py # Fine-tuning and text generation script
├── requirements.txt # Python dependencies
├── .gitignore
└── README.md
python generate_text.pySteps performed:
- Downloads the DistilGPT-2 model and the UltraFeedback dataset from HuggingFace.
- Fine-tunes the model for 3 epochs on 10 000 conversation prompts.
- Reloads a fresh base model and the saved fine-tuned checkpoint.
- Task 1: generates 5 completions per prompt for both base and fine-tuned models; prints comparison dictionary to stdout.
- Task 2: runs a text-generation pipeline with the fine-tuned model on 3 prompts; prints ranked completions to stdout.
All output is printed to stdout. Task 1 produces a nested dictionary keyed by prompt, with not_tuned and tuned sub-dictionaries each containing 5 generated completions. Task 2 produces ranked completion lists per prompt. The fine-tuned model reflects the conversational style present in the UltraFeedback training data.
Biswajeet Sahoo
MIT License