Level 5 · research · ~60 h
Reproduce Attention Is All You Need on a small corpus
Implement the full encoder-decoder Transformer from Vaswani et al. (2017) and reproduce its translation quality on a small WMT14 English-German subset, including the original learning-rate schedule, label smoothing and beam search.
Problem statement
- 01Implement the full encoder-decoder Transformer from Vaswani et al. (2017) and reproduce its translation quality on a small WMT14 English-German subset, including the original learning-rate schedule, label smoothing and beam search.
Real-world motivation
- 01The paper defines the architecture behind modern foundation models; reproducing it forces you to get every implementation detail right, and the gap between a near-reproduction and the reported BLEU is itself a research result.
Learning objectives
- 01Implement multi-head scaled dot-product attention, positional encoding, encoder and decoder stacks from scratch
- 02Reproduce the original schedule with warmup and label smoothing=0.1
- 03Match the reported BLEU within 2 points on a small-data configuration and document every deviation
Technical architecture
- 016 encoder and 6 decoder layers, d_model=512, 8 heads, d_ff=2048
- 02sinusoidal positional encodings and masked decoder self-attention
- 03AdamW with beta2=0.98, eps=1e-9, inverse-sqrt warmup over 4000 steps
Mathematical foundations
- 01$\mathrm{Attention}(Q,K,V)=\mathrm{softmax}(QK^\top/\sqrt{d_k})V$
- 02$lr= d_{model}^{-0.5}\min(step^{-0.5}, step\cdot warmup^{-1.5})$
- 03loss $=-(1-\epsilon)\log p(y_t)-\epsilon/K$ with label smoothing $\epsilon=0.1$
Dataset and sources
- 01WMT14 En-De (small subset, 100k sentence pairs)
- 02WikiText-103 for an auxiliary language-model sanity check
Step-by-step tasks
- 01Implement and unit-test scaled dot-product attention against a naive reference
- 02Build positional encoding and verify periodicity numerically
- 03Implement encoder and decoder layers with residual dropout
- 04Implement the schedule and label-smoothed loss
- 05Train on the subset for the full schedule with checkpointing
- 06Decode with beam search width 4 and length penalty 0.6
- 07Ablate warmup, label smoothing and positional encoding
Implementation requirements
- 01Write attention, sublayers and the full model in PyTorch without nn.Transformer
- 02Use SentencePiece subwords with a shared source-target vocabulary
- 03Log gradient norm, learning rate and token throughput every 100 steps
Testing requirements
- 01Compare attention output with a hand-computed 2x2 example
- 02Verify causal masking blocks future tokens exactly
- 03Run a 10-batch overfit test to near-zero loss
Evaluation metrics
- 01BLEU (sacreBLEU)
- 02token-level accuracy
- 03tokens per second
- 04label smoothing ablation delta
Expected outputs
- 01trained checkpoint
- 02reproduction report with a deviation table
- 03beam-search decoder
- 04ablation figures
Common failure modes
- 01warmup too short causes early divergence
- 02label smoothing applied to padding tokens corrupts the loss
- 03beam search without length normalization favors short outputs
Stretch goals
- 01implement relative positional encodings
- 02compare with a pretrained baseline on the same subset
Research extensions
- 01measure how BLEU changes with data size and extrapolate
- 02study attention-head specialization with head pruning ablations
GitHub submission requirements
- 01Repository with model code, training script and unit tests
- 02README with exact hyperparameters and seeds
- 03Report with the reproduction gap and an ablation table
- 04BLEU logs and sample translations
Completion rubric
- 01attention implementation verified numerically
- 02schedule and label smoothing exactly reproduced
- 03BLEU within 2 points of the reference small-data setting
- 04every deviation documented
- 05ablation with three controlled changes
Submit when every rubric item is satisfied and your repository contains runnable code plus a reproduction command.