This repository contains a Sequence-to-Sequence (Seq2Seq) neural machine translation model for translating from French to English, along with inference utilities.
- seq2seq.ipynb - Main training notebook for the Seq2Seq model with attention mechanism
- inference.ipynb - Inference notebook for generating translations using trained models
- fra.csv - Test Data for inference
- tatoeba/eng-fra.txt - Train Data from Tatoeba with english and french sentences
This project implements a neural machine translation system using:
- Encoder-Decoder Architecture with attention mechanism
- Bidirectional GRU encoder
- GRU-based Decoder with attention
The model is trained on French-English parallel text data and supports both training and inference workflows.
- Python 3.7+
- PyTorch
- pandas
- tqdm
Install dependencies:
pip install torch pandas tqdm-
Prepare training data in TSV format (source \t target)
-
Configure hyperparameters:
- Embedding dimension
- Hidden dimension
- Number of layers
- Dropout rate
- Learning rate
- Batch size
-
Run the notebook cells to:
- Load and preprocess data
- Build vocabularies
- Initialize and train the model
- Save trained weights
- Load pre-trained model weights and vocabularies
- Provide input sentences for translation
- Generate translations using beam search or greedy decoding
Example:
input_sentence = "Comment allez-vous?"
translation = translate(input_sentence)
print(translation) # "How are you?"Training data should be in TSV format:
French sentence English sentence
Bonjour Hello
Comment allez-vous? How are you?
- Embedding layer
- Bidirectional GRU (2 layers)
- Linear projection layer
- Embedding layer
- GRU with attention
- Output projection layer
- Luong-style attention
- Scores computed over encoder outputs