// Stage 4 · Transformers & LLMs
Transformers & Attention
Self-attention, multi-head attention, positional encoding, residuals and normalisation — build a GPT from scratch.
about 16 hours6 algorithms3 paperslesson text ready
01Goals
- Derive scaled dot-product attention by hand
- Understand causal masking and the decoder structure
- Train a small GPT from scratch
Do these first: Tokenization & Embeddings · Training Deep Nets
02Read on this site
03Algorithms to master
Each card has the original paper, prerequisites and resources.
04Must-read papers
- Attention Is All You Need ↗2017 ✓ verified in Essentials
- BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding ↗2018 ✓ verified in Essentials
- Language Models are Few-Shot Learners ↗2020 ✓ verified in Essentials
05Courses & videos
- Jay Alammar:The Illustrated Transformer ↗ExplainersEN
- Harvard NLP:The Annotated Transformer ↗ExplainersEN
- Karpathy ↗VideoEN
- github.com ↗Reference codeEN
- web.stanford.edu ↗CoursesEN
06Hands-on: project, code & exercises
Free, official or author-published pages. Most run in the browser or on a free Colab GPU.
PROJECT
Following nanoGPT, train a character-level GPT on Shakespeare or classical Chinese poetry and visualise one layer’s attention.
- 1Georgia Tech:Transformer Explainer ↗Interactive
Type a sentence and step through GPT-2’s attention and next-token probabilities.
- 2
- 3
07Self-test
Answer in your head, then open to check.
Why divide attention scores by √d?
To stop large dot products from saturating the softmax.
What does the causal mask do?
It lets each position see only the tokens before it.
Why multi-head rather than single-head attention?
Different heads can attend to different relationship sub-spaces.
On these routes: Application Developers · Algorithm Researchers · Domain Scientists