A small English→Russian Transformer, trained from scratch
Built in lesson 3 of the course "Transformers: from scratch to production": https://github.com/xmarva/transformers-from-scratch
- the encoder-decoder Transformer of Vaswani et al. (2017) at half its base size
- 3 + 3 layers, 4 heads, d_model 256
- trained on xmarva/tfs-tatoeba-en-ru with the tokenizer xmarva/tfs-bpe-en-ru-16k
- best validation cross-entropy: 1.063
The model class is tfs.model.Transformer from the course repository:
# pip install git+https://github.com/xmarva/transformers-from-scratch
import json
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from tfs.model import Transformer
repo = "xmarva/tfs-transformer-en-ru"
with open(hf_hub_download(repo, "config.json")) as f:
model = Transformer(**json.load(f))
model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
Lesson 3 shows how to translate with it, greedily or with beam search.