CoolFace
Modelpublic

arykarki/seq2seq-en-es

sourceHugging Facemitupdated 2y agoView on Hugging Face
3likes
Model Card

Neural Machine Translation with Attention ๐Ÿš€

A PyTorch implementation of a Sequence-to-Sequence model with Attention for English-Spanish translation.

Python PyTorch License

๐ŸŒŸ Features

  • โ€”Bidirectional GRU Encoder: Captures context from both directions of the input sequence
  • โ€”Attention Mechanism: Helps the model focus on relevant parts of the input sequence
  • โ€”Teacher Forcing: Implements curriculum learning for better training stability
  • โ€”Dynamic Batching: Efficient training with variable sequence lengths
  • โ€”Hugging Face Integration: Uses MarianTokenizer for robust text processing

๐Ÿ—๏ธ Architecture

The model consists of three main components:

  1. 1.Encoder: Bidirectional GRU network that processes input sequences
  2. 2.Attention: Computes attention weights for each encoder state
  3. 3.Decoder: GRU network that generates translations using attention context
plaintext
Input โ†’ Encoder โ†’ Attention โ†’ Decoder โ†’ Translation
      โ†‘          โ†‘          โ†‘
      Embeddings Context    Attention Weights

๐Ÿš€ Quick Start

  1. 1.Clone the repository:
bash
git clone https://github.com/yourusername/nmt-attention.git
cd nmt-attention
  1. 1.Install dependencies:
bash
pip install torch transformers datasets
  1. 1.Train the model:
python
python train.py
  1. 1.Translate text:
python
from translate import translate
text = "How are you?"
translated = translate(model, text, tokenizer)
print(translated)

# Loading a saved model
model = Seq2Seq(encoder, decoder, device)
model.load_state_dict(torch.load('LSTM_text_generator.pth'))
model.eval()

๐Ÿ“Š Model Performance

Training metrics after 10 epochs:

  • โ€”Initial Loss: 11.147
  • โ€”Final Loss: 3.527
  • โ€”Training Time: ~2 hours on NVIDIA V100

๐Ÿ”ง Hyperparameters

python
BATCH_SIZE = 32
LEARNING_RATE = 1e-3
CLIP = 1.0
N_EPOCHS = 10
ENC_EMB_DIM = 256
DEC_EMB_DIM = 256
ENC_HID_DIM = 512
DEC_HID_DIM = 512

๐Ÿ“š Dataset

Using the loresiensis/corpus-en-es dataset from Hugging Face Hub, which provides English-Spanish sentence pairs for training.

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create your feature branch (git checkout -b feature/amazing-feature)
  3. 3.Commit your changes (git commit -m 'Add amazing feature')
  4. 4.Push to the branch (git push origin feature/amazing-feature)
  5. 5.Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • โ€”Attention Is All You Need paper
  • โ€”Hugging Face for the transformers library and datasets
  • โ€”PyTorch team for the amazing deep learning framework

โญ๏ธ If you found this project helpful, please consider giving it a star!