This project implements a neural machine translation system for translating English text to Hindi using a sequence-to-sequence (Seq2Seq) architecture with attention mechanism. The model is built with PyTorch and features a GRU-based encoder-decoder network.
- Seq2Seq architecture with attention mechanism
- GRU-based encoder and decoder
- Customizable model parameters (hidden size, embedding dimensions, etc.)
- Interactive translation through command line interface
- Web interface using Gradio
- Support for vocabulary management and data preprocessing
- Teacher forcing during training
├── app.py # Gradio web interface for translation
├── inference.py # Functions for model inference
├── train.py # Model training script
├── models/ # Neural network architecture components
│ ├── encoder.py # Encoder implementation
│ ├── decoder.py # Decoder implementation
│ ├── attention.py # Attention mechanism
│ └── seq2seq.py # Seq2Seq model
├── utils/ # Utility functions
│ ├── config.py # Configuration parameters
│ ├── data_loader.py # Data loading utilities
│ └── preprocessing.py # Text preprocessing functions
├── data/ # Data directory
│ └── hindi_english_parallel.csv # Parallel corpus
└── bin/ # Model checkpoints and vocabularies
├── seq2seq.pth # Trained model weights
├── eng_vocab.pkl # English vocabulary
└── hin_vocab.pkl # Hindi vocabulary
- Clone the repository:
git clone https://github.com/yourusername/english-hindi-translator.git
cd english-hindi-translator- Install the required packages:
pip install -r requirment.txtTo train the translation model:
python train.pyThis will:
- Load and preprocess the Hindi-English parallel corpus
- Build vocabularies for both languages
- Initialize and train the Seq2Seq model
- Save model checkpoints after each epoch
For interactive translation through command line:
python inference.pyTo launch the web interface for translation:
python app.pyThis will start a Gradio interface that you can access in your web browser.
- Encoder: GRU-based with configurable layers and embedding dimensions
- Decoder: GRU with attention mechanism
- Attention: Calculates attention scores between encoder outputs and decoder hidden states
- Training: Uses teacher forcing and cross-entropy loss
Model parameters can be adjusted in the config.py file:
embedding_dim: Size of word embeddingshidden_size: Size of hidden layersnum_layers: Number of RNN layersdropout: Dropout ratebatch_size: Training batch sizelearning_rate: Learning rate for optimizerepochs: Number of training epochsteacher_forcing_ratio: Ratio of teacher forcing during trainingmax_vocab_english: Maximum size of English vocabularymax_vocab_hindi: Maximum size of Hindi vocabularymax_length: Maximum sentence length
- torch
- pandas
- numpy
- tqdm
- gradio