An encoder gives hidden states , and . The decoder state is . Using Luong dot-product attention, compute the attention weights and the context vector. How does Bahdanau (additive) attention differ?
Sequence models and transformers, Sequence-to-sequence models
Level L2 Elementary. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can compute an attention step by hand and distinguish the two classic score functions and where each uses the decoder state.
Key idea
Score , weights , context . Bahdanau scores use instead.
Steps
- Scores: , , .
- Softmax: , , , sum . So .
- Context (using unrounded weights, ). It is close to , which matches the query best.
- Luong variants: dot , general , concat . Luong uses the current decoder state and then forms to predict.
- Bahdanau uses the previous decoder state to get , which then feeds into the RNN (recurrent neural network) to produce . Its score is the additive form , with a bidirectional encoder.
- Additive attention has extra parameters and works well when dimensions differ. Dot-product has none and is faster.
Common mistakes
- Forgetting to softmax the scores before taking the weighted sum.
- Mixing up the time index: Bahdanau uses , Luong uses .
- Computing the weighted sum with the scores instead of the weights.
How long your answer should be
Half a page; 4–5 minutes.
Read this
- Luong, Pham and Manning (2015), Effective approaches to attention-based neural machine translation: Section 3 defines global attention with the dot, general and concat scores, and where the decoder state is used.
- Bahdanau, Cho and Bengio (2015), Neural machine translation by jointly learning to align and translate: Section 3.1 defines the additive score and uses the previous decoder state.
- NPTEL: Deep Learning (Part 1) (IIT Ropar, Prof. Sudarshan Iyengar; lectures by Prof. Mitesh M. Khapra): Week 12, Lectures: Attention Mechanism; Attention Mechanism (Contd.), which cover alignment scores, softmax weights and the context vector.
Previous in Sequence models and transformers: A transformer layer-norm sees the feature vector for one token, with , for every feature and . What is the output? How does the statistics axis of layer norm differ from batch norm?
Next in Sequence models and transformers: A model gives next-token probabilities for tokens A–E. What is the sampling distribution under top- with , and under nucleus (top-) sampling with ? Why is nucleus sampling often preferred to a fixed ?