Every attention computation you will ever face falls into one of these cells. The rest of the page fills each one.
#
Cell (scenario class)
What makes it tricky
Covered by
A
Dot-product scoring, aligned spaces (ds=dh)
Softmax on hand-computed dot products
Ex 1
B
General/bilinear scoring (ds=dh)
The matrix Wa bridges two sizes
Ex 2
C
Bahdanau additive scoring
tanh non-linearity + va⊤ read-out
Ex 3
D
All scores equal (degenerate)
Uniform attention — the "no-info" case
Ex 4
E
One score →+∞ (limiting)
Attention collapses to one word (hard attention)
Ex 5
F
Negative & zero scores, sign handling
exp of negatives stays positive
Ex 6
G
Real-world word problem (translation)
Reading the α matrix as an alignment
Ex 7
H
Exam twist: Bahdanau vs Luong timing
Which decoder state feeds the score?
Ex 8
(All of ds, dh, da are defined in the callout just above.)
Forecast:st points purely along the first axis. Which hi do you think wins the attention — and by how much? Guess before computing.
Compute the raw scores.Why this step? The dot product s⊤h measures how much two vectors point the same way — that is exactly "relevance" when both live in the same space.
e1=(1)(1)+(0)(0)=1,e2=(1)(0)+(0)(2)=0,e3=(1)(2)+(0)(0)=2.
Exponentiate.Why?Softmax needs positive, order-preserving numbers; exp makes negatives positive and amplifies gaps.
e1=2.7183,e0=1,e2=7.3891,sum=11.1074.
Normalise.Why? Dividing by the sum forces the weights to add to 1 — a genuine probability split of "where my attention goes".
α1=0.2447,α2=0.0900,α3=0.6652.
Blend the memories.Why? The context vector is the mix the decoder actually reads. Add coordinate-by-coordinate:
first coord: 0.2447(1)+0.0900(0)+0.6652(2)=0.2447+1.3304=1.5751,second coord: 0.2447(0)+0.0900(2)+0.6652(0)=0.1800,ct=(1.5751,0.1800).
Verify:h3 had the biggest score (2) and wins the most weight (0.665) — matches the forecast. Weights sum: 0.2447+0.0900+0.6652=0.9999≈1. ✓
Forecast:Wa reshapes st into the 3-D encoder space. Will the two words end up sharing attention roughly equally, or lopsidedly?
Map the decoder into encoder space.Why?st⊤Wa is a 3-vector that lives where the hi live — now a dot product is legal.
st⊤Wa=(1,2)(100110)=(1,2,1).
Dot with each memory.Why? Same relevance idea as Ex 1, now in the shared 3-D space.
e1=(1,2,1)⋅(1,0,0)=1,e2=(1,2,1)⋅(0,0,1)=1.
Softmax.Why? Turn scores into a probability split.
α1=e1+e1e1=0.5,α2=0.5.
Verify: The two scores came out equal, so attention splits 50/50 — the bilinear form correctly bridged the size gap and the symmetry is preserved. Note Wa has ds⋅dh=2×3=6 parameters, matching the parent's count. ✓
Forecast: Both inputs get pushed through tanh, which saturates near ±1. Do you expect the weights to be extreme or gentle?
Pre-activation for each.Why? Bahdanau projects decoder (Wast−1) and encoder (Uahi) into the shared space and adds them — the "additive" name.
z1=2(1)+1(1)=3,z2=2(1)+1(−1)=1.
Apply tanh.Why tanh and not just z? The non-linearity lets the network learn alignments that a plain sum cannot; it also bounds values in (−1,1) so no score can explode.
tanh(3)=0.9951,tanh(1)=0.7616.
Read out with va (here =1). So e1=0.9951,e2=0.7616.
Verify:z1>z2 so α1>α2 — order preserved. Because tanhsquashed the raw gap (3 vs 1 became 0.995 vs 0.762), the weights are gentle, not extreme — exactly the saturation effect we forecast. ✓
Forecast: If nothing is more relevant than anything else, where should attention land?
Softmax of equal scores.Why?exp of the same number gives the same value; the sum just multiplies by the count.
αi=4e1.5e1.5=41=0.25for every i.
Context vector.Why? With uniform weights the blend is a plain average.
ct=41(h1+h2+h3+h4).
Verify: Weights sum to 4×0.25=1. ✓ Interpretation: attention has learned nothing selective — it degrades gracefully to the old fixed-vector average, which is the seq2seq bottleneck the parent note warned about. Notice the score value1.5 never mattered: softmax is shift-invariant. ✓
Forecast: One word gets shouted louder and louder. Where does attention concentrate?
Write the weight.Why? Track the winning word's share as z grows.
α1=ez+e0+e0ez=ez+2ez=1+2e−z1.
Take the limit.Why?e−z→0 as z→∞.
limz→∞α1=1+01=1,α2=α3→0.
Verify: At z=5: α1=1/(1+2e−5)=1/(1+0.01347)=0.9867 — already near 1. This is hard attention: the soft blend collapses to picking one word. The opposite limit (z→−∞) drives α1→0, handing all attention to the others. ✓
Forecast: Negatives look dangerous. Can a probability come out negative? (No — but see why.)
Exponentiate — signs vanish here.Why?exp maps every real number, negative or positive, to a positive value. That is precisely why softmax can eat any score.
e−2=0.1353,e0=1,e3=20.0855,sum=21.2208.
Normalise.α1=0.00638,α2=0.04712,α3=0.94650.
Verify: All three weights are positive despite a negative score. Sum =0.00638+0.04712+0.94650=1.0000. ✓ The most-negative score e1 got the tiniest (but non-zero!) weight — attention never fully ignores anything unless a score is −∞. ✓
Forecast: French says the noun first. Which English word should attention pick for output word 1?
Softmax the scores.Why? Convert relevance into a readable percentage split.
α1=e0.2+e2.5e0.2=1.2214+12.18251.2214=0.0911,α2=0.9089.
Read the alignment.Why? The largest α tells us which source word the decoder is "flipping back to."
The model puts 90.9% of its attention on h2 = "car" while emitting "voiture" (= car). ✓
Verify: French voiture rouge reorders adjective and noun; attention has correctly aligned output-1 "voiture" to input-2 "car" across the reordering — the exact skill a fixed bottleneck could not do (see the attention overview). Weights sum: 0.0911+0.9089=1.000. ✓
Now do the second output word "rouge" (= red) the same way. Suppose its scores are e1=2.3,e2=0.5:
α1=e2.3+e0.5e2.3=0.8581,α2=0.1419.
So output-2 "rouge" puts 85.8% of its attention on h1 = "red" — the other diagonal. Together the two rows form the alignment picture below.
Forecast: Same formula shape, different decoder state. Can the timing alone flip which word wins? Guess before computing.
Bahdanau uses the PREVIOUS state st−1.Why this step? Bahdanau computes attention before the RNN step (parent note, "input feeding"), so at scoring time only st−1 exists yet.
e1=(1,0)⋅(1,0)=1,e2=(1,0)⋅(0,1)=0.α1=e1+e0e1=2.7183+12.7183=0.7311,α2=0.2689.
So Bahdanau's blend leans on h1.
Luong uses the CURRENT state st.Why this step? Luong runs the RNN first, then scores with the freshly-updated st (parent note, "attention after the step").
e1=(0,1)⋅(1,0)=0,e2=(0,1)⋅(0,1)=1.α1=e0+e1e0=0.2689,α2=e0+e1e1=0.7311.
So Luong's blend leans on h2 instead.
Name each recipe.Why? The whole point of the twist is to attach the right label. The recipe that scores with the olderst−1 is Bahdanau (additive origins, attention before the step); the one that scores with the currentst is Luong (multiplicative, attention after the step).
Verify: The winning word flips — h1 under Bahdanau, h2 under Luong — purely from which decoder state feeds the score, which is the single most-tested distinction. Both weight-pairs sum to 0.7311+0.2689=1.0000. ✓ See 3.5.11-Self-Attention-and-Transformers for where this timing question disappears entirely (queries and keys are computed in parallel).
Recall Self-check
Softmax is invariant to adding a constant to every score. True or false? ::: True — that is why the score value1.5 was irrelevant in Ex 4, and why the max-subtraction stability trick is safe.
Why can't Luong dot-product scoring be used when ds=dh? ::: The dot product needs both vectors the same length; the bilinear form s⊤Wah inserts Wa to bridge the sizes.
In Ex 7, which input word did output-1 "voiture" align to, and with what weight? ::: "car" (h2), with α2≈0.909.
As one score →+∞, soft attention becomes _____ attention. ::: hard (one-hot) attention.
What is da? ::: The attention hidden size — the length of the shared space Bahdanau projects both states into before tanh.