Neural Machine Translation by Jointly Learning to Align and Translate (Bahdanau Attention)¶
Authors: Dzmitry Bahdanau, Kyunghyun Cho, Yoshua Bengio
Published: September 2014 (ICLR 2015)
Paper Link: https://arxiv.org/abs/1409.0473
Why This Paper Matters¶
This paper introduced attention - the single most important idea in modern deep learning. Before this work, neural machine translation used a Seq2Seq encoder-decoder architecture where the entire source sentence was compressed into one fixed-length vector before decoding began. That bottleneck strangled performance on long sentences. Bahdanau et al. broke the bottleneck by letting the decoder look back at all encoder states at every step and dynamically focus on the parts of the input most relevant to the current output word.
The mechanism they invented - soft alignment via learned attention weights - became the conceptual seed for self-attention, cross-attention, and ultimately the Transformer. Every large language model in use today is a direct descendant of this paper.
The Problem This Paper Solves¶
The Fixed-Length Bottleneck¶
The standard Seq2Seq model (see: Seq2Seq) works in two phases:
- Encoder - reads the entire source sentence and compresses it into a single context vector
c - Decoder - generates the translation word by word, using only that one vector
"The cat sat on the mat"
|
[ ENCODER ]
|
[ c ] <- single fixed vector (bottleneck!)
|
[ DECODER ]
|
"La chat était assis sur le tapis"
The problem: For a sentence of 20 words, the encoder must squeeze all meaning into a vector of fixed dimension (e.g., 1000 numbers). For 50-word sentences, translation quality collapses - there simply is not enough capacity in that one vector to hold everything the decoder needs.
Why This Hurts in Practice¶
- Long-range dependencies are lost (subject mentioned 15 words before a verb)
- Rare words and phrases get overwritten by more common content
- BLEU scores drop sharply for sentences longer than ~30 words
- The decoder has no way to say "wait, I need to re-examine word 3 of the input"
The Core Innovation: Soft Alignment / Attention¶
The Key Idea¶
Instead of forcing the encoder to summarize everything into one vector upfront, give the decoder a dynamic, step-specific context vector computed as a weighted sum over ALL encoder hidden states.
At each decoder step t, the model: 1. Looks at the current decoder state and all encoder states 2. Computes an alignment score for each encoder position 3. Converts scores to weights (softmax, so they sum to 1) 4. Computes a context vector as a weighted combination of encoder states 5. Uses that context vector (plus the previous decoder state) to predict the next word
Encoder hidden states: h1 h2 h3 h4 h5
"The cat sat on mat"
At decoder step generating "chat" (cat in French):
alignment weights: 0.05 0.88 0.04 0.02 0.01
^
high weight on "cat"
Context vector c2 = 0.05*h1 + 0.88*h2 + 0.04*h3 + 0.02*h4 + 0.01*h5
The decoder is no longer reading from one static summary. It is conducting a focused, dynamic lookup into the full source sentence at every generation step.
Key Components Explained¶
1. The Alignment Model (Additive / Bahdanau Scoring)¶
The score measuring how well encoder state hj and decoder state si-1 match is computed by a small feed-forward network:
e(si-1, hj) = va^T * tanh(Wa * si-1 + Ua * hj)
si-1- previous decoder hidden state (what the decoder knows so far)hj- encoder hidden state at source position jWa,Ua,va- learned parameterstanh- non-linearity that lets the model capture complex interactions
This is called additive attention because it adds the two linear projections before applying the non-linearity. It was later contrasted with dot-product attention used in the Transformer.
Analogy: Think of the decoder as a reader with a highlighter. Before writing each translated word, the reader scans the original sentence and highlights the words that matter most right now. The alignment model is what decides where to highlight.
2. Attention Weights (Softmax Normalization)¶
The raw scores are normalized into a proper probability distribution:
a_ij = softmax(e(si-1, hj))
= exp(e(si-1, hj)) / sum_k exp(e(si-1, hk))
Properties: - All weights are positive - They sum to 1 across source positions - High weight = decoder "attends to" that source word - Low weight = source word is less relevant right now
3. Context Vector (Weighted Sum)¶
ci = sum_j a_ij * hj
This is a soft, differentiable selection. Unlike "hard attention" (picking one word), soft attention takes a weighted blend of all encoder states. This is crucial: because it is differentiable, the entire system trains end-to-end with standard backpropagation. The alignment model learns what to attend to purely from translation signal - no word-alignment labels needed.
4. Bidirectional Encoder (BiRNN)¶
A standard RNN encoder only sees past context. This paper uses a bidirectional RNN: one pass forward through the sentence, one pass backward, then concatenate the two hidden states at each position.
Forward: h->1 h->2 h->3 h->4 h->5
The cat sat on mat
Backward: h<-1 h<-2 h<-3 h<-4 h<-5
Concat: h1 h2 h3 h4 h5
This means each hj captures context from both directions - what came before AND after word j in the source. The decoder then attends to these richer representations.
Architecture Diagram¶
SOURCE: "The cat sat on the mat"
BiRNN Encoder
+-------------------------------------+
| h1 h2 h3 h4 h5 h6 |
| (each hj = [forward; backward]) |
+----------------+--------------------+
| all hj available
v
ATTENTION at step t
+-------------------------------------+
| Alignment scores: e(st-1, hj) |
| Softmax -> weights: at1...at6 |
| Context vector: ct = sum atj * hj |
+----------------+--------------------+
|
ct + st-1 + yt-1
v
RNN Decoder step t
v
output word yt
Key Results¶
BLEU Score on English-to-French (ACL WMT 2014)¶
| Model | Notes |
|---|---|
| RNNenc (plain Seq2Seq) | Quality drops sharply on long sentences |
| RNNsearch-30 (attention, trained on <=30-word pairs) | 28.45 BLEU, holds up on long sentences |
| RNNsearch-50 (attention, trained on <=50-word pairs) | 29.88 BLEU, holds up on long sentences |
| Moses (phrase-based SMT baseline) | 33.30 BLEU |
The headline finding is not the raw BLEU number - it is the robustness on long sentences. The plain Seq2Seq model's quality degrades rapidly as sentence length grows. The attention model's quality stays flat or even improves, because it never has to fit everything into one vector.
The Learned Alignment Matrix¶
One of the most striking results in the paper is a visualization: plot a_ij (attention weight from decoder step i to encoder position j) as a heat map. The result is a near-diagonal matrix that largely recovers the word correspondence table a human would draw between English and French.
The European Economic Area
^ source
La X
zone X
economique X
europeenne X
^ target
The model learned this alignment from sentence pairs only, with no explicit alignment supervision.
Why This Was Revolutionary¶
1. Broke the Fixed-Length Bottleneck¶
Performance on long sentences went from degrading to stable. This was the direct, practical fix for the main failure mode of Seq2Seq.
2. Interpretability via Alignment¶
The attention weights are a human-readable artifact. You can inspect which source words the model focused on for each output word. This was a step toward understanding what neural translation models were doing internally.
3. Soft Alignment is Fully Differentiable¶
Earlier work on alignment in SMT used discrete, non-differentiable steps. Soft attention is continuous and end-to-end trainable - no separate alignment step, no EM algorithm, no extra labels.
4. The Conceptual Seed of Self-Attention¶
The Transformer (see: Attention Is All You Need) generalizes exactly this mechanism. Cross-attention in the Transformer encoder-decoder is Bahdanau attention with a dot-product scoring function and multi-head parallelism. Self-attention applies the same weighted-lookup idea but within a single sequence rather than between source and target.
Impact and Descendants¶
Direct Line to the Transformer¶
- 2014 - This paper: additive attention in RNN Seq2Seq
- 2015 - Luong attention: dot-product and general scoring variants
- 2016 - Attention becomes standard in NMT pipelines (Google Brain's production NMT)
- 2017 - "Attention Is All You Need": removes the RNN entirely, attention IS the architecture
- 2018-present - BERT, GPT, T5, Claude, ChatGPT... all built on that Transformer
Other Areas Influenced¶
- Image captioning (2015): attention over image regions while generating captions
- Speech recognition (2015): attention over audio frames
- Question answering: attention over document tokens
- Protein structure: cross-attention between sequence and structure in AlphaFold
Key Takeaways for Practitioners¶
- The bottleneck lesson - any time you compress variable-length input into a fixed-size vector before processing, ask whether a dynamic lookup would work better
- Soft > hard selection - making selection differentiable via softmax is a general technique; use it whenever you want the model to learn where to look
- Bidirectional context is cheap - a BiRNN doubles encoder parameters but substantially improves the representations the decoder can attend to
- Attention weights are interpretable - they are a free debugging tool; plot them to understand what your model is doing
- End-to-end training wins - learning alignment jointly with translation (rather than as a separate pipeline stage) is cleaner and more powerful
Limitations and Future Directions¶
Limitations¶
- Quadratic cost - for each decoder step, alignment scores must be computed against every encoder state: O(|source| x |target|) total operations
- Still sequential decoding - the decoder RNN still generates one token at a time; training is not parallelizable across time steps
- Additive scoring is slower than dot-product - the small feed-forward network for scoring adds compute vs. a simple dot product
- Single attention head - the model attends with one weighted mixture; it cannot simultaneously attend to a noun and its verb with separate weights
What Came Next¶
- Luong (2015) - simplified to dot-product scoring, showed multiplicative attention also works well
- Transformer (2017) - eliminated the RNN, replaced sequential processing with parallel self-attention, added multi-head attention to address the single-head limit
- Sparse attention - for very long sequences, compute only top-k attention weights rather than all of them
- Flash Attention - hardware-aware exact attention that reduces memory from O(n^2) to O(n)
Further Reading¶
- Original Paper: https://arxiv.org/abs/1409.0473
- The Illustrated Attention Mechanism (Jay Alammar): https://jalammar.github.io/visualizing-neural-machine-translation-mechanics-of-seq2seq-models-with-attention/
- Luong Attention (2015): https://arxiv.org/abs/1508.04025
- Seq2Seq sibling summary: ../../architectures/55-seq2seq/summary.md
- Transformer sibling summary: ../../architectures/01-attention-is-all-you-need/summary.md
Citation¶
@article{bahdanau2014neural,
title={Neural machine translation by jointly learning to align and translate},
author={Bahdanau, Dzmitry and Cho, Kyunghyun and Bengio, Yoshua},
journal={arXiv preprint arXiv:1409.0473},
year={2014}
}
Related in This Collection¶
- Attention Is All You Need
- BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- Sequence to Sequence Learning with Neural Networks (Seq2Seq)
- Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (T5)
- Highly Accurate Protein Structure Prediction with AlphaFold (AlphaFold 2)