See the parent repository for full training logs, ablation studies against
larger variants, and why a 9.3M clean corpus outperformed a 30M noisy
one (data quality > data quantity > capacity).
1# 1. Clone the parent repo for model definition + beam search code
2git clone https://github.com/Euswbnix/Machine_translation
3cd Machine_translation
4pip install -r requirements.txt
5
6# 2. Download the weights + tokenizer from this HF repo
7pip install huggingface_hub
8hf download euswbnix/transformer-wmt14-enfr-base \
9 pytorch_model.bin sentencepiece.model config.json --local-dir hf_model
10
11# 3. Translate
12python examples/load_and_translate.py \
13 --weights hf_model/pytorch_model.bin \
14 --spm hf_model/sentencepiece.model \
15 --config hf_model/config.json \
16 --text "Machine learning is transforming the world."
1import sentencepiece as spm
2import torch
3from src.model import Transformer
4
5# Load the model (shapes come from config.json)
6cfg = json.load(open("config.json"))
7model = Transformer(
8 vocab_size=cfg["vocab_size"], d_model=cfg["d_model"],
9 n_heads=cfg["n_heads"], n_encoder_layers=cfg["n_encoder_layers"],
10 n_decoder_layers=cfg["n_decoder_layers"], d_ff=cfg["d_ff"],
11 dropout=0.0, max_seq_len=cfg["max_seq_len"],
12 share_embeddings=cfg["share_embeddings"], pad_idx=0,
13)
14model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
15model.eval()
1@inproceedings{vaswani2017attention,
2 title={Attention is all you need},
3 author={Vaswani, Ashish and Shazeer, Noam and Parmar, Niki and others},
4 booktitle={NeurIPS},
5 year={2017}
6}