VerifiedarXiv:1409.047329 min
Architecture · NLP

Bahdanau attention: Neural Machine Translation by Jointly Learning to Align and Translate

A translator that rereads every source word, with learned weights, before it writes each word of the output.

In 2014 a neural translator read the source sentence into one vector of 1000 numbers and wrote the translation from that vector alone, and its quality fell on long sentences. This paper keeps one vector per source word, and for every output word the decoder takes a new weighted average of them. Those weights are what is now called attention.

Explaining the paperNeural Machine Translation by Jointly Learning to Align and TranslateBahdanau, Cho, Bengio · Jacobs University Bremen / Université de Montréal · ICLR 2015 · arXiv:1409.0473 ↗

Nobody tells the model which English word matches which French word. The weights are trained only by the translation loss, and they come out lining up the two sentences the way a bilingual reader would, including where French reverses the word order.

The model in this paper, which the authors call RNNsearch, translates English into French with two recurrent neural networks, like the sequence-to-sequence translator published the same month. It changes how the second network reads from the first, and that change is the additive attention now named after Bahdanau. The sections below build the model in the order its parts depend on each other:

  1. the fixed-vector encoder–decoder it extends, and why its single vector was suspected to be a bottleneck;
  2. a context vector computed separately for every output word, as a weighted average of per-word vectors;
  3. the alignment model that scores each source word, and the softmax that turns scores into weights;
  4. why those weights are soft, and what that does for training;
  5. the bidirectional encoder that produces the per-word vectors;
  6. one full decoder step at the paper's tensor sizes;
  7. the results: BLEU scores, quality against sentence length, and the alignments the model learned.

Why one fixed-length vector limits translation

Neural machine translation in 2014 meant an encoder–decoder. An encoder RNN reads the English sentence one word at a time and leaves behind a single vector cc. A decoder RNN then writes the French one word at a time, conditioned on cc. In the baseline this paper compares against, the RNN Encoder–Decoder of Cho et al. (2014a), which the paper calls RNNencdec, the encoder has 1000 hidden units. A 5-word sentence and a 50-word sentence both have to be summarized in those 1000 numbers, and every French word, the first and the fiftieth, is written from the same cc.

The authors conjecture that this fixed size is a bottleneck. Their evidence is a companion study (Cho et al., 2014b), which found that a basic encoder–decoder translates short sentences well and gets rapidly worse as sentences get longer. This paper's experiments test the conjecture; Figure 5, near the end of this page, plots BLEU against sentence length for both models.

Figure 1 draws the two designs. In the fixed-vector mode the box for cc keeps its width as you drag the sentence length LL up, so each word's share of it falls as 1/L1/L. In the soft-search mode the encoder keeps one vector per word, so the strip grows with the sentence and the decoder reads a different part of it for each output word.

Figure 1 · the fixed-vector bottleneck
L = 24
A source of L words is read by an encoder. RNNencdec squeezes all of it into one fixed vector c whose width never changes, so each word's share is 1/L1/L, and every output word reads the same c. RNNsearch keeps one annotation per word, a strip that grows with the sentence, and the decoder reads a different slice of it per output word. Drag L to 40 and watch the fixed box crowd.

The 1/L1/L share is a sketch: a trained network does not split its 1000 numbers evenly between words. It does have to fit a 40-word sentence into the same space as a 4-word one, while in RNNsearch each of the 40 words keeps its own 2000-number vector and the memory grows with the sentence.

The encoder–decoder baseline

The paper writes the baseline in three equations. The encoder is an RNN, a function ff that takes the current word and the previous hidden state and returns the new state. After the last word, a function qq turns the hidden states into the context vector:

ht=f(xt,ht−1),c=q({h1,…,hTx})h_t = f(x_t, h_{t-1}), \qquad c = q(\{h_1, \dots, h_{T_x}\})
(1)

In (1), xtx_t is the tt-th source word, hth_t the encoder state after reading it, and TxT_x the source length. Sutskever et al. used an LSTM for ff and let qq return the last state, c=hTxc = h_{T_x}.

The decoder defines the probability of a French sentence one word at a time:

