Drills: Attention.
Five questions at a time from the whole volume, until attention is a tool you can reason about.
This plate draws rounds of five from the questions and predictions of the eight plates before it, with the reasoning and source plate after each answer.
Attention is the one mechanism that distinguishes a Transformer from the networks of Vol. III. Its arithmetic — dot products, a softmax, a mask, a weighted average — and its cost — quadratic in length — are used on nearly every later plate.
Below: a round of five. Answer each, read the explanation, and press “Next round” for another five.
- Compute attention weights and outputs by hand.
- Reason about masks, heads and scaling.
- Estimate attention’s cost at a given length.
- Tell observation from causal evidence.
What to carry forward
Attention replaces a fixed-size memory with a lookup over every earlier token (plate IV.1): queries match keys by dot products, scaled by √d, and a softmax blends the values (plates IV.2–IV.3). The causal mask keeps every lookup honest and lets one pass train every position (plate IV.4), and several heads look in different ways at once (plate IV.5).
Trained heads fall into recognisable kinds — previous-token, sink, induction (plate IV.6) — but where a head looks is not proof that it matters (plate IV.8). And attention’s work grows with the square of the length (plate IV.7), which shapes much of the rest of the course. Vol. V assembles attention, MLPs, norms and residuals into the Transformer.
Terms
- Attention
- softmax(QKᵀ/√d)V.
- Causal mask
- No attention to later positions.
- Head
- One of several parallel attentions.
- Ablation
- Remove and measure.