This repository presents a fine-tuned T5-small model for multilingual text translation across English, French, German, Italian, and Portuguese. It includes quantization for efficient inference and speech synthesis support for accessibility.
📝 Problem Statement
The goal is to translate text between English and multiple European languages using a transformer-based model. Instead of using black-box APIs, this project fine-tunes the T5 model on parallel multilingual corpora, enabling offline translation and potential customization.
📊 Dataset
Source: Custom parallel corpus (.txt files) with one-to-one sentence alignments.
Languages Supported:
English
French
German
Italian
Portuguese
Structure:
Each language has a corresponding .txt file.
Lines are aligned by index to form translation pairs.
Example Input Format:
Source: translate English to French: I am a student.
Target: Je suis un étudiant.
1from transformers import T5ForConditionalGeneration, T5Tokenizer
2import torch
34# Load quantized model (float16)5model = T5ForConditionalGeneration.from_pretrained("quantized_model", torch_dtype=torch.float16)6tokenizer = T5Tokenizer.from_pretrained("quantized_model")78# Translation example9source ="translate English to German: How are you?"10inputs = tokenizer(source, return_tensors="pt", padding=True, truncation=True)1112with torch.no_grad():13 outputs = model.generate(**inputs)1415print("Translated:", tokenizer.decode(outputs[0], skip_special_tokens=True))
📈 Performance Metrics
As this project is based on a single-epoch fine-tuning, performance metrics are not explicitly computed. For a production-level system, BLEU or ROUGE scores should be evaluated.
🏋️ Fine-Tuning Details
📚 Dataset Preparation
A total of 5 text files (english.txt, french.txt, etc.)
Each sentence aligned by index for parallel translation.
🔧 Training Configuration
Epochs: 1
Batch size: 4
Max sequence length: 128
Model base:t5-small
Framework: Hugging Face Transformers + PyTorch
Evaluation strategy: 10% test split
🔄 Quantization
Post-training quantization was performed using .half() precision (FP16) to reduce model size and improve inference speed.