p(y)=∏t=1Tp(yt∣{y1,…,yt−1},c)p(\mathbf{y}) = \prod_{t=1}^{T} p(y_t \mid \{y_1, \dots, y_{t-1}\}, c)
(2)
p(yt∣{y1,…,yt−1},c)=g(yt−1,st,c)p(y_t \mid \{y_1, \dots, y_{t-1}\}, c) = g(y_{t-1}, s_t, c)
(3)

sts_t is the decoder's hidden state and gg is a small network that outputs a probability for every word in the 30,000-word French vocabulary. The cc in (3) has no subscript: the same vector conditions the first output word and the last. Training maximizes the log of (2) over the parallel corpus, so every French word's gradient reaches the encoder through that one vector.

How Bahdanau attention works: one context vector per output word

RNNsearch keeps the decoder's form and gives the context a subscript:

p(yi∣y1,…,yi−1,x)=g(yi−1,si,ci),si=f(si−1,yi−1,ci)p(y_i \mid y_1, \dots, y_{i-1}, \mathbf{x}) = g(y_{i-1}, s_i, c_i), \qquad s_i = f(s_{i-1}, y_{i-1}, c_i)p(yi∣y1,…,yi−1,x)=g(yi−1,si,ci),si=f(si−1,yi−1,ci)\begin{aligned} p(y_i \mid y_1, \dots, y_{i-1}, \mathbf{x}) &= g(y_{i-1}, s_i, c_i), \\ s_i &= f(s_{i-1}, y_{i-1}, c_i) \end{aligned}
(4)

The next-word distribution for position ii and the state update both read cic_i, a context computed for that position. To build it, the encoder no longer reduces the sentence to one vector. It keeps one vector per source word, h1,…,hTxh_1, \dots, h_{T_x}, which the paper calls annotations. Annotation hjh_j describes word jj in the context of the whole sentence (the encoder that makes it comes two sections down; for now take hjh_j as a 2000-number vector per word). The context for output word ii is a weighted sum of all of them:

ci=∑j=1Txαij hjc_i = \sum_{j=1}^{T_x} \alpha_{ij}\, h_j
(5)

The weights for one output word are nonnegative and add up to 1 over the source positions, so cic_i is a weighted average of the annotations. All the weight on one annotation makes cic_i equal to it; equal weights make it the plain average of the sentence.

A concrete case: the source is the deal was signed in August and the output is l'accord a été signé en août. When the decoder is about to write accord, a trained model should put most of the weight on deal. With the weights from Figure 2 below,

c2=0.048 h1+0.877 h2+0.024 h3+0.029 h4+0.008 h5+0.013 h6c_2 = 0.048\,h_1 + 0.877\,h_2 + 0.024\,h_3 + 0.029\,h_4 + 0.008\,h_5 + 0.013\,h_6c2=0.048 h1+0.877 h2+0.024 h3+0.029 h4+0.008 h5+0.013 h6\begin{aligned} c_2 &= 0.048\,h_1 + 0.877\,h_2 + 0.024\,h_3 \\ &\quad + 0.029\,h_4 + 0.008\,h_5 + 0.013\,h_6 \end{aligned}

a 2000-number vector that is mostly the annotation of deal. One word later, writing a, the largest weight (0.717) sits on was, and c3c_3 is mostly h3h_3.

The paper reads (5) as an expected annotation: treat αij\alpha_{ij} as the probability that French word ii is aligned to, or translated from, English word jj, and cic_i is the expected value of the annotation under that distribution. The network computes this expectation exactly, as a deterministic weighted average under its own learned weights. Nothing is sampled, and there is no posterior over some true hidden alignment.

Alignment scores and the softmax

The weights come from one score per source word, which the paper calls the energy eije_{ij}, passed through a softmax over the source positions:

αij=exp⁡(eij)∑k=1Txexp⁡(eik),eij=a(si−1,hj)\alpha_{ij} = \frac{\exp(e_{ij})}{\sum_{k=1}^{T_x} \exp(e_{ik})}, \qquad e_{ij} = a(s_{i-1}, h_j)
(6)

The exponential makes every weight positive, the division makes the weights sum to 1 across the TxT_x source words, and the result changes smoothly with every energy, so the gradient of the loss reaches whatever computed the energies. Adding the same constant to all energies leaves the weights unchanged; only the differences between source words matter.

