Two networks and one vector between them
The encoder reads the whole input and its final state is handed to the decoder as a summary, traditionally called the context vector.
The decoder is a language model conditioned on that vector, generating one token at a time until it emits an end symbol.
This is what made translation, summarisation and dialogue the same problem, since none of them require the output to be the same length as the input.
The bottleneck, and the fix that became everything
A fifty-word sentence and a five-word sentence are compressed into the same few hundred numbers, and translation quality fell off sharply with length for exactly that reason.
Attention replaced the single vector with a different weighted average at every output step, so the decoder can look back at the input word it currently needs.
Nothing is compressed away. The encoder's states are all kept, and the weights say which ones matter now.
That change was introduced to patch the bottleneck in a recurrent model, and it turned out to be the only part worth keeping.
Teacher forcing, and the gap it leaves
During training the decoder is fed the true previous token, which makes the steps independent and lets the whole sequence train in parallel.
At inference it is fed its own previous output, so one early mistake shifts the model into a state it never saw in training.
That mismatch is called exposure bias, and it is why generated text can start well and degrade, rather than being uniformly slightly wrong.
One translation, in order
- Encode the source sequence, keeping every hidden state.
- Start the decoder with a beginning-of-sequence token.
- Compute attention weights over the encoder states from the current decoder state.
- Predict a distribution over the vocabulary and pick a token.
- Feed that token back in and repeat until the end symbol is produced.
Beam search, because greedy is not the objective
Taking the most likely token at each step does not give the most likely sequence, because a strong first token can lead into a weak continuation.
Beam search carries several candidates forward and expands each one, at times the cost and with a reliable gain in quality.
Scores are normalised by length, because summing log probabilities penalises every extra token and an unnormalised beam search prefers short, unhelpful outputs.