Transformers and LLMs · 2017

Attention Is All You Need

Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin

NeurIPS 2017 · arXiv 1706.03762 · Read the paper ↗

The paper that replaced recurrence with attention. Every modern LLM is a stack of the blocks you build here.

8 steps · 0 solved

Start: Positional encoding →
  1. 1Positional encodingInject token order with fixed sine and cosine waves.Generate sinusoidal position encodingsEasy
  2. 2Scaled dot-product attentionScore queries against keys, scale by sqrt(d_k), mask, softmax, mix values.GPT decoder: causal self-attention for one headMedium
  3. 3Split and merge headsReshape one projection into h heads and back.Split and merge attention headsMedium
  4. 4Multi-head attentionRun attention in parallel heads, for self and cross attention.Write multi-head attention that works for self and cross attentionHardPro
  5. 5Layer normalizationNormalise each token's features to zero mean and unit variance.Implement LayerNorm forwardEasy
  6. 6Encoder blockAttention, feed-forward, residuals and post-norm, as in the paper.Implement the original post-norm transformer blockMedium
  7. 7Warmup learning rateThe paper's warmup then inverse square root schedule.Compute the Noam warmup learning rateEasy
  8. 8Label smoothingThe regularised cross-entropy used to train the model.Cross-entropy with label smoothing from raw logitsEasy

More transformers and llms papers