The scoring function aa is the alignment model. It reads the decoder state si−1s_{i-1}, the state before word ii is written, and the annotation hjh_j. Scoring against si−1s_{i-1} means the model chooses where to read before it commits to word ii; the context it builds then feeds both the choice of yiy_i and the next state sis_i, as in (4). The paper makes aa a network with one hidden layer (App. A.1.2):

a(si−1,hj)=va⊤tanh⁡ ⁣(Wa si−1+Ua hj)a(s_{i-1}, h_j) = v_a^\top \tanh\!\big(W_a\, s_{i-1} + U_a\, h_j\big)

with Wa∈Rn′×nW_a \in \mathbb{R}^{n' \times n}, Ua∈Rn′×2nU_a \in \mathbb{R}^{n' \times 2n} and va∈Rn′v_a \in \mathbb{R}^{n'}, and n=n′=1000n = n' = 1000 in every experiment. That is 1,000,000 parameters in WaW_a, 2,000,000 in UaU_a and 1,000 in vav_a, about 3.0 million for the scorer. The decoder state is projected by WaW_a, the annotation by UaU_a, the two 1000-number projections are added and passed through tanh, and vav_a reduces the result to one number. Because the two inputs are added inside the tanh, this form is called additive attention. The same annotation hjh_j is the vector that gets scored here and the vector that gets averaged in (5); there are no separate key and value projections.

UahjU_a h_j does not depend on the output position ii, so the paper computes it once per source word and reuses it for every French word. Per output word, the only new matrix product is Wasi−1W_a s_{i-1}, and each source word then costs one tanh over 1000 numbers and one 1000-term dot product.

Figure 2 runs one sentence through this. The energies are illustrative numbers, and every weight printed below them is their exact softmax. Writing accord, the energies are (+0.2, +3.1, −0.5, −0.3, −1.6, −1.1). deal's energy is 2.9 above the runner-up, the (+0.2), so deal gets about e2.9≈18e^{2.9} \approx 18 times the's weight; after the softmax divides by the sum over all six words, its weight is 0.877. Press Play and follow the weights along the source as the French is written; at été they split between was (0.53) and signed (0.35).

Figure 2 · one attention step
word 1/7
For each French word, the six source annotations h₁…h₆ get an energy against the previous decoder state (amber bars, numbers below), the energies are softmaxed into weights α that sum to 1, and the weights blend the annotations into the context c, drawn as a stacked bar with one segment per source word. Press Play or scrub through the seven French words.

The weight row is recomputed from scratch for every French word, from a decoder state that already reflects the words written so far. No rule makes the weights move left to right; they follow the source in order here because English and French put these words in the same order.

Why the alignment is soft

Statistical translation before this paper treated word alignment as a discrete hidden variable: French word ii comes from exactly one English word jj, and the system searches or sums over the choices. RNNsearch could have done the same and used only the annotation of the highest-scoring source word. The paper states that its alignment is not a latent variable: the alignment model computes a soft alignment, the gradient of the cost passes through it, and the alignment model trains jointly with the rest of the translator.

A hard pick is a step function of the energies. Change the scores slightly and the same word stays picked, so the derivative of the loss with respect to the energies is zero almost everywhere and backpropagation gives the alignment model nothing to learn from. Later hard-attention models, such as Xu et al.'s image captioner (2015), sample a position and train with a REINFORCE-style estimator, which gets a usable but noisy gradient from the samples. With the softmax, α\alpha is a smooth function of the energies and cic_i a smooth function of α\alpha, so ordinary backprop delivers the gradient on every energy.

The paper also gives a translation reason. In its Figure 3(d), the man becomes l'homme. A hard alignment maps the to l' and man to homme, but the French article depends on the noun after it: the can become le, la, les or l'. With soft weights the decoder reads both words while writing l'; the published weights for that row are 0.32 on the and 0.50 on man. Soft weights also handle phrases of different lengths in the two languages without aligning leftover words to a dummy NULL word.

Figure 3 takes that l' row, renormalized over four nearby source words, and multiplies its energies by a scale β\beta. At β=0\beta = 0 every energy is 0 and each weight is 0.25. The real model starts there: the paper initializes vav_a to zero and draws every element of WaW_a and UaU_a from a Gaussian with mean 0 and variance 0.00120.001^2 (App. B.1), so every energy va⊤tanh⁡(⋅)v_a^\top \tanh(\cdot) is 0 and every context is the plain average of the sentence. At β=1\beta = 1 you get the published weights. As β\beta grows toward 10 the softmax approaches a hard pick of man, and the curve shows the size of ∂α/∂e\partial \alpha / \partial e falling from 0.45 at β=1\beta = 1 to 0.02 at β=10\beta = 10.

Figure 3 · soft versus hard alignment
β = 1.00
Weights for writing l', from the paper's Figure 3(d). Drag β to scale the energies: 0 gives uniform weights (the model at initialization), 1 the published weights, 10 a near-hard pick of "man". In the 2D sketch of the four annotations, the context c, a weighted average, always stays inside their hull. The curve is the softmax gradient size ∥∂α/∂e∥F\lVert \partial\alpha/\partial e \rVert_F, which collapses as the pick hardens.

At the uniform starting point the softmax passes gradient well (0.43, close to the curve's peak), and vav_a gets a nonzero gradient through tanh⁡(Wasi−1+Uahj)\tanh(W_a s_{i-1} + U_a h_j), so the energies start to separate after the first updates. From there, gradient descent sharpens a row where a sharper weight lowers the translation loss and can leave it spread where that lowers the loss, as in the l' row.

Annotations from a bidirectional RNN

An annotation should describe its word together with the words on both sides of it, and a left-to-right RNN state at position jj has read only words 1 to jj. So the encoder runs two RNNs: a forward one from x1x_1 to xTxx_{T_x}, producing h→1,…,h→Tx\overrightarrow{h}_1, \dots, \overrightarrow{h}_{T_x}, and a backward one from xTxx_{T_x} back to x1x_1, producing h←1,…,h←Tx\overleftarrow{h}_1, \dots, \overleftarrow{h}_{T_x}. The annotation stacks the two states for the same position:

hj=[ h→j⊤ ;  h←j⊤ ]⊤h_j = \big[\, \overrightarrow{h}_j^\top \,;\; \overleftarrow{h}_j^\top \,\big]^\top

Each RNN has 1000 units, so hjh_j has 2000 numbers, which is why UaU_a above is 1000 by 2000. The two RNNs share the source word-embedding matrix and have separate recurrent weights (App. A.2.1). The paper argues that since RNNs represent recent inputs best, both halves are dominated by words near jj, so hjh_j summarizes the whole sentence with its focus on the neighborhood of word jj. Because of that focus, a weight on hjh_j can be read as a weight on word jj in the alignment plots later.

The decoder needs a state before it has read any context. The paper sets s0=tanh⁡(Wsh←1)s_0 = \tanh(W_s \overleftarrow{h}_1). The backward RNN reaches position 1 last, after reading every word from the end of the sentence back to the start, so h←1\overleftarrow{h}_1 is the encoder state that has seen the whole source. Fix every cic_i to the last forward state h→Tx\overrightarrow{h}_{T_x} instead of computing it from (5), and RNNsearch turns back into RNNencdec (App. A.2.2).

In Figure 4, pick a word to see which inputs fed its forward state (itself and the words to its left) and its backward state (itself and the words to its right). The fade with distance is an illustration of the paper's recency argument, not a measurement. The decoder-start button shows s0s_0.

Figure 4 · bidirectional annotations
word 3
A forward RNN (top chain) reads left to right and a backward RNN (bottom chain) right to left. Hover, tap or slide to a word: its two states light up, along with the words that fed each, and its annotation is the two concatenated, 1000 + 1000 numbers. "decoder start s₀" lights h←1\overleftarrow{h}_1, the backward RNN's last state.

One decoder step, with the paper's sizes

Every RNN in the paper uses the gated hidden unit of Cho et al. (2014a), now called the GRU. The paper notes that LSTM units would also work, as in Sutskever et al. For the decoder (App. A.2.2), with e(yi−1)e(y_{i-1}) the 620-number embedding of the previous French word:

# decoder GRU update for output word i (App. A.2.2, biases omitted)
# s_prev = s_{i-1} (1000), emb = e(y_{i-1}) (620), c = c_i (2000)
z  = sigmoid(Wz @ emb + Uz @ s_prev + Cz @ c)   # update gate, 1000
r  = sigmoid(Wr @ emb + Ur @ s_prev + Cr @ c)   # reset gate, 1000
s_ = tanh(W @ emb + U @ (r * s_prev) + C @ c)   # proposed state, 1000
s  = (1 - z) * s_prev + z * s_                  # new state s_i

The update gate z sets, per unit, how much of the old state to replace; where z is near 0 the unit copies si−1s_{i-1} forward unchanged, which gives gradients a path across many steps. The reset gate r sets how much of the old state enters the proposal. The context enters all three lines through 1000-by-2000 matrices C, Cz, Cr.

The output layer is a "deep output" with one maxout layer: a 1000-number vector is computed from the previous state, the previous word and the context, each adjacent pair of entries is reduced to its maximum, leaving l=500l = 500 numbers, and a softmax over the 30,000-word vocabulary gives the next-word probabilities. One full step for output word ii, in order:

# one decoder step: write output word i (biases omitted)
# H: Tx x 2000 annotations; UaH = H @ Ua.T, Tx x 1000, computed once per sentence
# s_prev = s_{i-1} (1000); y_prev = id of the previous French word
q     = Wa @ s_prev                       # 1000: the decoder's part of every score
e     = tanh(UaH + q) @ va                # Tx energies e_ij
alpha = softmax(e)                        # Tx weights, sum to 1          eq. (6)
c     = alpha @ H                         # 2000: context c_i             eq. (5)
emb   = E[:, y_prev]                      # 620: previous word embedding
t     = Uo @ s_prev + Vo @ emb + Co @ c   # 1000 = 2l
t     = t.reshape(500, 2).max(axis=1)     # maxout over adjacent pairs, l = 500
p     = softmax(Wo @ t)                   # 30000 next-word probabilities
s     = gru(s_prev, emb, c)               # new state s_i (listing above)
# loss for this word: -log p[y_i]; gradient reaches Wa, Ua, va, both encoders

Eq. (4) in the main text writes the output as g(yi−1,si,ci)g(y_{i-1}, s_i, c_i), with the new state sis_i. Appendix A.2.2 computes it from si−1s_{i-1}, and so does the authors' GroundHog code; the listing follows the appendix and the code.

Training minimizes −log⁡p(yi)-\log p(y_i) summed over the French words of each sentence pair. Every matrix above, including WaW_a, UaU_a, vav_a and both encoder RNNs, gets its gradient from that one loss; there is no separate alignment objective. The optimizer is minibatch SGD with Adadelta (ϵ=10−6\epsilon = 10^{-6}, ρ=0.95\rho = 0.95), 80 sentence pairs per minibatch, and the gradient's L2 norm clipped to at most 1. Each step costs time proportional to the longest sentence in the minibatch, so before every 20th update the authors pulled 1600 sentence pairs, sorted them by length and split them into 20 minibatches. Each regular model trained for about five days (RNNsearch-50: 111 hours, 2.2 epochs, on a Quadro K-6000 GPU); RNNsearch-50★, the same model kept training until the development score stopped improving, ran for 252 hours (5.0 epochs). Translations are decoded with beam search, which keeps several of the most probable partial translations at each step instead of committing to the single most probable next word, and a translation ends when the model emits the end-of-sentence token.

The alignment model runs Tx×TyT_x \times T_y times per sentence pair, once for each source word and output word. At 30 words each way that is 900 evaluations of a tanh over 1000 numbers plus a 1000-term dot product, about 0.9 million multiply-adds, next to 60 million for computing UahjU_a h_j for the 30 source words. The paper calls the quadratic term acceptable because most translation sentences are 15 to 40 words long, and flags it as a possible limit for other tasks. At 1000 tokens each way it would be a million evaluations per sentence pair. Transformer attention inherited the same quadratic growth; FlashAttention makes that computation faster and its memory linear without removing the quadratic compute.

Results: BLEU on English-to-French and on long sentences

The task is WMT'14 English-to-French. The parallel corpora total 850M words, reduced to 348M with the data selection method of Axelrod et al. (2011), and no monolingual data is used. Each language keeps its 30,000 most frequent words and maps every other word to [UNK]. The development set is news-test-2012 and news-test-2013 combined; the test set is news-test-2014, 3003 sentences. Both architectures are size-matched at 1000 hidden units (RNNsearch has a forward and a backward encoder RNN of 1000 units each), and each is trained twice, on sentences of up to 30 words (-30) and up to 50 words (-50).

Quality is measured in BLEU, which counts the 1- to 4-word sequences of the output that also appear in a reference translation, combines the four precisions, applies a penalty for output shorter than the reference, and reports the result on a 0 to 100 scale. Table 1 of the paper:

ModelAll sentencesNo unknown words
RNNencdec-3013.9324.19
RNNsearch-3021.5031.44
RNNencdec-5017.8226.71
RNNsearch-5026.7534.16
RNNsearch-50★ (trained longer)28.4536.15
Moses (phrase-based)33.3035.63

The right column scores only sentences with no unknown word in the source or the reference, and there the models were not allowed to output [UNK]. Every RNNsearch beats the RNNencdec trained on the same lengths: RNNsearch-50 scores 26.75 against 17.82, nearly nine BLEU. RNNsearch-30, trained only on sentences up to 30 words, also beats RNNencdec-50, 21.50 to 17.82, which the paper cites as further confirmation. Both numbers in the starred row, 28.45 and 36.15, come from the longer-trained run.

On sentences without unknown words, RNNsearch-50★ scores 36.15 against the phrase-based system Moses's 35.63. On the full test set Moses wins, 33.30 to 28.45, and Moses also used a separate 418M-word monolingual corpus. The paper claims only that on known-word sentences a single neural network performs as well as the phrase-based system. The difference between the two columns points at the 30,000-word vocabulary, and the paper's conclusion names unknown and rare words as one of the challenges left.

Table 1 averages over all lengths. The paper's Figure 2 splits BLEU by source sentence length and is the direct test of the bottleneck conjecture. Figure 5 re-plots its four curves, traced by eye from the published plot, so read the values to about half a BLEU point.

Figure 5 · quality against sentence length
50 words
BLEU on the full test set against source length, traced from the paper's Figure 2. RNNsearch-50 stays near 26 to 27 past 50 words; RNNencdec-50 peaks near 22 around 15 to 20 words and falls to about 9 by 50; RNNsearch-30 follows RNNsearch-50 to about 20 words and then falls. Drag or slide to read values; the buttons hide or show each model.

At 10 words RNNsearch-50 scores about 24.6 and RNNencdec-50 about 21.0. At 30 words the fixed-vector model is down to about 19.2 while RNNsearch-50 is at 27.5. At 50 words RNNencdec-50 is near 9 and RNNsearch-50 near 26, a gap of about 17 BLEU. RNNsearch-50 shows no deterioration even past 50 words, which is the paper's main evidence that the fixed vector was the bottleneck. At the very shortest lengths on the plot, RNNencdec-50 is slightly ahead.

RNNsearch-30 tracks RNNsearch-50 up to about 20 words, then declines, to about 23 at 30 words and about 10 at 50, level with RNNencdec-50. It never saw a training sentence longer than 30 words, and soft-search did not make it translate long sentences well. It stays above RNNencdec-30, which falls to about 3, at every length.

Section 5.2.2 of the paper shows the difference on one test sentence: An admitting privilege is the right of a doctor to admit a patient to a hospital or a medical centre to carry out a diagnosis or a procedure, based on his status as a health care worker at a hospital. RNNencdec-50 translates it correctly up to a medical centre and then drifts, ending with en fonction de son état de santé, "based on his state of health". RNNsearch-50 keeps the meaning to the end: … selon son statut de travailleur des soins de santé à l'hôpital.

What the learned alignments look like

Each row of weights is a distribution over source words, so one sentence's weights form a matrix that can be drawn as an image: a row per French word, a column per English word, brightness for weight. The paper's Figure 3 shows four such matrices from RNNsearch-50. Figure 6 reproduces two of them, with each cell's weight read from the published grayscale images; the rows of that reading sum to between 0.96 and 1.00.

Figure 6 · the alignment matrices
zone
Columns are the English source, rows the generated French; a brighter cell carries more weight. Values are read from the paper's Figure 3 panels (a) and (d). Hover or tap a row, or use the slider, to list the source words it reads; the buttons switch between the two sentences.

Panel (a) is mostly a diagonal, because English and French put most words in the same order. The exception is European Economic Area, which French writes zone économique européenne, noun first. The model writes zone reading Area (0.71), then économique reading Economic (0.76), then européenne reading European (0.97): it jumps over two words and walks back one word at a time. The row for la puts 0.61 on the and 0.27 on Area; one plausible reading, which the paper does not offer, is that the article has to agree in gender with zone, the word that translates Area.

Panel (d) holds the l' row from Figure 3 above (0.32 on the, 0.50 on man), and the next row, homme, puts 0.98 on man.

From RNNsearch to Luong attention and the Transformer

Luong, Pham and Manning (2015) moved the score to the current decoder state sis_i and tried multiplicative scores such as si⊤Whjs_i^\top W h_j, which replace the tanh layer with one bilinear product. The Transformer (Vaswani et al., 2017) removed the RNNs. Each position computes a query, a key and a value with three separate projections, the score is a dot product of query and key divided by the square root of their width, and attention alone moves information between positions. The Transformer keeps (5) and (6) from this paper: a softmax over scores, then a weighted average, recomputed for every output position and trained by the same loss as the rest of the network.

The paper itself uses the word attention three times, in three consecutive sentences of Section 3.1, where it describes the decoder deciding which parts of the source to attend to. Its own names for the mechanism are the alignment model and (soft-)search, and the model is RNNsearch.

Provenance Verified against primary literatureHow we verify
Sutskever, Vinyals & Le (2014)The seq2seq baseline: an LSTM encoder folds the source into one fixed vector (q = h_T), reading the input reversed. No attention.
Cho et al. (2014a)The RNN Encoder-Decoder (RNNencdec, the baseline here) and the "gated hidden unit", later called the GRU, used for every RNN in this paper.
Cho et al. (2014b)The study showing a fixed-vector encoder-decoder degrades as sentences get longer. It motivates the bottleneck conjecture, which this paper tests.
Schuster & Paliwal (1997)The bidirectional RNN that produces the per-word annotations.
Graves (2013)Handwriting synthesis with a learned alignment over the input characters, restricted to move monotonically. The paper cites it as the closest prior alignment model.
GroundHog (lisa-groundhog)The authors' Theano implementation, linked in Sec. 4 of the paper. experiments/nmt/encdec.py, Decoder.build_decoder: the output layer reads the previous decoder state s_{i-1}, as in App. A.2.2.
Luong, Pham & Manning (2015)Attention that scores the CURRENT decoder state, including multiplicative scores, a later variant of this additive scorer.
Vaswani et al. (2017)The Transformer: scaled dot-product attention over separately projected queries, keys and values, with no RNN.
correctionFour points where this page differs from common retellings or from the paper's own text. (1) The attention here is additive: a one-layer tanh network scores the PREVIOUS decoder state s_{i-1} against each annotation, and the same annotation is both the scored vector and the averaged one. It is not the Transformer's scaled dot product over separate Q, K, V (2017), nor Luong's score of the current state (2015). The recurrent cell is the gated unit later called the GRU, not an LSTM. (2) The paper is inconsistent about the output layer: Eq. (4) feeds it the new state s_i, App. A.2.2 the previous state s_{i-1}. The authors' GroundHog code (experiments/nmt/encdec.py, Decoder.build_decoder) reads s_{i-1}; this page follows the appendix and the code. (3) The model does not beat the phrase-based Moses system overall. RNNsearch-50* edges it only on sentences without unknown words (36.15 vs 35.63) and loses on the full test set (28.45 vs 33.30). (4) The word "attention" appears three times, in three consecutive sentences of Sec. 3.1, and nowhere else; the paper's own terms are "alignment model", "(soft-)search" and "RNNsearch". Minor: Sec. 5.2.1 first prints the phrase as "zone économique européen" before the correct "européenne", and in arXiv v7 the alignment model has no equation number (it sits in App. A.1.2), so this page leaves it unnumbered.

Questions you might still have

?

Is this the same attention as in the Transformer?
The core is the same: softmax weights over a set of vectors, then their weighted average, recomputed for every output position. The parts differ. Here the score is a one-layer tanh network of the previous decoder state and an annotation, each annotation serves as both key and value, and RNNs do the encoding and decoding. The Transformer scores with a scaled dot product between separately projected queries and keys, averages separately projected values, and has no RNN. The Attention Is All You Need explainer covers that design.

?

The weights are never supervised. Why do they line up with real word alignments?
Because putting weight on the right source word helps predict the next French word, and the translation loss is the only thing the weights are trained on. The alignment model gets its gradient through the softmax from that loss. The heatmaps are a check after training: the paper did not use alignment labels at any point.

?

Why a weighted average instead of picking the single best source word?
A hard pick does not change when the scores change slightly, so its derivative with respect to the scores is zero almost everywhere and backpropagation cannot train the scorer. Hard attention, as in Show, Attend and Tell (2015), samples a position and uses a REINFORCE-style estimator, which works but is noisier. The softmax average is differentiable, and it can split weight across words, which the paper needs for cases like "the man" becoming "l'homme".

?

If attention fixes long sentences, why does RNNsearch-30 decline past about 20 words?
It was trained only on sentences of up to 30 words. In the paper's Figure 2 it scores about 23 BLEU at 30 words and about 10 at 50, level with RNNencdec-50, while RNNsearch-50 stays near 26. The paper does not analyze the cause. The curves show that soft-search removes the fixed-vector limit, but the model still has to be trained on sentences of the length it will translate. RNNsearch-30 does stay above RNNencdec-30 at every length.

?

Does attention remove the fixed-length limit at no cost?
The cost moves into computation. The alignment model runs once for every pair of source word and output word, so the work grows as the product of the two lengths. At 30 words each way that is 900 small evaluations per sentence pair, about 0.9 million multiply-adds. The paper calls this acceptable for 15-to-40-word sentences and a possible limit for other tasks. Transformer attention has the same quadratic cost; FlashAttention keeps the quadratic compute and cuts the memory traffic (see that explainer).

?

How does the model handle words outside its 30,000-word vocabulary?
It does not. Every other word becomes the token [UNK], in the source and in the target. This is why the paper reports two BLEU columns: on sentences with no unknown words RNNsearch-50* scores 36.15, on the full test set 28.45. The conclusion names better handling of rare and unknown words as one of the challenges left.

?

Did this paper coin the word "attention"?
It uses "attention" three times, in three consecutive sentences of Section 3.1, as an intuition for what the decoder does. Its working terms are "alignment model" and "(soft-)search", and the model is called RNNsearch. The name "attention" stuck afterwards, and "Bahdanau attention" is the later label for this additive form.

Footnotes & further reading

  1. The paper: Bahdanau, Cho, Bengio, Neural Machine Translation by Jointly Learning to Align and Translate (ICLR 2015; this page follows arXiv v7). The authors' implementation: GroundHog; the decoder is in experiments/nmt/encdec.py.
  2. The seq2seq model with a single fixed vector: Sutskever, Vinyals, Le, Sequence to Sequence Learning with Neural Networks (explainer).
  3. The RNN Encoder–Decoder and the gated hidden unit (GRU): Cho et al., Learning Phrase Representations using RNN Encoder–Decoder, and the length-degradation study behind the bottleneck conjecture, Cho et al., On the Properties of Neural Machine Translation.
  4. The bidirectional RNN: Schuster & Paliwal, Bidirectional Recurrent Neural Networks (1997). The earlier monotonic alignment model: Graves, Generating Sequences With Recurrent Neural Networks (2013).
  5. Later forms of attention: Luong et al., Effective Approaches to Attention-based NMT (current-state and multiplicative scores); Xu et al., Show, Attend and Tell (hard versus soft attention); Vaswani et al., Attention Is All You Need (explainer).
  6. BLEU: Papineni et al., BLEU: a Method for Automatic Evaluation of Machine Translation (2002).