Views
No views yet
pip install transformers torch1from transformers import T5Tokenizer, T5ForConditionalGeneration
2import torch
3
4device = "cuda" if torch.cuda.is_available() else "cpu"
5
6model_name = "AventIQ-AI/t5-text-summarizer"
7tokenizer = T5Tokenizer.from_pretrained(model_name)
8model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
9
10def test_summarization(model, tokenizer):
11 user_text = input("\nEnter your text for summarization:\n")
12 input_text = "summarize: " + user_text
13 inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512).to(device)
14
15 output = model.generate(
16 **inputs,
17 max_new_tokens=100,
18 num_beams=5,
19 length_penalty=0.8,
20 early_stopping=True
21 )
22
23 summary = tokenizer.decode(output[0], skip_special_tokens=True)
24 return summary
25
26print("\n📝 **Quantized Model Summary:**")
27print(test_summarization(model, tokenizer))| Metric | Score | Meaning |
|---|---|---|
| ROUGE-1 | 0.3061 (~30%) | Measures overlap of unigrams (single words) between the reference and generated summary. |
| ROUGE-2 | 0.1241 (~12%) | Measures overlap of bigrams (two-word phrases), indicating coherence and fluency. |
| ROUGE-L | 0.2233 (~22%) | Measures longest matching word sequences, testing sentence structure preservation. |
| ROUGE-Lsum | 0.2620 (~26%) | Similar to ROUGE-L but optimized for summarization tasks. |
cnn_dailymail dataset was used, containing the text and their summarization examples..
├── model/ # Contains the quantized model files
├── tokenizer_config/ # Tokenizer configuration and vocabulary files
├── model.safetensors/ # Quantized Model
├── README.md # Model documentation