The attention game — how a transformer decides what to look at
These are hand-authored teaching games. You edit scores, query features and shared projection rules. The stars measure the game’s goals; they are not training a language model. The next-token animation’s attention scores and vocabulary probabilities are scripted separately, not produced by these chip puzzles.
| Game | Model operation and limits |
|---|---|
| 1 · Budget | Softmax normalizes each query’s scores to shares summing to one. A +1 score change multiplies the unnormalized weight by e; normalized shares then change together. |
| 2 · Keys & queries | Dot products compare Q and K. Readable chips replace learned numerical features. Values are separate transformed representations, not words. |
| 3 · Sharpness | The dial multiplies scores experimentally. Vaswani’s 1/√dₖ scaling is fixed by key dimension, not a learned or user-adjusted sharpness setting. |
| 4 · Two heads | Real heads use different learned Q/K/V projections. Their outputs are concatenated and transformed by W_O. These games use shared readable keys/values to isolate different queries. |
| 5 · One rule for all | Your IF → LOOK FOR rules stand in for W_Q applied to every token; keys remain fixed chips here. Our column-vector q = W_Q x is the transpose convention of the paper’s row-vector Q = XW_Q. |
| 6 · Two layers | Attention contributes to representations through a residual connection. The real layer also has output projection, normalization and feed-forward operations. The first layer starts from embeddings plus position; later layers receive contextual representations. |
| Intro · Next token | Attention softmax weights source positions. A separate vocabulary softmax follows the full decoder. The scripted example illustrates generation; Vaswani et al. train an encoder–decoder for translation, with decoder cross-attention to the source sentence. |
All chip puzzles allow both directions, like encoder self-attention. The introduction masks future tokens, like decoder self-attention. NEAR and BEFORE are shortcuts for positional relationships; the paper adds sinusoidal positional encodings. Its base model has six encoder and six decoder layers, and eight heads per attention block.
Human attention is a set of interacting alerting, orienting and control networks, not one serial beam. Nor does the machine’s exact sum-to-one constraint establish an equivalent fixed budget in the brain. Use the Human and Compare tabs to examine this analogy.
Sources: Vaswani et al. (2017), §§3.1–3.5; Petersen & Posner (2012). The trophy examples adapt the Winograd Schema Challenge (Levesque et al., 2012); the previous-token pattern connects to Olsson et al. (2022), In-context learning and induction heads. The supplied chips demonstrate a mechanism, not evidence that this toy learned those circuits.