Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# t5-small Quantized Model for Text Summarization on Reddit-TIFU dataset
|
3 |
+
|
4 |
+
This repository hosts a quantized version of the t5-small model, fine-tuned for text summarization using the Reddit-TIFU dataset. The model has been optimized using FP16 quantization for efficient deployment without significant accuracy loss.
|
5 |
+
|
6 |
+
## Model Details
|
7 |
+
|
8 |
+
- **Model Architecture:** t5-small(short version)
|
9 |
+
- **Task:** Text generation
|
10 |
+
- **Dataset:** Reddit-TIFU (Hugging Face Datasets)
|
11 |
+
- **Quantization:** Float16
|
12 |
+
- **Fine-tuning Framework:** Hugging Face Transformers
|
13 |
+
|
14 |
+
---
|
15 |
+
|
16 |
+
## Installation
|
17 |
+
|
18 |
+
```bash
|
19 |
+
pip install datasets transformers rouge-score evaluate
|
20 |
+
```
|
21 |
+
|
22 |
+
---
|
23 |
+
|
24 |
+
## Loading the Model
|
25 |
+
|
26 |
+
```python
|
27 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
28 |
+
import torch
|
29 |
+
|
30 |
+
# Load tokenizer and model
|
31 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
32 |
+
model_name = "t5-small"
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
|
35 |
+
|
36 |
+
# Define test sentences
|
37 |
+
new_text = """
|
38 |
+
Today I was late to my morning meeting because I spilled coffee all over my laptop.
|
39 |
+
Then I realized my backup laptop was also out of battery.
|
40 |
+
Eventually joined from my phone, only to find out the meeting was cancelled.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# Generate
|
44 |
+
def generate_summary(text):
|
45 |
+
inputs = tokenizer(
|
46 |
+
text,
|
47 |
+
return_tensors="pt",
|
48 |
+
max_length=512,
|
49 |
+
truncation=True
|
50 |
+
).to(device)
|
51 |
+
|
52 |
+
summary_ids = model.generate(
|
53 |
+
inputs["input_ids"],
|
54 |
+
max_length=100,
|
55 |
+
min_length=5,
|
56 |
+
num_beams=4,
|
57 |
+
length_penalty=2.0,
|
58 |
+
early_stopping=True
|
59 |
+
)
|
60 |
+
|
61 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
62 |
+
return summary
|
63 |
+
```
|
64 |
+
|
65 |
+
---
|
66 |
+
|
67 |
+
## Performance Metrics
|
68 |
+
|
69 |
+
- **Rouge1:** 19.590
|
70 |
+
- **Rouge2:** 4.270
|
71 |
+
- **Rougel:** 16.390
|
72 |
+
- **Rougelsum:** 16.800
|
73 |
+
|
74 |
+
---
|
75 |
+
|
76 |
+
## Fine-Tuning Details
|
77 |
+
|
78 |
+
### Dataset
|
79 |
+
|
80 |
+
The dataset is sourced from Hugging Faceβs `Reddit-TIFU` dataset. It contains 79,000 reddit post and their summaries.
|
81 |
+
The original training and testing sets were merged, shuffled, and re-split using an 90/10 ratio.
|
82 |
+
|
83 |
+
### Training
|
84 |
+
|
85 |
+
- **Epochs:** 3
|
86 |
+
- **Batch size:** 8
|
87 |
+
- **Learning rate:** 2e-5
|
88 |
+
- **Evaluation strategy:** `epoch`
|
89 |
+
|
90 |
+
---
|
91 |
+
|
92 |
+
## Quantization
|
93 |
+
|
94 |
+
Post-training quantization was applied using PyTorchβs `half()` precision (FP16) to reduce model size and inference time.
|
95 |
+
|
96 |
+
---
|
97 |
+
|
98 |
+
## Repository Structure
|
99 |
+
|
100 |
+
```python
|
101 |
+
.
|
102 |
+
βββ quantized-model/ # Contains the quantized model files
|
103 |
+
β βββ config.json
|
104 |
+
β βββ model.safetensors
|
105 |
+
β βββ tokenizer_config.json
|
106 |
+
β βββ spiece.model
|
107 |
+
β βββ special_tokens_map.json
|
108 |
+
β βββ generation_config.jason
|
109 |
+
β βββ tokenizer.json
|
110 |
+
|
111 |
+
βββ README.md # Model documentation
|
112 |
+
```
|
113 |
+
|
114 |
+
---
|
115 |
+
|
116 |
+
## Limitations
|
117 |
+
|
118 |
+
- The model is trained specifically for text summarization on reddit posts
|
119 |
+
- FP16 quantization may result in slight numerical instability in edge cases.
|
120 |
+
|
121 |
+
|
122 |
+
---
|
123 |
+
|
124 |
+
## Contributing
|
125 |
+
|
126 |
+
Feel free to open issues or submit pull requests to improve the model or documentation.
|