Worked examples — The attention mechanism intuition
You have met the three-line recipe on the parent note: score every encoder state, squash the scores with softmax, then blend. This page drills that recipe until every possible shape of input feels routine — the sharp cases, the flat cases, the degenerate one-word case, the negative-score case, and the exam trap where someone hands you scores that are already probabilities and dares you to softmax them twice.
Before we compute anything, let us name the pieces one more time in plain words, because we will use these symbols in every single example.
The only new machine we lean on is the softmax. Here is why it is the right tool and not, say, "just divide each score by the total."
One trap to flag now, so you recognise it when it arrives: softmax is for turning scores into weights, never for re-processing weights that are already normalised. If someone hands you three numbers that already add to , running softmax again would flatten them toward uniform and destroy the focus. We show exactly how to handle that in Example 9.
The scenario matrix
Every attention computation you will ever be asked to do falls into one of these cells. Here is the input sequence length defined just above, and (introduced in Example 8) is a scaling factor we multiply scores by — it is not a sequence length, it is a "sharpness dial". The examples below are labelled with the cell(s) they cover, and together they hit all of them.
| # | Case class | What is unusual about it | Example |
|---|---|---|---|
| A | One sharp peak | one score clearly biggest → focused | Ex 1 |
| B | All scores equal | degenerate → uniform | Ex 2 |
| C | Negative scores present | naive "divide by sum" breaks; softmax survives | Ex 3 |
| D | Shifted scores ( to all) | should NOT change — invariance check | Ex 4 |
| E | Single input word () | degenerate → always, context | Ex 5 |
| F | Two near-tied peaks | soft blend of two boxes, entropy is high | Ex 6 |
| G | Word-problem / reordering | real translation, non-monotonic alignment | Ex 7 |
| H | Limiting behaviour (scores , ) | attention becomes a hard argmax | Ex 8 |
| I | Exam twist: already-normalised input | do NOT softmax twice; compute entropy | Ex 9 |
Example 1 — Cell A: one sharp peak (the French "am ↔ suis" case)
Forecast: "suis" should win big — guess its weight before reading on. Above ? Above ?
Step 1 — exponentiate every score. , , . Why this step? Softmax needs positive quantities before it can form fractions; delivers that and blows up the gap so the biggest score dominates.
Step 2 — add them for the denominator. . Why this step? Dividing by this total is exactly what forces the weights to sum to — it is the "share of the whole" step.
Step 3 — divide. Why this step? These are the fractions of focus.

Figure — what to see: the three coloured bars are the weights . The coral bar for "suis" (height ) towers over the lavender "Je" and mint "étudiant" bars (each near ). Notice the visual of amplification: the raw score gap was only vs , yet after the winning bar is roughly five times taller — that height ratio is exactly . The arrow marks the of focus poured onto "suis" the moment the decoder emits "am".
Verify: ✓ (sums to one, as any probability distribution must). "suis" carries — correct, since "am" translates "suis".
Example 2 — Cell B: all scores equal → uniform attention
Forecast: If the model can't tell the boxes apart, what should it do? Guess the weight of each.
Step 1 — notice the scores are equal. Why this step? When inputs to softmax are identical, symmetry forces identical outputs; no arithmetic needed yet, but let's confirm.
Step 2 — exponentiate and divide. Each ; sum . Why this step? Confirms the symmetry: equal scores give the uniform distribution .
Verify: ✓. This is the "no focus" degenerate case — softmax does not invent focus out of nothing (Mistake 3 on the parent note). The context becomes a plain average .
Example 3 — Cell C: negative scores present
Forecast: The naive division uses — a negative denominator. Predict what goes wrong, then predict the real winner (position 2).
Step 1 — show why naive division fails. Naive: . A "weight" of means focus — impossible, and it is negative-denominator nonsense. Why this step? This is exactly the failure softmax was built to avoid; seeing it cements why we exponentiate.
Step 2 — exponentiate (kills the sign problem). , , . All positive. Why this step? maps every real number, negative included, to a positive one — the whole point.
Step 3 — normalise. . Why this step? Dividing each exponentiated score by their total is the softmax normalisation: it turns the positive numbers from Step 2 into fractions of focus that add to . This is the same "share of the whole" move as Example 1, Step 2 — the only reason it deserves its own step here is to show the machinery survives negative inputs untouched.
Verify: all in , and ✓. Position 2 wins with — softmax handled the negative score gracefully.
Example 4 — Cell D: shift-invariance (add to every score)
Forecast: Will the weights change, shrink, or stay exactly the same? Commit to an answer.
Step 1 — write the shifted softmax and factor out the constant. Why this step? The cancels top and bottom — algebraic proof that only score differences matter.
Step 2 — check numerically. , , ; . , , . Why this step? Confirms the algebra matches Example 3 to the digit.
Verify: identical to Ex 3 (0.0351, 0.7054, 0.2595) ✓. This is the fact real libraries use to subtract before exponentiating — it prevents from overflowing without changing the answer.
Example 5 — Cell E: a single input word ()
Forecast: With only one box, how much focus can it possibly get? Answer before computing.
Step 1 — apply softmax over a one-element list. Why this step? The denominator is the sum over the only term, so it equals the numerator — the score value cancels entirely.
Step 2 — build the context. . Why this step? With no choice to make, attention degenerates to "just use the one state you have" — it can never do worse than vanilla seq2seq here.
Verify: regardless of the score ✓. Edge case handled: attention on a length-1 input is a no-op that returns .
Example 6 — Cell F: two near-tied peaks (diffuse, high-entropy)
Forecast: Will the focus split roughly 50/50 between positions 2 and 3? Will entropy be higher or lower than the sharp Example 1?
Step 1 — softmax. , , , ; . Why this step? Standard recipe; note positions 2 and 3 nearly split the mass.
Step 2 — sanity on the split. — over shared between the two tied boxes. Why this step? Confirms this is a "blend two sources" situation, not a single-winner one.
Step 3 — compute entropy. . Term by term: , , , . nats. Why this step? Entropy measures how spread-out the focus is: bigger = more diffuse.
Verify: weights sum ✓. nats here versus a much lower entropy for Example 1's sharp peak — confirming "two tied peaks" is genuinely more diffuse. (Uniform-4 would be the maximum, .)
Example 7 — Cell G: word problem with reordering (English → French)
Forecast: French output order is 3-2-1 relative to English. So the first output word should attend to English word... which one? Guess before Step 3.
Step 1 — softmax the three scores. , , ; . Why this step? Turn relevance scores into focus fractions.
Step 2 — divide. Why this step? Position 3 ("translation") gets — the model reversed the order, exactly what French word-order demands.
Step 3 — read the alignment as a heatmap cell. Output word 1 → input word 3. On an attention heatmap this is an off-diagonal dot (top-right).

