Luong Attention › Attention Placement: Input vs Output
Language AI HandbookAll chapters Luong Attention › Attention Placement: Input vs OutputOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
A subtle but important difference between Bahdanau and Luong attention is where the attention mechanism fits into the decoder architecture. This choice affects both the information flow and the computational graph.
Bahdanau: Attention as Input
In Bahdanau attention, the context vector is computed using the previous decoder hidden state and then concatenated with the input embedding to form the input to the current decoder step. The computation proceeds as:
where:
- : the decoder hidden state from the previous timestep
- : the matrix of all encoder hidden states
- : the context vector computed by attending over encoder states using
- : the input embedding at timestep (typically the previous output token)
- : the augmented input formed by concatenating and
- : the new decoder hidden state
The context vector influences the RNN computation directly. This means the decoder can use information about which source positions are relevant when updating its hidden state.
Luong: Attention as Output
In Luong attention, the decoder RNN runs first, producing the current hidden state. Then attention is computed using this new state, and the results are combined. The computation proceeds as:
where:
- : the input embedding at timestep
- : the decoder hidden state from the previous timestep
- : the new decoder hidden state after the RNN step
- : the matrix of all encoder hidden states
- : the context vector computed by attending over encoder states using the current
- : the concatenation of context and hidden state
- : a learned weight matrix that combines context and hidden state
- : the "attentional hidden state" used for prediction
The final output combines the context vector with the decoder state through a learned transformation. This attentional state is then used for prediction, typically by projecting it to vocabulary size and applying softmax.


Implications of Placement
The placement choice has several practical implications:
Information flow: Bahdanau attention allows the context to influence the RNN state update, potentially enabling richer interactions. Luong attention keeps the RNN computation separate, which can be easier to reason about and debug.
Parallelization: Luong attention is slightly more amenable to parallelization during training because the RNN step doesn't depend on the attention computation. However, this advantage is minimal compared to the sequential nature of RNNs themselves.
Empirical performance: Luong et al. found their approach performed comparably or slightly better than Bahdanau attention on machine translation benchmarks. The simpler architecture and faster score functions (especially dot product) made it an attractive choice.