Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## English to French Translation AI Model
|
| 2 |
+
|
| 3 |
+
This demonstrates training, quantization, and inference of a text translation model from **English to French** using Hugging Face Transformers on CUDA-enabled devices.
|
| 4 |
+
|
| 5 |
+
## 🧠 Model Overview
|
| 6 |
+
|
| 7 |
+
- **Base Model**: `Helsinki-NLP/opus-mt-tc-big-en-fr`
|
| 8 |
+
- **Task**: English to French text translation
|
| 9 |
+
- **Dataset**: [`FrancophonIA/english_french`](https://huggingface.co/datasets/FrancophonIA/english_french)
|
| 10 |
+
- **Framework**: Hugging Face Transformers & Datasets
|
| 11 |
+
- **Accelerator**: CUDA (GPU)
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## 📦 Dependencies
|
| 16 |
+
|
| 17 |
+
Install all required Python packages:
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
pip install torch transformers datasets evaluate sentencepiece
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
# Load Dataset
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
from datasets import load_dataset
|
| 28 |
+
dataset = load_dataset("FrancophonIA/english_french")
|
| 29 |
+
dataset["train"] = dataset["train"].shuffle(seed=42).select(range(60000))
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
## ⚙️ Training Configuration
|
| 33 |
+
Training is done using Seq2SeqTrainer with the following configuration:
|
| 34 |
+
|
| 35 |
+
- **batch_size**: **8**
|
| 36 |
+
|
| 37 |
+
- **epochs**: **3**
|
| 38 |
+
|
| 39 |
+
- **fp16**: **Mixed precision enabled**
|
| 40 |
+
|
| 41 |
+
- **save_strategy**: **Disabled to reduce I/O**
|
| 42 |
+
|
| 43 |
+
- **report_to**: **Disabled (no Weights & Biases)**
|
| 44 |
+
|
| 45 |
+
## 🧊 Model Quantization (CPU Inference)
|
| 46 |
+
|
| 47 |
+
We apply dynamic quantization on the trained model to reduce size and enable CPU inference:
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
quantized_model = torch.quantization.quantize_dynamic(
|
| 51 |
+
model.cpu(), {torch.nn.Linear}, dtype=torch.qint8
|
| 52 |
+
)
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## 📏 Evaluation (Optional)
|
| 56 |
+
The BLEU score section is commented out but can be enabled by:
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from evaluate import load
|
| 60 |
+
|
| 61 |
+
metric = load("sacrebleu")
|
| 62 |
+
score = metric.compute(predictions=predictions, references=references)
|
| 63 |
+
print(f"BLEU Score: {score['score']}")
|
| 64 |
+
```
|