Neural Machine Translation with Attention
Paper info
Title: Neural Machine Translation by Jointly Learning to Align and Translate
Authors: Dzmitry Bahdanau, Kyunghyun Cho, Yoshua Bengio
TL;DR
Encoder-Decoder Neural Machine Translation systems struggle with long-sentence translations due to their design—information loss is inevitable when a fixed-length vector generated by the encoder is used by the decoder to generate the translation. To address this issue, the authors introduced a learnable alignment model at the decoder that, at each decoding step, weights the relevance of each encoder hidden state to the word being predicted. The researchers performed a comparative analysis of three models: RNNsearch, an encoder-decoder model utilizing soft alignment that they trained; RNNencdec, a baseline encoder-decoder model; and Moses, a phrase-based translation system. The results confirmed their intuition that soft alignment would help especially on long sentences.
Context
Machine Translation is the process of translating text from one language to another using a computer program. At the time of this publication, one common Machine Translation approach was Phrase-based Machine Translation, and Neural Machine Translation was an emerging topic. Phrase-based Machine Translation is a statistical approach that translates groups of words or phrases based on a learned bilingual corpus. Neural Machine Translation relies on training a single model to take in sentences in the source language and translate them into the target language.
A number of studies propose an Encoder-Decoder RNN architecture to learn the mapping between a source language and a target language. This architecture consists of two components: an encoder to obtain a representation of the source language and a decoder to autoregressively translate into the target language.
Encoder
The encoder takes a sequence of input vectors and produces a context vector —a dense representation of the input. RNNs are commonly used:
where is the hidden state at time , and and are non-linear functions that transform the input and the hidden states. In this work, the encoder is bidirectional: each concatenates forward and backward hidden states, as shown in Figure 1.
Decoder
The RNN decoder is trained to autoregressively predict by taking and the dense representation context vector from the encoder.
In an RNN, the conditional probability can be modeled using , a potentially multi-layered nonlinear function that predicts the output given the previous word , the hidden state , and the context vector from the encoder.
Main idea
The main contribution of this research is the introduction of a learnable attention mechanism to weigh the importance of each encoder hidden state with respect to the current word to be predicted. This allows the model to learn a soft-alignment between the source and target language. With attention, the decoder hidden state at time is computed as:
where
and
where is the alignment model that scores how well the encoder hidden state at position aligns with the decoder state at step . This attention mechanism alleviates the need for the encoder to generate a fixed-length context vector. Figure 1 illustrates this architecture.

Figure 1: Soft-alignment attention over encoder hidden states.
Results
To measure the performance of their approach, researchers conducted a comparative analysis of three models: RNNsearch, an encoder-decoder model utilizing soft alignment that they trained; RNNencdec, a baseline encoder-decoder model; and Moses, a phrase-based translation system. RNNsearch and RNNencdec were both trained on WMT '14, an English-French parallel dataset containing a total of 850M words. Moses uses an extra monolingual dataset (418M words) in addition to the WMT '14 parallel dataset.

Figure 2: BLEU score vs. sentence length for RNNsearch and RNNencdec.
The research compared RNNsearch with RNNencdec models on a test set using the BLEU score. As shown in Figure 2, the performance of RNNencdec sharply drops when the sentence length increases, while RNNsearch holds up, confirming that soft alignment helps especially on long sentences. Moreover, the RNNsearch model performed on par with the Moses Phrase-Based translation system. Considering the fact that Moses uses an additional monolingual dataset with an extra 418M words, the results show that RNNsearch is a promising step toward stronger neural machine translation.