In an RNN encoder–decoder for translation, what is the bottleneck problem, and how does attention fix it? What are the equations for the context vector at decoder step , and what is the context vector for scores over three encoder states with (scalar) values ?
Sequence models and transformers, Sequence-to-sequence models
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can write Bahdanau or Luong attention as score, softmax and weighted sum, and connect it to query–key–value attention.
Key idea
Instead of one fixed vector for the whole source, each decoder step builds its own context . Here are the encoder states, are the attention weights, and are scores against the decoder state .
Steps
- Bottleneck: the plain encoder squeezes the whole source into its final state , so quality drops sharply on long sentences.
- Scores: additive (Bahdanau) , with learned ; or dot product (Luong) .
- Weights and context: and . The decoder uses in its state update and in the output, e.g. .
- Worked example: . Then .
- Link to transformers: the decoder state is the query, and the encoder states are the keys and values. The cost is score computations for source length and target length . The matrix gives a soft alignment between source and target words that you can plot.
Common mistakes
- Forgetting the softmax, so the weights do not sum to 1.
- Using one context vector for all decoder steps. It is recomputed at every step.
- Mixing up which state forms the score in Bahdanau () and Luong ().
How long your answer should be
About 3 minutes; three equations and the example.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: What are the LSTM cell equations, and why does the cell state ease the vanishing-gradient problem of a vanilla RNN? How does a GRU differ, and how many parameters does each have for input size 100 and hidden size 128?
Next in Sequence models and transformers: What is the KV cache in autoregressive transformer decoding? How does it change the cost of generating each token, and how much memory does it need for a 32-layer model with , a context of 4096 tokens, and fp16 values?