This page is a trap-hunter. Every line below is a claim, a broken statement, or a "why" that a student who half-learned Bahdanau and Luong attention would stumble on. Cover each one, then reveal. If a reveal surprises you, re-read the matching section of the parent note before moving on.
Before you start, make sure the symbols we lean on constantly actually mean something concrete to you.
The two score functions this page quizzes you on are worth pinning down before the traps, so each item reads on its own.
Two pictures anchor everything below — glance at them before the questions, and we point back to them by name inside the reveals.
The heatmap above is the attention weights αti: one row per decoder step, one column per encoder word, each cell's brightness is how much that word was attended to. The softmax curve on the right shows why a small lead in score becomes a big lead in weight.
The alignment picture shows the encoder states h1…hT along the bottom, the decoder walking left-to-right on top, and the bright links whose thickness is αti — the decoder "flipping to the relevant page" at each step.
TF1. "Attention removes the encoder's final hidden state entirely."
False. Attention removes the reliance on a single fixed vector, but the encoder still produces all states h1…hT; the decoder is often still initialised from the last one. It stops being the only channel of information, not the only vector.
TF2. "Because attention weights sum to 1, the context vector can never point somewhere no encoder state reached."
True, and the proof is coordinate-wise. Fix any coordinate k: ct,k=∑iαtihi,k is a convex combination (weights ≥0 summing to 1) of the numbers h1,k…hT,k, so minihi,k≤ct,k≤maxihi,k — every coordinate lies inside the range the encoder states span. (The Euclidean norm is then bounded too: ∥ct∥≤∑iαti∥hi∥≤maxi∥hi∥ by the triangle inequality.) This is exactly why the bright blend in figure s02 always lands between the pink encoder nodes, never outside them.
TF3. "Bahdanau uses the current decoder state st to score."
False. In the score eti=va⊤tanh(Wast−1+Uahi) the decoder term is the previous state st−1, because attention is computed before the RNN step — the new state st does not exist yet when scoring happens.
TF4. "Luong's dot-product score works for any encoder/decoder dimensions."
False. Plain dot product st⊤hi requires ds=dh, because you can only dot two vectors of equal length. The general variant st⊤Wahi was invented precisely to lift that restriction.
TF5. "Softmax makes attention weights positive, so a low-relevance encoder state gets weight exactly 0."
False. exp(⋅) is always strictly positive, so every weight is strictly greater than 0 — the model can shrink an irrelevant state's weight toward zero but never reaches exactly zero (soft attention, not hard). In figure s01 even the dimmest heatmap cell is a small positive number, never pure black.
TF6. "Additive and multiplicative attention differ mainly in whether they add or multiply the context into the output."
False. The "additive/multiplicative" names describe the score function — Bahdanau adds projected states inside a tanh (Wast−1+Uahi), Luong multiplies them via a dot product (st⊤Wahi). It has nothing to do with how the context is later merged.
TF7. "Removing the tanh from Bahdanau's score would leave the mechanism unchanged in expressive power."
False. Without tanh, va⊤(Wast−1+Uahi) collapses to a single linear function of st−1 and hi; the tanh non-linearity is what lets it learn alignments that aren't just linear similarity.
TF8. "Luong's general score st⊤Wahi is symmetric: swapping s and h gives the same value."
False. Wa is generally not symmetric, so s⊤Wah=h⊤Was in general. Encoder and decoder play different roles, which is the point.
The context is a weighted sum of encoder stateshi, not of the scalar scores eti. Correct: ct=∑iαtihi.
SE2. "αti=∑jexp(ejt)exp(eti)."
The normalising sum runs over the same decoder step t across all encoder positions j: ∑jexp(etj). Writing ejt sums over the wrong axis (different decoder steps), which is meaningless. In figure s01 this is normalising along a row, not down a column.
SE3. "In Luong, we first compute the context, then run the RNN to get st."
Reversed. Luong runs the RNN first to get st, then uses that st to score and build ct. Doing it the Bahdanau way here breaks the definition.
SE4. "Luong output: p(yt)=softmax(Wost)."
Luong feeds the attentional state s~t=tanh(Wc[st;ct]) (that's the Wc combination matrix), not raw st, into the output layer. Skipping the combine step throws away the context entirely.
SE5. "Dot-product attention has a weight matrix Wa∈Rds×dh."
The dot-product variant has no parameters at all. The matrix Wa∈Rds×dh belongs to the general variant. Confusing them mis-counts the model's parameters.
The shapes must all funnel into the attention dimension da: Ua∈Rda×dh and va∈Rda. Otherwise the sum Wast−1+Uahi wouldn't be a vector of the same length.
SE7. "Since va⊤(⋯) produces a scalar, we can skip softmax and use eti directly as the weight."
The raw scores can be negative and don't sum to 1, so using them directly would let the context vector blow up or point in nonsensical directions. Softmax is what turns scores into a valid blend.
SE8. "To compute softmax we exponentiate the raw scores directly: exp(eti)."
In practice you first subtract the max score, exp(eti−maxjetj), which is mathematically identical (the constant cancels in numerator and denominator) but prevents exp from overflowing to infinity or underflowing to zero on large scores.
WHY1. Why does Bahdanau project both states into a shared da-space before comparing them?
The decoder space (length ds) and encoder space (length dh) may be different sizes and mean different things; the matrices Wa and Ua project both into a common da-space so the sum Wast−1+Uahi is even well-defined, and the model learns the comparison rather than assuming the two spaces already line up.
WHY2. Why does softmax use the exponential rather than just dividing scores by their sum?
Exponentiation makes every weight positive (scores can be negative, so plain division would break) and it amplifies differences — a slightly higher score gets a disproportionately larger weight, sharpening focus. That amplification is exactly the softmax curve in figure s01. See 2.4.7-Softmax-Function.
WHY3. Why is Luong called "cheaper" than Bahdanau despite both using softmax and a context vector?
The difference is only in the score: Bahdanau runs a small feedforward net (Wa, Ua, tanh, va) per encoder position, while Luong's general score is a single matrix multiply st⊤Wahi. Fewer operations and often fewer parameters.
WHY4. Why does attention help with the vanishing-gradient problem of long sequences?
It creates direct weighted paths from every encoder state to the decoder (the links in figure s02), so gradient can flow back to early inputs without passing through every intermediate RNN step — shortening the effective path length that gradients must survive.
WHY5. Why does Bahdanau feed the context into the RNN (input feeding) while Luong combines it after via Wc?
Bahdanau lets the context shape the hidden-state evolution itself for tighter integration; Luong keeps the RNN attention-free and merges context afterward through s~t=tanh(Wc[st;ct]) for a cleaner, easier-to-implement separation. Neither is universally "correct".
WHY6. Why must the alignment scores be recomputed at every decoder step?
Because relevance changes as you generate: the word you need to attend to for output token 2 (e.g. the subject) differs from token 5 (e.g. the verb). You can see this in figure s01 — the bright cell moves across the row as t increases. Freezing the weights would defeat the entire purpose.
WHY7. Why does the context vector have the same dimension as a single encoder state, not T times bigger?
It is a weighted average (a blend), not a concatenation, of the T states — averaging preserves the shape of one state regardless of how many you blend. That is what keeps the decoder input a fixed size no matter the sequence length.
WHY8. Why does Luong wrap the combined state in a tanh (s~t=tanh(Wc[st;ct]))?
The concatenation-and-Wc-multiply step can produce large values; tanh bounds the output to (−1,1) per component, stabilising the signal fed to the final softmax and letting the layer learn how much to trust context versus state.
WHY9. Why is attention a stepping stone to self-attention?
Both compute weighted blends via learned similarity; self-attention just makes a sequence attend to itself (queries, keys, values all from the same sequence) and drops the RNN, so the scoring intuition here transfers directly.
EC1. What are the attention weights when all alignment scores are equal?
Softmax of equal scores gives the uniform distribution αti=1/T for every i, so the context becomes a plain average of all encoder states — the model is "undecided" and looks everywhere equally (a heatmap row of identical mid-tone cells in figure s01).
EC2. What happens to the context vector when the sequence has length T=1?
With one encoder state, softmax over a single score always gives αt1=1, so ct=h1 exactly — attention degenerates to just copying that one state, and the whole mechanism adds nothing.
EC3. What about the truly empty source, T=0 (no encoder states at all)?
There is nothing to score, the softmax denominator ∑j=10exp(⋅)=0, and ct=∑i=10(⋯) is an empty sum — attention is undefined. In practice you never let this happen: an empty input is rejected or a special start/end token is inserted so T≥1.
EC4. If one score is enormously larger than the rest (say et2→+∞), what does attention become?
Softmax saturates toward a one-hot vector: αt2→1, all others →0, so ct→h2. This is the "hard attention" limit — soft attention can approach but never exactly hit it. Numerically this is where the subtract-the-max trick matters, or exp overflows.
EC5. What does a negative alignment score mean for a state's weight?
A negative score simply means "less relevant than the others", but after exp(⋅) it still yields a positive weight (just a small one). Negativity is relative, not a veto.
EC6. Two encoder states hi=hj are identical — what happens?
They receive identical scores and therefore identical weights; their combined contribution is (αti+αtj)hi. The model can't distinguish them, which is fine — duplicate information is just pooled.
EC7. In Luong dot-product attention with ds=dh, what happens if you run it anyway?
The dot product is undefined — you cannot multiply mismatched-length vectors. The model won't even build; you must switch to the general variant (whose Wa∈Rds×dh bridges the gap) or reshape. This is a hard error, not a soft degradation.
EC8. What if every embedding/encoder state is the zero vector?
All scores become equal (dot products and projections of zero vanish), so weights are uniform and ct=0 — the context carries no information, and the decoder falls back to whatever the RNN state alone provides.
Recall Rebuild the framework from memory
Name the four shared steps of both mechanisms, in order.
Answer ::: (1) alignment scoring — compute a scalar eti for each encoder state; (2) softmax to weights — turn scores into a probability distribution αti summing to 1; (3) context vector — blend the encoder states, ct=∑iαtihi; (4) output generation — use the context (Bahdanau feeds it into the RNN; Luong combines it via s~t=tanh(Wc[st;ct])) to predict yt.