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