What Is Attention Actually Comparing?
Attention compares a query vector to a bank of key vectors via a dot product, and the resulting scores weight how much of each value vector is read — a similarity operation over learned representations, not over surface words.
A complete interactive classroom, not just a preview.
Start when you are ready to enter this Stage's 8 scenes and explore, respond, and learn as you go.
When an attention head runs, what two things are actually being compared against each other to score a match?
You press a single key on a keyboard and an entire language model reshapes its thoughts. Something is being compared — but what, exactly, against what?
We say 'attention compares queries to keys,' but that description hides the real question: is it comparing words, meanings, positions, or something else entirely?
Hand-built dotted-product heatmaps, a manipulable query/key simulator, and a side-by-side of syntactic vs semantic alignment.
Attention is not comparing words to words — it is comparing each query vector to a set of key vectors, producing a similarity score that decides how much of each value to read.
A common first guess is that attention is comparing the current word to the previous word, or the current word to the whole sentence, at the level of the actual tokens.
- Multi-head parallelism and head ablation studies
- Cross-attention between encoder and decoder
- FlashAttention and memory-efficient kernels
- Causal/masked attention internals
- Training dynamics and backprop through softmax
- 01The Hidden ComparisonslideQuestion
Open with the mechanical feeling of attention: a token is read, and the model's 'focus' shifts. Pose the driving question visually with two arrows pointing at each other — what is on each side of the comparison?
- Attention is often described as 'looking back' at previous words
- But the actual operation is more specific than that
- Driving question: what two things are being compared when a head scores a match?
- 02Your First GuessquizPrediction
A single forced-choice question: when the model attends from the word 'sat' in 'The cat sat on the', what is it actually comparing? Commit to an intuition before the mechanism is shown.
- Choose the most concrete comparison you think is happening
- No penalty for being wrong — the point is to surface the assumption
- 03Watch the Three Vectors ForminteractiveEvidence
A small, focused simulator: pick a token, and watch three vectors light up — the query (blue), one key from the bank (orange), and the value (green). The learner can swap keys and see the dot-product score change in real time.
- Every token produces three vectors: Q, K, and V
- The query is the seeker; the key is the address; the value is what gets returned
- Only the query is compared — against keys, not against words
- 04The Dot Product HeatmapslideEvidence
Show a real-looking attention matrix as a heatmap: rows are queries, columns are keys. Highlight the row for 'sat' and let the brightest cell point to 'cat' — surprising, because 'cat' is a noun, not a verb. The evidence is that the match is not syntactic.
- Rows are queries, columns are keys, cells are dot products
- Bright cells reveal where the model 'attends'
- The match can be semantic, positional, or syntactic — not always what grammar would predict
- 05Why Vectors, Not WordsslideExplanation
Step through the pipeline: token → embedding → linear projection into Q, K, V. The comparison happens in the projected space, not on the string. Show that two very different words can have nearby vectors, and two identical words can have different vectors in different positions.
- Tokens are mapped into a high-dimensional space by learned matrices
- Q and K live in that space; similarity is geometric, not lexical
- Same word, different position → different Q, different K, different score
- 06Test It on a New SentenceinteractiveTransfer
A manipulable scene: the learner can change the sentence and watch the attention row for the new verb shift. Predict where the brightest cell will land, then verify. The principle should hold across a new example.
- Apply the same Q-vs-K comparison to a fresh sentence
- Predict first, then observe
- The attention pattern is not about matching words — it is about matching learned vectors
- 07What Attention Is Not DoingslideBoundary
A short, sharp boundary scene: attention does not compare words to words, does not store facts, does not 'understand' meaning. It is a differentiable, learned similarity lookup — and saying so precisely prevents overclaiming.
- Attention is a soft key-value retrieval, not a database
- Heads do not 'know' facts; they pattern-match in projection space
- The comparison is purely geometric: how aligned two vectors are
- 08The Comparison, RestatedslideResolution
Resolve the driving question directly: attention compares a query vector to a bank of key vectors via dot product; the scores softmax into weights; the weights mix the value vectors. Close by naming the original intuition that was wrong.
- Compared: Q vs K (both are learned projections)
- Produced: a scalar similarity score per key
- Used: to weight the values that are summed into the output
- The first guess — comparing words to words — was the layer of illusion
Discussion threads for a Stage aren't available yet.