This is a fine-tuned T5-small model specialized for email summarization. The model can generate both brief (one-line) and detailed (comprehensive) summaries of emails, and is robust to messy, informal inputs with typos and abbreviations.
Two training examples created per email (brief and full summaries)
Data augmentation applied to 50% of examples
How to Use
Installation
pip install transformers torch
Basic Usage
python
1from transformers import T5ForConditionalGeneration, T5Tokenizer
23# Load model and tokenizer4tokenizer = T5Tokenizer.from_pretrained("wordcab/t5-small-email-summarizer")5model = T5ForConditionalGeneration.from_pretrained("wordcab/t5-small-email-summarizer")67# Example email8email ="""Subject: Team Meeting Tomorrow. Body: Hi everyone,
9Just a reminder that we have our weekly team meeting tomorrow at 2 PM EST.
10Please prepare your status updates and any blockers you're facing.
11We'll also discuss the Q4 roadmap. Thanks!"""1213# Generate brief summary14inputs = tokenizer(f"summarize_brief: {email}", return_tensors="pt", max_length=512, truncation=True)15outputs = model.generate(**inputs, max_length=50, num_beams=2)16brief_summary = tokenizer.decode(outputs[0], skip_special_tokens=True)17print(f"Brief: {brief_summary}")1819# Generate full summary20inputs = tokenizer(f"summarize_full: {email}", return_tensors="pt", max_length=512, truncation=True)21outputs = model.generate(**inputs, max_length=150, num_beams=2)22full_summary = tokenizer.decode(outputs[0], skip_special_tokens=True)23print(f"Full: {full_summary}")
Advanced Usage with Long Emails
For emails longer than 512 tokens, consider using chunking:
python
1defsummarize_long_email(email, model, tokenizer, mode="brief"):2# Check if email fits in context3 tokens = tokenizer.encode(email)4iflen(tokens)<=500:# Leave room for prefix5# Direct summarization6 prefix =f"summarize_{mode}:"if mode in["brief","full"]else"summarize:"7 inputs = tokenizer(f"{prefix}{email}", return_tensors="pt", max_length=512, truncation=True)8 outputs = model.generate(**inputs, max_length=150if mode =="full"else50)9return tokenizer.decode(outputs[0], skip_special_tokens=True)1011# For longer emails, use strategic truncation or chunking12# ... implement chunking strategy
Performance Metrics
Evaluation Results
ROUGE-L Score: 0.42
Average inference time: 0.63s (brief), 0.71s (full) on T4 GPU
Coherence score on messy inputs: 80%
Successfully differentiates brief vs full summaries (2.5x length difference)
Robust handling of informal text and typos
Deployment
Using HuggingFace Inference API
python
1import requests
23API_URL ="https://api-inference.huggingface.co/models/wordcab/t5-small-email-summarizer"4headers ={"Authorization":"Bearer YOUR_HF_TOKEN"}56defquery(payload):7 response = requests.post(API_URL, headers=headers, json=payload)8return response.json()910output = query({11"inputs":"summarize_brief: Subject: Meeting. Body: Let's meet tomorrow at 3pm to discuss the project.",12})
Using Text Generation Inference (TGI)
bash
1docker run --gpus all -p 8080:80 \2 -v t5-small-email-summarizer:/model \3 ghcr.io/huggingface/text-generation-inference:latest \4 --model-id wordcab/t5-small-email-summarizer \5 --max-input-length 512\6 --max-total-tokens 662