Fine-tuning the T5-small model on the CNN/DailyMail dataset for text summarization using Hugging Face Transformers.
Automatically generate concise news summaries with state-of-the-art Transformers ⚡
- ✅ Preprocessing and tokenization of the dataset
- ✅ Fine-tuning T5-small using
Seq2SeqTrainer - ✅ Evaluation with ROUGE metrics
- ✅ Inference function to generate summaries from any text
- ✅ GPU-friendly (supports mixed precision for faster training)
t5-cnn-dailymail-summarization/
│
├── .gitignore
├── requirements.txt
├── README.md
└── src/
├── train.py # Sets up Trainer and trains the model
├── inference.py # Generates summaries / inference
└── config.py # Stores training\_args and fixed parameters
Follow these steps to set up the project:
# 1️⃣ Clone the repository
git clone https://github.com/<YOUR_USERNAME>/t5-cnn-dailymail-summarization.git
cd t5-cnn-dailymail-summarization
# 2️⃣ Install dependencies
pip install -r requirements.txt
train.pyfine-tunes the T5 model and saves outputs toOUTPUT_DIR.- All parameters and paths are configurable in
src/config.py.
python src/train.py- During training, the model is evaluated using ROUGE scores.
- ROUGE-1, ROUGE-2, and ROUGE-L metrics are computed and displayed automatically.
- Generate summaries using the trained model:
python src/inference.py- Example usage inside
inference.py:
from src.inference import generate_summary
text = "The Apollo program was the third United States human spaceflight program..."
summary = generate_summary(text)
print(summary)- Python >= 3.9
- PyTorch >= 2.0
- transformers >= 4.30
- datasets >= 2.13
- evaluate >= 0.4
- numpy, pandas, scikit-learn, tqdm, accelerate
Here is an example of T5 generating a concise summary from a news article:
