https://github.com/nullhawk/translator
RNN Based Seq2Seq Model to Translate English to Hindi
https://github.com/nullhawk/translator
nmt rnn seq2seq
Last synced: 7 months ago
JSON representation
RNN Based Seq2Seq Model to Translate English to Hindi
- Host: GitHub
- URL: https://github.com/nullhawk/translator
- Owner: nullHawk
- Created: 2025-06-04T23:36:20.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-10T03:54:56.000Z (7 months ago)
- Last Synced: 2025-06-10T04:31:54.485Z (7 months ago)
- Topics: nmt, rnn, seq2seq
- Language: Python
- Homepage: https://huggingface.co/spaces/nullHawk/english-hindi_translator
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# English to Hindi Neural Machine Translator
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.
## Features
- 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
## Project Structure
```
├── 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
```
## Installation
1. Clone the repository:
```bash
git clone https://github.com/yourusername/english-hindi-translator.git
cd english-hindi-translator
```
2. Install the required packages:
```bash
pip install -r requirment.txt
```
## Usage
### Training the Model
To train the translation model:
```bash
python train.py
```
This 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
### Translation via Command Line
For interactive translation through command line:
```bash
python inference.py
```
### Web Interface
To launch the web interface for translation:
```bash
python app.py
```
This will start a Gradio interface that you can access in your web browser.
## Model Architecture
- **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
## Configuration
Model parameters can be adjusted in the config.py file:
- `embedding_dim`: Size of word embeddings
- `hidden_size`: Size of hidden layers
- `num_layers`: Number of RNN layers
- `dropout`: Dropout rate
- `batch_size`: Training batch size
- `learning_rate`: Learning rate for optimizer
- `epochs`: Number of training epochs
- `teacher_forcing_ratio`: Ratio of teacher forcing during training
- `max_vocab_english`: Maximum size of English vocabulary
- `max_vocab_hindi`: Maximum size of Hindi vocabulary
- `max_length`: Maximum sentence length
## Requirements
- torch
- pandas
- numpy
- tqdm
- gradio