Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Text-to-Text Transfer Transformer (T5) Quantized Model for Text Translation
|
2 |
+
|
3 |
+
This repository hosts a quantized version of the T5 model, fine-tuned for text translation tasks. The model has been optimized for efficient deployment while maintaining high accuracy, making it suitable for resource-constrained environments.
|
4 |
+
|
5 |
+
## Model Details
|
6 |
+
- **Model Architecture:** T5
|
7 |
+
- **Task:** Text Translation
|
8 |
+
- **Dataset:** Hugging Face's `opus100`
|
9 |
+
- **Quantization:** Float16
|
10 |
+
- **Supporting Languages:** English to French
|
11 |
+
- **Fine-tuning Framework:** Hugging Face Transformers
|
12 |
+
|
13 |
+
## Usage
|
14 |
+
### Installation
|
15 |
+
```sh
|
16 |
+
pip install transformers torch
|
17 |
+
```
|
18 |
+
|
19 |
+
### Loading the Model
|
20 |
+
```python
|
21 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
22 |
+
import torch
|
23 |
+
|
24 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
+
|
26 |
+
model_name = "AventIQ-AI/t5-text-translator"
|
27 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
28 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
|
29 |
+
|
30 |
+
def translate_text(model, text, src_lang, tgt_lang):
|
31 |
+
input_text = f"translate {src_lang} to {tgt_lang}: {text}"
|
32 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
33 |
+
|
34 |
+
# Generate translation
|
35 |
+
output_ids = model.generate(input_ids, max_length=50)
|
36 |
+
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
37 |
+
|
38 |
+
# Test Example
|
39 |
+
test_sentences = {"en-fr": "Hello, what is your approach?"}
|
40 |
+
|
41 |
+
for lang_pair, sentence in test_sentences.items():
|
42 |
+
src, tgt = lang_pair.split("-")
|
43 |
+
print(f"{src} β {tgt}: {translate_text(model, sentence, src, tgt)}")
|
44 |
+
```
|
45 |
+
|
46 |
+
## π ROUGE Evaluation Results
|
47 |
+
After fine-tuning the T5-Small model for text translation, we obtained the following ROUGE scores:
|
48 |
+
|
49 |
+
| **Metric** | **Score** | **Meaning** |
|
50 |
+
|------------|---------|--------------------------------------------------------------|
|
51 |
+
| **ROUGE-1** | 0.4673 (~46%) | Measures overlap of unigrams (single words) between the reference and generated text. |
|
52 |
+
| **ROUGE-2** | 0.2486 (~24%) | Measures overlap of bigrams (two-word phrases), indicating coherence and fluency. |
|
53 |
+
| **ROUGE-L** | 0.4595 (~45%) | Measures longest matching word sequences, testing sentence structure preservation. |
|
54 |
+
| **ROUGE-Lsum** | 0.4620 (~46%) | Similar to ROUGE-L but optimized for summarization tasks. |
|
55 |
+
|
56 |
+
## Fine-Tuning Details
|
57 |
+
### Dataset
|
58 |
+
The Hugging Face's `opus100` dataset was used, containing different types of translations of languages.
|
59 |
+
|
60 |
+
### Training
|
61 |
+
- **Number of epochs:** 3
|
62 |
+
- **Batch size:** 8
|
63 |
+
- **Evaluation strategy:** epoch
|
64 |
+
|
65 |
+
### Quantization
|
66 |
+
Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
|
67 |
+
|
68 |
+
## Repository Structure
|
69 |
+
```
|
70 |
+
.
|
71 |
+
βββ model/ # Contains the quantized model files
|
72 |
+
βββ tokenizer_config/ # Tokenizer configuration and vocabulary files
|
73 |
+
βββ model.safetensors/ # Quantized Model
|
74 |
+
βββ README.md # Model documentation
|
75 |
+
```
|
76 |
+
|
77 |
+
## Limitations
|
78 |
+
- The model may not generalize well to domains outside the fine-tuning dataset.
|
79 |
+
- Currently, it only supports English to French translations.
|
80 |
+
- Quantization may result in minor accuracy degradation compared to full-precision models.
|
81 |
+
|
82 |
+
## Contributing
|
83 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
|