Figure — what to see: rows are the three French output words (top to bottom, in the order they are generated), columns are the three English input words. Colour is the attention weight — darker means more focus. The dark cells do not run down the main diagonal (top-left to bottom-right); instead they run down the anti-diagonal (top-right to bottom-left), the coral arrow pointing at the darkest cell where "traduction" (row 1) locks onto "translation" (column 3). That anti-diagonal streak is the visual fingerprint of reordering: had the languages shared word order, the dark cells would have formed the main diagonal instead.
Verify: ✓. Dominant weight on "translation" ✓ — the non-monotonic (reversed) alignment the parent note predicted for English↔French.
Example 8 — Cell H: limiting behaviour, scores scaled by a sharpness dial
Forecast: As we exaggerate the gap between scores, does attention get sharper or flatter? What is the extreme limit?
Step 1 — : scores . . Why this step? This is our baseline — the raw gap of between the two scores, un-amplified. Everything after this shows what turning the dial up does to that same gap.
Step 2 — : scores . . Why this step? Multiplying by stretches the gap from to ; since softmax amplifies gaps through , the winning weight jumps from to — we are watching focus sharpen as the dial turns.
Step 3 — : scores . . Why this step? Pushing very large makes the gap enormous, and in the limit softmax becomes a hard argmax — it collapses to weight on the single largest score and on everything else. This is the boundary case that connects soft attention to plain "pick the best".
Verify: at each the pair sums to : ✓, ✓. Sharpness rises monotonically toward the argmax limit ✓. (Shrinking would instead flatten toward uniform — the opposite extreme, matching Example 2.)
Example 9 — Cell I: exam twist — do NOT softmax already-normalised numbers
Forecast: Do these three numbers already sum to ? If so, what would a second softmax do to them — sharpen, flatten, or leave them alone?
Step 1 — check normalisation before touching softmax. and all are in : they are already valid attention weights. Why this step? Softmax is for turning scores into weights. These are already weights, so softmax has no job here. To see the damage it would do: , sum , giving — the sharp has been flattened toward uniform and position 2 lost half its lead. Double-softmax destroys focus; never do it.
Step 2 — compute the context as a weighted sum of the genuine weights. -coordinate: . -coordinate: . So . Why this step? is just the weighted average of the boxes — Step 3 of the recipe, using the weights we were given, with no softmax involved.
Step 3 — compute the attention entropy of the true weights. . Term by term: , , . nats. Why this step? Entropy quantifies how focused these given weights are; at nats they are moderately focused — well below the uniform-3 maximum , confirming position 2's dominates.
Verify: weights already sum to () ✓. Context : each coordinate lies inside the min–max of that coordinate across — holds () and holds () ✓, as any convex combination must. Entropy nats ✓, less than . Trap avoided.
Recall Self-check before you leave
Equal scores give which attention distribution? ::: Uniform, (Ex 2). Why exponentiate before normalising? ::: makes every score positive so negative scores don't break the fractions (Ex 3). Adding the same constant to all scores does what to ? ::: Nothing — softmax is shift-invariant (Ex 4). With one input word, what is ? ::: Always , and (Ex 5). As scores are scaled up without bound by , softmax approaches what? ::: A hard argmax — weight on the largest score (Ex 8). If you are given numbers that already sum to , should you softmax them? ::: No — they are already weights; softmax would flatten them. Just take the weighted sum (Ex 9).
Related reading in the vault: Transformers and self-attention (where these same softmax weights power self-attention), Neural machine translation (the reordering of Ex 7 in the wild), Encoder-decoder architecture and Seq2seq models (why the context vector matters), and Information bottleneck (the very problem attention dissolves).