Modelcore
Encoder-decoder model
Also called sequence-to-sequence model, seq2seq.
One network encodes the source sequence into vectors and another generates the target sequence one token at a time from them.
An encoder-decoder model is a neural network that maps an input sequence to an output sequence of a different length. The encoder reads the source tokens and produces vectors. The decoder is a conditional language model: it generates the target one token at a time, each token conditioned on the earlier target tokens and on the encoder output. It is the model behind neural machine translation, and also behind summarization, speech recognition and many other tasks. The first versions (Cho et al. 2014; Sutskever, Vinyals and Le 2014) used recurrent networks and passed one fixed-length vector from the encoder to the decoder. Attention and then the transformer replaced the single vector by access to all the encoder states.
The machine
The input is a source sequence over a source vocabulary of size , and the output is a target sequence over a target vocabulary of size that contains an end symbol , with . The model factors the conditional probability by the chain rule:
The recurrent version of Sutskever, Vinyals and Le has these layers, with embedding size and state size :
- Embeddings. and map each token to a column vector in .
- Encoder. for , with , where is an LSTM or GRU cell, possibly with several layers.
- Context. , the last encoder state. This is the fixed-length vector.
- Decoder. and , with a start symbol. Cho et al. also feed into every decoder step.
- Output. with and .
With attention, the context changes at each step: , where the weights come from a score of the decoder state and each (additive attention, multiplicative attention). In the transformer, self-attention layers replace the recurrence in both parts, and cross-attention from the decoder to the encoder output replaces the context vector.
Standing assumptions: fixed vocabularies (usually subword units from byte-pair encoding), output from left to right with an end symbol, and parameters trained by maximum likelihood, that is by the cross-entropy loss on the reference with teacher forcing: the decoder gets the reference prefix , not its own outputs.
What it counts
The model computes the probability of any target sequence, or the log probability . This is a proper distribution over the finite sequences that end in when the probability of never stopping is 0, which holds in practice but is not guaranteed by the factorization.
The cost of one evaluation of for a given in the recurrent model with one layer is for the encoder, for the decoder states, and for the output softmax. The softmax term often dominates because is in the tens of thousands. Attention adds . Training keeps the activations of all steps for backpropagation through time, which takes numbers per layer plus for the output distributions.
Generation is a search for a good . Greedy decoding takes the most probable token at each step. Beam search with beam costs score evaluations for an output of length , plus the selection of the top . Neither is exact: the decoder state depends on the whole prefix, so the dynamic programming that decodes an HMM does not apply.
Relation to other models
- Language model. A decoder with no encoder is an autoregressive recurrent neural network language model. The encoder-decoder is a language model of the target conditioned on the source.
- Noisy channel. The noisy channel translation model of statistical translation scores with separate translation and language models. The encoder-decoder models directly, in one network.
- Attention models. Additive attention and multiplicative attention keep the recurrent encoder and decoder and replace the single context vector by a weighted sum of all encoder states at each step.
- Transformer. The transformer is an encoder-decoder model with attention only. It computes all encoder states, and all decoder states in training, in parallel.
- Non-autoregressive models. Non-autoregressive translation keeps the encoder but drops the dependence of each target token on the earlier ones, so it can emit all tokens at once.
- Other tasks. Listen, attend and spell is an encoder-decoder for speech recognition, and the pointer-generator network is one for summarization that can copy source words.
Known results in the model
- Factorization. By the chain rule, every distribution over finite target sequences that end in can be written as the product above (a theorem). The model restricts the distribution only through the size of the network and the vocabulary.
- Bottleneck. With one fixed-length context vector, translation quality drops on long sentences. Bahdanau, Cho and Bengio (2015) state this as the motivation for attention and show that RNNsearch keeps its quality on long sentences (a measurement on WMT'14 English to French).
- First results. On WMT'14 English to French, the deep LSTM model of Sutskever, Vinyals and Le reached 34.8 BLEU against 33.3 for a phrase-based baseline, and 36.5 when it reranked the 1000 best outputs of that baseline. Reversing the order of the source words improved the results (measurements, from the abstract). Cho et al. (2014) improved a phrase-based system by adding the phrase probabilities of the model as a feature (a measurement).
- Exact decoding. No polynomial algorithm is known that finds the most probable output of a recurrent decoder, and beam search can miss it. The search problem is the subject of beam search and length normalization.
- The mode. For trained translation models the most probable output can be the empty sequence, and a larger beam can make the outputs worse (inadequacy of the mode, a measurement on trained models, not a theorem).
- Exposure bias. Teacher forcing trains the decoder on reference prefixes, but at test time it sees its own outputs. The gap is called exposure bias; minimum risk training and scheduled sampling train on model outputs to reduce it (measured methods).
References
- Ilya Sutskever, Oriol Vinyals and Quoc V. Le, Sequence to Sequence Learning with Neural Networks, Advances in Neural Information Processing Systems 27 (NIPS 2014), pages 3104 to 3112, abstract (an LSTM encoder and an LSTM decoder; 34.8 BLEU against 33.3 for a phrase-based system on WMT'14 English to French; 36.5 when reranking 1000 hypotheses; reversing the source helps)
- Kyunghyun Cho, Bart van Merrienboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk and Yoshua Bengio, Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation, EMNLP 2014, pages 1724 to 1734, the RNN Encoder-Decoder, trained to maximize the conditional probability of the target given the source, and its use as a feature of a log-linear phrase-based system
- Dzmitry Bahdanau, Kyunghyun Cho and Yoshua Bengio, Neural Machine Translation by Jointly Learning to Align and Translate, ICLR 2015, Section 1 and Section 5 (the fixed-length vector as a bottleneck on long sentences, and attention as the remedy)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag PJCW26 Edit this page History Report an error Markdown