Add Seq2Seq Encoder-Decoder GRU with Luong Attention trained on Multi30K
Browse files- .gitattributes +1 -0
- README.md +87 -0
- best_seq2seq_luong.safetensors +3 -0
- config.json +24 -0
- en_de_luong_loss.png +3 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
en_de_luong_loss.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
license: mit
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
- de
|
| 7 |
+
library_name: pytorch
|
| 8 |
+
pipeline_tag: translation
|
| 9 |
+
tags:
|
| 10 |
+
- pytorch
|
| 11 |
+
- gru
|
| 12 |
+
- seq2seq
|
| 13 |
+
- luong
|
| 14 |
+
- machine-translation
|
| 15 |
+
- multi30k
|
| 16 |
+
datasets:
|
| 17 |
+
- bentrevett/multi30k
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Seq2Seq GRU Translator (English -> German)
|
| 21 |
+
|
| 22 |
+
A PyTorch Seq2Seq Encoder-Decoder GRU with Luong Attention trained from scratch on the Multi30k dataset.
|
| 23 |
+
|
| 24 |
+
## Model Details
|
| 25 |
+
|
| 26 |
+
- Architecture: Seq2Seq Encoder-Decoder GRU with Luong Attention
|
| 27 |
+
- Framework: PyTorch
|
| 28 |
+
- Dataset: Multi30k (English -> German)
|
| 29 |
+
- Embedding Dimension: 128
|
| 30 |
+
- Hidden Dimension: 256
|
| 31 |
+
|
| 32 |
+
## Training
|
| 33 |
+
|
| 34 |
+
- Optimizer: Adam
|
| 35 |
+
- Learning Rate: 1e-3
|
| 36 |
+
- Loss: CrossEntropyLoss (ignore_index=PAD)
|
| 37 |
+
- Gradient Clipping: max_norm=1.0
|
| 38 |
+
- Epochs: 50
|
| 39 |
+
- Batch Size: 64
|
| 40 |
+
|
| 41 |
+
## Dataset
|
| 42 |
+
|
| 43 |
+
| Split | Samples |
|
| 44 |
+
|------|--------:|
|
| 45 |
+
| Train | 29,000 |
|
| 46 |
+
| Validation | 1,014 |
|
| 47 |
+
| Test | 1,000 |
|
| 48 |
+
|
| 49 |
+
## Performance
|
| 50 |
+
|
| 51 |
+
| Metric | Value |
|
| 52 |
+
|------|------:|
|
| 53 |
+
| Train Loss | 0.42 |
|
| 54 |
+
| Validation Loss | 5.17 |
|
| 55 |
+
| Test Loss | 3.26 |
|
| 56 |
+
| BLEU | 27.13 |
|
| 57 |
+
|
| 58 |
+

|
| 59 |
+
|
| 60 |
+
## Usage
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
# Load model
|
| 64 |
+
model = Seq2Seq(encoder, decoder, device)
|
| 65 |
+
|
| 66 |
+
model.load_state_dict(
|
| 67 |
+
load_file("best_seq2seq_luong.safetensors")
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
model.eval()
|
| 71 |
+
|
| 72 |
+
# Inference
|
| 73 |
+
sentence = "A man is riding a bicycle."
|
| 74 |
+
|
| 75 |
+
translation = translate_sentence(
|
| 76 |
+
sentence,
|
| 77 |
+
model
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
print(" ".join(translation))
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Author
|
| 84 |
+
Ankit Bari
|
| 85 |
+
|
| 86 |
+
GitHub: https://github.com/aijadugar
|
| 87 |
+
Hugging Face: https://huggingface.co/aijadugar
|
best_seq2seq_luong.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e285bd2be7604bb0f563100c8dc1f1049008ce27d86c991fec1bd15874a17a9f
|
| 3 |
+
size 17984272
|
config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_name": "Seq2Seq Encoder-Decoder GRU with Luong Attention",
|
| 3 |
+
"task": "translation",
|
| 4 |
+
"framework": "PyTorch",
|
| 5 |
+
"dataset": "bentrevett/multi30k",
|
| 6 |
+
"src_lang": "en",
|
| 7 |
+
"tgt_lang": "de",
|
| 8 |
+
"src_vocab_size": 5968,
|
| 9 |
+
"tgt_vocab_size": 7812,
|
| 10 |
+
"architecture": {
|
| 11 |
+
"type": "Seq2Seq",
|
| 12 |
+
"cell": "GRU",
|
| 13 |
+
"emb_dim": 128,
|
| 14 |
+
"hidden_dim": 256
|
| 15 |
+
},
|
| 16 |
+
"training": {
|
| 17 |
+
"optimizer": "Adam",
|
| 18 |
+
"learning_rate": 0.001,
|
| 19 |
+
"loss": "CrossEntropyLoss",
|
| 20 |
+
"grad_clip_norm": 1.0,
|
| 21 |
+
"epochs": 50,
|
| 22 |
+
"batch_size": 64
|
| 23 |
+
}
|
| 24 |
+
}
|
en_de_luong_loss.png
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
torch
|
| 3 |
+
datasets
|
| 4 |
+
matplotlib
|
| 5 |
+
tqdm
|
| 6 |
+
nltk
|
| 7 |
+
safetensors
|