Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Seq2Seq,
explained.
A neural network is happiest with a fixed-size input and a fixed-size output. But a sentence isn't fixed — "hello" and a rambling paragraph are both valid inputs, and their translations differ in length too. How do you map one variable-length sequence to another? This paper's answer was so clean it became the template for machine translation, chatbots, and — eventually — the Transformer: read it all into one vector, then write the answer out.
Contents 17 sections
The delta The variable-length problem The big idea: encode, then decode The encoder The decoder The tricks that made it work The fixed-vector bottleneck The limits Why it still matters How it works The math The evidence Since then Solve it yourself Questions Check yourself Where this sitsWhat changes here: one network replaces a pipeline
Rung 1, so the comparison is against the machine translation it displaced. A strong translation system in 2014 was an assembly of separately-trained components: a word-alignment model, an extracted phrase table, a reordering model and a separate language model, combined by a tuned scoring function. Each piece was individually sensible and the whole thing was engineered rather than learned.
The change is to train one network, end to end, on pairs of sentences. An encoder reads the source sequence one token at a time and its final hidden state is taken as a representation of the entire sentence; a decoder is initialised from that state and generates the target sequence one token at a time. No alignments, no phrase table, no explicit reordering — the model is handed the input and the desired output and nothing else.
The unit to carry up the ladder is the fixed-length vector, because it is both the idea and the flaw. Everything the decoder will ever know about the source has to fit in that one vector, whether the sentence is four words or forty. The paper's most telling empirical result is a trick that should not have helped as much as it did: reversing the order of the source sentence improved translation quality noticeably. Reversing changes no capacity and no parameters — it only shortens the distance between the first words of the source and the first words of the output. That the fix worked is evidence that distance, not capacity, was the binding constraint, which is exactly what rung 2 attacks.
The variable-length problem
Classic neural networks assume a fixed shape: a fixed number of inputs, a fixed number of outputs. That's fine for classifying a photo into one of 1,000 labels. It falls apart for language, where the input is a sentence of arbitrary length and the output is another sentence of a different, also-arbitrary length. Translation, summarization, dialogue — all are sequence-to-sequence, and none fit a fixed-size box.
Recurrent networks could consume a variable-length sequence, but the standard setups produced one output per input step — no good when the output length differs from the input and the alignment isn't one-to-one. The field needed a way to map any sequence to any other sequence, learned end to end from data. That's the gap this paper closed.
The big idea: encode, then decode
The solution splits the job across two recurrent networks. An encoder reads the entire input sequence and boils it down to a single fixed-length vector — a compressed "meaning" of the whole sentence, often called the context vector. A decoder then takes that vector and unrolls it into the output sequence, one token at a time.
It's like a translator who listens to a full sentence, forms a complete mental impression of it, and only then starts speaking the translation — rather than translating word by word as they hear it. The bridge between the two languages is that one internal impression: the context vector.
The encoder
The encoder is an LSTM — a recurrent network with gates designed to carry information across many steps without the gradients vanishing. It ingests the input tokens one by one, updating an internal hidden state each step. After the last token, that final hidden state is treated as the summary of the entire input: everything the decoder will get to know about what was said.
LSTMs mattered here because plain RNNs forget too fast — by the end of a long sentence, the influence of the early words has washed out. The gated memory of the LSTM was what made encoding a whole sentence into one usable vector even feasible.
The decoder
The decoder is a second LSTM, initialized with the encoder's context vector as its starting memory. It generates the output autoregressively: predict the first output token, then feed that prediction back in to help predict the second, and so on — each new word conditioned on the context vector plus everything generated so far.
Special tokens frame the process: a start token kicks off decoding, and the decoder keeps going until it emits an end-of-sequence token, which is how a variable-length output naturally terminates itself. This "generate one token, feed it back" loop is exactly how modern language models still produce text — seq2seq is where that pattern went mainstream.
The tricks that made it work
Two practical choices moved the needle a lot. First, depth: stacking several LSTM layers gave the model enough capacity to handle real translation. Second, and famously, reversing the input. Feeding the source sentence backwards improved results markedly.
Why would reversing help? It shortens the distance between related words. With the input reversed, the first source words sit close in time to the first target words the decoder must produce, so the LSTM has shorter dependency chains to learn at the crucial start of the sentence. A tiny change in data ordering, a surprisingly large gain — a reminder that in deep learning, the plumbing often matters as much as the theory.
To search for good output sequences at generation time, seq2seq used beam search: keep the few most-promising partial translations at each step rather than greedily committing to the single best token. It's still a standard decoding strategy.
The fixed-vector bottleneck
The architecture's elegance is also its flaw. Everything about the input must pass through one fixed-size context vector. The whole model factorizes the output probability as a product of per-token predictions, but every one of them is conditioned on the same frozen summary c:
A 5-word sentence and a 50-word sentence get the exact same number of bytes to be remembered by.
For a short sentence, fine. For a long, information-dense one, that single vector becomes a straw through which a river must flow — one vector looks like it can't retain every detail. Other encoder-decoder models of the same year (Cho et al., Bahdanau et al.) did lose quality as sentences got longer; this paper's own deep LSTM, helped by reversing the source sentence, held up well on long ones.
This bottleneck was the clear, well-understood weakness — and naming it so precisely is part of the paper's legacy. It set up the very next breakthrough: what if the decoder didn't have to rely on one summary vector, but could look back at all the encoder's hidden states and focus on the relevant ones? That question is attention.
The limits
Beyond the bottleneck, seq2seq inherits the costs of recurrence. Because each step depends on the previous hidden state, the encoder and decoder must run sequentially — you can't process all tokens in parallel, which makes training on long sequences slow and hard to scale. And even with LSTMs, very long-range dependencies remain difficult.
Both limitations pointed the field forward. Attention fixed the bottleneck; a few years later the Transformer removed recurrence entirely, so a whole sequence could be processed in parallel — while keeping seq2seq's encoder-decoder skeleton. Seq2seq was a crucial rung on the ladder, not the top of it.
Why it still matters
Seq2seq established the mental model that all of modern NLP runs on: cast a task as mapping an input sequence to an output sequence, learned end to end. Translation, summarization, question answering, dialogue, code generation — all are seq2seq problems, and this paper is where that framing was proven at scale on real machine translation.
Its exact ingredients live on. The encoder-decoder split survives in the Transformer and in T5. The autoregressive "generate a token, feed it back, stop at end-of-sequence" loop is exactly how GPT-style models write. And the bottleneck it exposed directly motivated attention — the mechanism that became the beating heart of the entire field.
Seq2seq (encode to one vector) → Attention (look back at all encoder states) → Transformer (drop recurrence, all attention). This paper is step one of that story.
How Sequence to Sequence Learning worked, step by step
The system in Sutskever, Vinyals and Le's paper is two deep LSTMs and a search procedure, trained on WMT'14 English-to-French. Nothing about either language is built in except the two vocabularies.
- Fix the vocabularies. The 160,000 most frequent English words form the input vocabulary and the 80,000 most frequent French words form the output vocabulary. Every other word is replaced by a single unknown token. Each word maps to a learned 1,000-dimensional embedding.
- Reverse the source, never the target. The English sentence a, b, c is fed in as c, b, a, while the French side keeps its normal order. The first source word now arrives last, immediately before the decoder writes the first target word.
- Encode with a deep LSTM. A 4-layer LSTM with 1,000 cells per layer reads the reversed sentence one word per step. Its state after the last word is the fixed-size representation v of the whole sentence.
- Decode with a second, separate LSTM. A different 4-layer LSTM with its own weights starts from v and works as a French language model conditioned on it. At each step it produces a softmax over the 80,000 output words, and the word it emits becomes its next input. Generation ends when it emits the end-of-sentence token. The authors note that two LSTMs instead of one add parameters at almost no extra compute.
- Train for likelihood. The objective is the average log probability of the correct French sentence given the English one. Training used a cleaned 12M-pair subset of the WMT'14 data (348M French words, 304M English words). Weights were initialised uniformly in ±0.08. The optimizer was plain SGD without momentum at a learning rate of 0.7, halved every half epoch after the fifth epoch, for 7.5 epochs in total, with minibatches of 128 sentences. The gradient norm was clipped at 5, and sentences of similar length were batched together, which roughly doubled training speed.
- Spread it over eight GPUs. Each of the four LSTM layers ran on its own GPU and the other four GPUs split the 80,000-way softmax. That reached about 6,300 words per second, and training took about ten days. The full model has 384M parameters, 64M of them recurrent connections.
- Search for the output. Decoding is a left-to-right beam search. It keeps the B most probable partial translations, extends each with every word in the vocabulary, keeps the B best again, and sets aside any hypothesis that has emitted end-of-sentence as finished. A beam of 1 already worked well and a beam of 2 gave most of the benefit. The headline numbers use 12.
- Or rescore a phrase-based system. In a second mode the LSTMs score each of the 1,000 best candidates produced by the phrase-based baseline. The final ranking takes an even average of the LSTM log probability and the baseline's own score.
What reversal changes, precisely
Reversal does not change the average distance between a source word and the target word it corresponds to. What it changes is the minimum: the first few source words end up a step or two from the first few target words, where before every pair was a whole sentence apart. The authors' explanation is that these short dependencies give backpropagation an early foothold between the two sentences, which then helps on the rest. They offer that as a hypothesis, not a proof.
Long sentences were not the failure
The paper reports that its LSTM handled long sentences well: BLEU showed no drop for sentences under about 35 words and only a small drop on the very longest. The authors credit the reversal for this. The well-known complaint that a single fixed vector cannot carry a long sentence came from Cho et al. and Bahdanau et al. in 2014, whose models did lose quality as sentences grew.
The seq2seq training objective, decoding rule and clipping rule
T̂ = argmaxT p(T | S) ≈ beam search with width B
if ‖g‖₂ > 5 : g ← 5 · g / ‖g‖₂
𝒮— the training set of (target T, source S) sentence pairs; J is the average log-likelihood the SGD steps climb.p(T | S)— the decoder's probability of the whole French sentence, a product of one softmax per word, each conditioned on v and the words already written.T̂— the translation the system outputs. The exact argmax would search every possible sentence, so a beam of width B approximates it.g— the minibatch gradient, divided by the batch size of 128 before the norm is checked.5— the clipping threshold. Below it the gradient passes unchanged; above it the direction is kept and the length is cut to 5.
At the extremes: B = 1 is greedy decoding, which the paper found already close; as B grows the search approaches the true argmax, with diminishing returns after 2. A clipping threshold of infinity means no clipping, which leaves training exposed to the occasional exploding gradient that LSTMs still produce; a tiny threshold would make every step the same length and turn SGD into sign-following.
What Sutskever, Vinyals and Le ran, and what it showed
All results are on the WMT'14 English-to-French test set (newstest2014), scored with BLEU on tokenized output. The comparison point is a strong phrase-based statistical system, which the paper also used as a source of candidate translations for its rescoring mode.
| System | Test BLEU |
|---|---|
| Phrase-based SMT baseline | 33.30 |
| Single LSTM, source in normal order, beam 12 | 26.17 |
| Single LSTM, source reversed, beam 12 | 30.59 |
| Ensemble of 5 reversed LSTMs, beam 1 | 33.00 |
| Ensemble of 5 reversed LSTMs, beam 12 | 34.81 |
| Baseline's 1,000-best list rescored by the ensemble | 36.5 |
| Best WMT'14 system | 37.0 |
The headline: a purely neural system, translating directly, beat a mature phrase-based system by 1.5 BLEU on a large task, even though every word outside its 80,000-word output vocabulary came out as an unknown token and was scored as wrong.
The ablations are the instructive part. Reversing the source cut test perplexity from 5.8 to 4.7 and was worth more than four BLEU points for a single model. Depth mattered too: each extra LSTM layer reduced perplexity by nearly 10%. Search mattered least: a beam of 1 on the ensemble already reached 33.00.
The paper also found that its model did not fall apart on long sentences, which is the opposite of what is often attributed to it. And a two-dimensional PCA projection of the sentence vectors showed them grouping by meaning, sensitive to word order and nearly unchanged between active and passive voice.
The negative result is the gap that remained. Direct translation stayed 2.2 BLEU short of the best WMT'14 entry, and the best neural figure, 36.5, still needed the phrase-based system to propose the candidates.
What the authors admit, and what happened next
The paper is candid that its most useful trick — reversing the source sentence — is an empirical finding it cannot fully explain, rather than dressing it up as a principle. It also reports something that surprised its own authors: the LSTM did well on long sentences, helped by that reversal. The long-sentence weakness of squeezing a whole input into one fixed vector was measured in other work the same year (Cho et al. on RNN encoder-decoders, and the Bahdanau et al. attention paper that answered it), not in this one.
It also depends on beam search at decoding time to get its headline numbers, and on an ensemble of models — so the reported figure is not what a single greedy model does, and the paper says so.
How it held up: the encoder-decoder frame survived completely, and the deeper claim — that a general sequence model trained end to end beats a hand-assembled pipeline of specialists — is now so thoroughly accepted that it is hard to see as a claim at all. The fixed vector did not last a year: Bahdanau and colleagues let the decoder look back at every encoder state through a learned weighting, which removed the bottleneck and introduced attention as a component. Rung 2's contribution is to notice that once you have that component, the recurrence it was bolted onto is no longer doing anything essential.
Beam search beats greedy decoding
A decoder that always grabs the single best next token is myopic — a great first word can lead into a dead end. Beam search, seq2seq's decoding trick, keeps the k most-promising partial sequences alive so a slightly-worse start can still win. This is the classic case: greedy commits to token A (0.50) and gets trapped, while beam keeps B (0.45) and rides it to a sequence 2.9× more likely. Set the beam width to 1 and it collapses back to greedy. Change the model probabilities and re-run.
Write the body of beam_decode. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 5 assertions below — they start red.
- Greedy commits to the locally-best first token
- Beam finds a different sequence than greedy
- Beam's total probability beats greedy's
- A wider beam never scores worse than a narrow one
- Beam width 1 is exactly greedy
Questions people ask about Seq2Seq
Why does reversing the input sentence help a seq2seq model?
Reversing the source, but not the target, puts the first source words right next to the first target words in time. The average distance between corresponding words is unchanged, but the shortest distances become one or two steps instead of a whole sentence. Sutskever, Vinyals and Le suggest that these short dependencies give backpropagation an easy starting connection between the two sentences, which then helps everywhere else. The effect was large: test perplexity fell from 5.8 to 4.7, and a single model gained more than four BLEU points on WMT English-to-French. The authors offered the explanation as a hypothesis. Reversal adds no parameters, which is why it is such a clean demonstration that distance in time, not capacity, was the obstacle.
Did the seq2seq paper find that long sentences hurt translation quality?
No. Sutskever, Vinyals and Le reported that their deep LSTM translated long sentences well: BLEU did not drop for sentences under roughly 35 words and dropped only slightly on the longest ones. They credited reversing the source sentence for this. The fixed-vector bottleneck argument, that one vector cannot carry a long sentence, was made by Cho et al. and Bahdanau et al. in 2014, whose encoder-decoder models did lose quality as sentences got longer. Bahdanau et al. answered it with attention, letting the decoder look back at every encoder state. The bottleneck is real as a design limit, but it is not what this paper measured.
How big was the original seq2seq model and how was it trained?
The encoder and decoder were separate 4-layer LSTMs with 1,000 cells per layer and 1,000-dimensional word embeddings, over a 160,000-word input vocabulary and an 80,000-word output vocabulary. That comes to 384M parameters, 64M of them recurrent connections. Training used about 12M English-French sentence pairs, plain SGD without momentum at learning rate 0.7, halved every half epoch after the fifth, 7.5 epochs in total, minibatches of 128, and gradient norms clipped at 5. Weights started uniform in plus or minus 0.08. It ran on eight GPUs, one per LSTM layer plus four for the softmax, at about 6,300 words per second, and took about ten days.
Did seq2seq beat phrase-based machine translation?
Yes, on direct translation. An ensemble of five reversed LSTMs with a beam of 12 scored 34.81 BLEU on WMT 2014 English-to-French against 33.30 for the phrase-based baseline, and the paper notes this was the first time a pure neural system beat a phrase-based one by a clear margin on a large task. It managed this despite having no way to produce words outside its vocabulary. It did not beat the best system of that year: the top WMT 2014 entry scored 37.0. The LSTM's best figure, 36.5, came from rescoring the phrase-based system's 1,000 best candidates rather than translating on its own.
How does beam search work in the seq2seq paper?
Decoding runs left to right. The search keeps B partial translations. At each step it extends every one of them with every word in the output vocabulary, scores the extensions by total log probability, and keeps the B best. A hypothesis that emits the end-of-sentence token is moved to the finished list. The paper reports that the model was strong enough for a beam of 1, plain greedy decoding, to work well, and that a beam of 2 gave most of the benefit of larger beams. The headline 34.81 BLEU used a beam of 12 on a five-model ensemble; the same ensemble at beam 1 scored 33.00.
4 questions to test what you just read
Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.
A 5-word source is translated word for word, so source word i lines up with target word i. Compute the step gap between each aligned pair with the source in normal order and reversed. Does the average gap change?
Show answer
Normal order: source word i is read at step i and target word i is written at step 5 + i, so every gap is 5. Reversed: source word i is read at step 6 − i, so the gaps are 1, 3, 5, 7, 9. The average is still 5. Only the minimum changes, from 5 to 1, which is exactly the effect the paper credits.
With a beam of 12 and the 80,000-word output vocabulary, how many extensions are scored at one decoding step, and how many survive?
Show answer
12 hypotheses × 80,000 words = 960,000 scored extensions per step, of which only the 12 most probable survive. Finished hypotheses leave the beam. This is why the 80,000-way softmax got four GPUs to itself.
A minibatch gradient has norm 12.5. What does the paper's clipping rule do to it, and what happens to a gradient of norm 3?
Show answer
The rule rescales any gradient longer than 5 to length 5: 12.5 becomes g × 5 / 12.5 = 0.4 g, so the direction is kept and the norm is 5. A gradient of norm 3 is under the threshold and passes through unchanged.
The five-model ensemble scores 33.00 at beam 1 while a single reversed LSTM scores 30.59 at beam 12. Why does the better model beat the better search here?
Show answer
Search can only find what the model ranks highly. Going from beam 1 to beam 12 lifted the ensemble by 1.8 BLEU (33.00 to 34.81), while ensembling five models lifted quality by more than that. Most of the error was in the model's probabilities, not in the search failing to find the model's favorite sentence.
The Transformer
The architecture itself: what it replaced, how position is encoded once recurrence is gone, and what it turns out to have learned inside.
- 1Seq2Seq2014
- 2Attention Is All You Need2017
- 3RoPE2021
- 4Concept Circuits2026
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- BERTThe paper that made "pre-train once, fine-tune anywhere" the default for NLP. Bidirectional context, masked language modeling, next-sentence prediction, the [CLS]/[SEP] tokens, and the GLUE sweep — explained with analogies, not just equations.Read →
- Chain-of-Thought PromptingShow a model a few worked examples with their reasoning and it starts solving problems it used to fail. Why reasoning emerges only at scale, the GSM8K jump, zero-shot "Let's think step by step", and how CoT seeded modern reasoning models.Read →
- LoRAThe paper that made fine-tuning affordable. Freeze the giant pretrained model and train two tiny low-rank matrices instead — up to 10,000x fewer trainable parameters, no extra inference latency, and swappable per-task adapters. The road to QLoRA and PEFT.Read →
- Direct Preference OptimizationRLHF without the RL. Align a model to human preference pairs with one simple classification-style loss — no separate reward model, no unstable reinforcement learning. Why "your LM is secretly a reward model", and how DPO became the default alignment method.Read →
- ChinchillaThe compute-optimal scaling law that said models were too big. Parameters and training tokens should scale together — ~20 tokens per parameter — so a 70B model trained on 1.4T tokens beat the 280B giants. Why every model since trains on trillions of tokens.Read →