Neural Machine Translation › Encoder-Decoder Translation
Language AI HandbookAll chapters An early recurrent design used an LSTM to encode the source and another LSTM to generate the target, as in Sutskever et al. (2014). The Encoder-Decoder Framework gives the general setup.
The encoder reads the source and produces hidden states. A bidirectional RNN runs forward and backward and concatenates:
For this bidirectional variant, the forward state depends on the prefix and the backward state depends on the suffix. Concatenating them lets the decoder's source representation incorporate context on both sides of a position.
The decoder is a conditional language model. At step it consumes the previous target token and its own previous state:
During autoregressive inference, the next-token distribution depends on the generated prefix. Decoding proceeds until an end token or a length limit. Each new token supplies part of the context for the next step.
Teacher forcing feeds the reference prefix and scores . During generation the model uses its own prefix, which can contain earlier errors. Teacher Forcing describes the mismatch.
The fixed-vector bottleneck
In the fixed-vector design, the decoder receives one fixed-size source representation as its initial state. In this simplified notation, denotes the final encoder state of a unidirectional encoder. A bidirectional variant can combine the terminal states of both directions.
Increasing the source length leaves the size of this representation fixed. The decoder can use encoded information about a source position only through that initial representation.
In their English-to-French experiment, Sutskever et al. (2014), §§3.3 and 3.5 found that reversing the source improved BLEU. They argued that the reversal shortened some early source-to-target dependencies, while the average distance between corresponding words was unchanged. The reversed-input model translated long sentences well in their length analysis.
Another way to give the decoder access to earlier source information is to retain a representation for each position and let the decoder select among them.
Attention removes the bottleneck
With attention the decoder can form a different weighted sum over the encoder states at each step. We covered the mechanism in Attention Intuition and Bahdanau Attention.
For decoder state and encoder state , compute an energy:
The energy is a learned score: how relevant is source position to the token the decoder is about to produce. The lets the score depend nonlinearly on both the decoder state and the encoder state, and the vector collapses the result to a scalar.
Normalize over source positions:
The softmax turns the scores into a distribution over allowed source positions. This row of weights is recomputed at each decoder step.
Form the context vector and feed it into the decoder:
The decoder can read through the attention sum, without requiring the encoder to carry the same information from position 3 all the way to its final state. Each decoder step still compresses the attended states into one context vector.
Bahdanau et al. (2015) reported that their attentive RNNsearch models held up better on longer English-to-French sentences than their fixed-vector RNNencdec baselines. Their qualitative examples included attention patterns resembling word correspondences, although the training objective used sentence pairs and supplied no word-alignment labels.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!