/ module 05 · Inside the model
Transformer Walkthrough
GPT, Llama, Claude and Gemini are all stacks of the same building block: the transformer. Here is one block shrunk to 4 numbers per token, so you can follow every multiplication from words to the predicted next word.
- Name the steps inside one transformer block, in order
- Explain queries, keys, values and the causal mask
- Say what residual connections and the MLP add
Try this first: Press 'Next step' seven times, reading one sentence per step.
architecture
The block in one breath
Each token becomes a vector (embedding) plus a hint about its position. Inside the block, attention lets tokens share information, then a per-token MLP transforms it. Residual connections add each result back onto the running vector and layer norm keeps the numbers in range. At the end, the last token's vector is compared with every vocabulary embedding to score the next word.
GPT-2 small does this with 768 numbers per token, 12 attention heads and 12 stacked blocks. This toy uses 4 numbers, 1 head and 1 block.
- input words
- token embed + position
- layer norm
- Q · K · V
- masked softmax
- Σ weights × V (+ residual)
- layer norm → MLP (+ residual)
- layer norm → unembed → softmax
- GPT-2 small repeats the middle part 12 times.
A special <bos> (beginning of sequence) token is added first. Each word is looked up in the vocabulary to get an integer ID. Real models use subword tokens, covered in the Tokens module.
scale
Toy vs. real
| setting | this toy | GPT-2 small | Llama 3 8B |
|---|---|---|---|
| vocabulary | 13 | 50,257 | 128,256 |
| numbers per token (d) | 4 | 768 | 4,096 |
| attention heads | 1 | 12 | 32 (8 KV) |
| blocks (layers) | 1 | 12 | 32 |
| MLP width | 8 | 3,072 | 14,336 |
| context length | 8 | 1,024 | 8,192 |
| parameters | ~200 | 124 M | 8 B |
Check yourself
Tick each one you could explain to a friend. If you can't yet, scroll back up and replay the lab.