Bahdanau attention (named after its first author; the model itself was called RNNsearch) is a recurrent encoder–decoder with one addition: before writing each word, the decoder looks back over the whole input sentence and decides which parts matter. Bahdanau, Cho and Bengio presented it in September 2014, under a title that says it all: neural machine translation "by jointly learning to align and translate" (Bahdanau et al., 2015). It is the first appearance of the Attention type in this Pokédex and the direct ancestor of the Transformer.
How it works
- An encoder that annotates. One recurrent network reads the sentence left to right and another right to left; concatenating their states yields, for each word xⱼ, an annotation hⱼ that summarizes the whole sentence with a focus on that word's neighborhood (Bahdanau et al., 2015, sec. 3.2). There is no longer a single vector: there is one per word.
- An attention step before every word. To produce word i, a small feedforward (MLP) block network, the alignment model, scores each annotation against the decoder's previous state: eᵢⱼ = a(sᵢ₋₁, hⱼ). A softmax turns these scores into weights αᵢⱼ that sum to 1, and the context vector is the weighted average cᵢ = Σⱼ αᵢⱼ hⱼ (Bahdanau et al., 2015, sec. 3.1).
- A decoder that writes. The new state sᵢ depends on the previous one, on the last word emitted and on cᵢ; from it comes the distribution over the next word.
The authors read αᵢⱼ as the probability that target word i is aligned to source word j, and add: "Intuitively, this implements a mechanism of attention in the decoder" (2015, sec. 3.1). Unlike in statistical translation, where alignment was a latent variable, here it is a soft, differentiable quantity trained together with everything else by backpropagation. Buckner (2024) notes a subtlety: the context is still a fixed-size vector, but it is now recomputed for every word (2024, p. 270).
The numbers are modest by today's standards: gated recurrent units (the GRUs of Cho et al. (2014)) with 1,000 dimensions, 620-dimensional embeddings and 30,000-word vocabularies per language (Bahdanau et al., 2015, appendix A), trained on the WMT'14 English–French corpus filtered down to 348 million words, for about five days per model (Bahdanau et al., 2015, secs. 4.1 and 4.2).
What changed
The paper's diagnosis is that the fixed vector of Seq2seq is a bottleneck; its remedy is to spread the information across many annotations and retrieve it selectively (Bahdanau et al., 2015, sec. 3.1). With the same data and training procedure, the basic encoder–decoder's BLEU collapses as sentences get longer, while RNNsearch-50 shows no deterioration even on sentences of 50 words or more: 26.8 versus 17.8 BLEU. On sentences without unknown words, its longer-trained version (36.2) matched Moses, the statistical baseline (35.6), which also used a 418-million-word monolingual corpus (Bahdanau et al., 2015, sec. 5.1).
The unexpected gift was the alignments. Drawn as matrices, the weights αᵢⱼ trace a diagonal, because English and French tend to preserve word order, but with deviations a linguist will recognize: to translate European Economic Area, the model first jumps to Area to write zone and then steps back one word at a time for économique européenne; to choose between le, la, les or l' for the man, it also looks at man (Bahdanau et al., 2015, sec. 5.2.1).
The lineage is direct. Vaswani et al. (2017) call this mechanism "additive attention," and their encoder–decoder attention layers mimic that of seq2seq models (2017, secs. 3.2.1 and 3.2.3): it is today's cross-attention. The transformer was born from a question: if the decoder can already see every encoder state, why keep the recurrence? (Buckner, 2024, pp. 271–272; Alammar & Grootendorst, 2024, pp. 14–15).
Limits
- Quadratic cost. Every source word must be scored for every target word. With sentences of 15 to 40 words this is not serious, but the authors warn that it may limit other applications (Bahdanau et al., 2015, sec. 6.1). The transformer inherits this cost.
- Still recurrent. Encoder and decoder advance step by step, so training cannot be parallelized along the sentence (Alammar & Grootendorst, 2024, p. 14).
- Rare words. Anything outside the 30,000 words is
[UNK]; the authors flag this as the main piece of unfinished business (Bahdanau et al., 2015, sec. 7). - Tempting maps. The alignment matrices invite being read as explanations of the translation (see the professor's note).