| ## 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']}") | |
| ``` | |