Updating Model Card
Browse files
README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- translation
|
| 5 |
+
- pytorch
|
| 6 |
+
- encoder-decoder
|
| 7 |
+
- transformer
|
| 8 |
+
- english-to-hindi
|
| 9 |
+
- nmt
|
| 10 |
+
library_name: pytorch
|
| 11 |
+
language:
|
| 12 |
+
- en
|
| 13 |
+
- hi
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# TransformerNMT: English-to-Hindi Experimental Transformer Model
|
| 17 |
+
|
| 18 |
+
This repository contains a **Transformer Encoder-Decoder** model implemented from scratch in PyTorch for English-to-Hindi neural machine translation. The model and all training, preprocessing, and inference scripts are custom and do **not** use Hugging Face Transformers, but follow the original "Attention is All You Need" architecture.
|
| 19 |
+
|
| 20 |
+
## Model Details
|
| 21 |
+
|
| 22 |
+
- **Architecture:** Transformer Encoder-Decoder (Vaswani et al., 2017)
|
| 23 |
+
- **Framework:** PyTorch
|
| 24 |
+
- **Languages:** English (source) → Hindi (target)
|
| 25 |
+
- **Vocabulary:** 32,000 BPE tokens per language (trained with `tokenizers`)
|
| 26 |
+
- **Training Data:** Parallel English-Hindi corpus (see repo for data details)
|
| 27 |
+
- **Intended Use:** Research, experimentation, and educational purposes
|
| 28 |
+
|
| 29 |
+
## Training
|
| 30 |
+
|
| 31 |
+
- Trained from scratch using the scripts in this repository.
|
| 32 |
+
- Supports distributed and mixed-precision training.
|
| 33 |
+
- Checkpoints and tokenizer files are provided in the `models/` and `Data/bi_tokenizers_32k/` directories.
|
| 34 |
+
|
| 35 |
+
## Intended Uses & Limitations
|
| 36 |
+
|
| 37 |
+
- **Intended for:** Experimentation, research, and demonstration of custom Transformer implementations.
|
| 38 |
+
- **Not intended for:** Production use or high-stakes applications.
|
| 39 |
+
- **Limitations:** May not achieve state-of-the-art translation quality. Use with caution for real-world tasks.
|
| 40 |
+
|
| 41 |
+
## Example Inference
|
| 42 |
+
|
| 43 |
+
Below is a simple inference script to translate English text to Hindi using the trained model and tokenizer:
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import torch
|
| 47 |
+
from tokenizer import BilingualTokenizer as Tokenizer
|
| 48 |
+
from model import Transformer, TransformerConfig
|
| 49 |
+
from translator import TranslationInference
|
| 50 |
+
|
| 51 |
+
# 1. Load config and checkpoint
|
| 52 |
+
config = TransformerConfig(shared_embeddings=True)
|
| 53 |
+
checkpoint = torch.load('models/TNMT_v1_Beta_single.pt', map_location='cpu')
|
| 54 |
+
|
| 55 |
+
# 2. Build model and load weights
|
| 56 |
+
model = Transformer(config)
|
| 57 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 58 |
+
model = model.to('cpu')
|
| 59 |
+
|
| 60 |
+
# 3. Load tokenizer
|
| 61 |
+
tokenizer = Tokenizer(vocab_size=32000)
|
| 62 |
+
tokenizer_loaded = tokenizer.load_tokenizers('bi_tokenizers_32k')
|
| 63 |
+
|
| 64 |
+
# 4. Create inference helper
|
| 65 |
+
translator = TranslationInference(
|
| 66 |
+
model=model,
|
| 67 |
+
tokenizer=tokenizer_loaded,
|
| 68 |
+
device='cpu'
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# 5. Translate
|
| 72 |
+
source_text = "This is a test sentence."
|
| 73 |
+
translated_text = translator.translate_text(source_text)
|
| 74 |
+
print("Translated text:", translated_text)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## Citation
|
| 78 |
+
|
| 79 |
+
If you use this code or model, please cite:
|
| 80 |
+
|
| 81 |
+
> Vaswani et al., "Attention is All You Need", NeurIPS 2017.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
**Author:** [Your Name or Organization]
|
| 86 |
+
**License:** MIT
|