Skip to content
AI.info

Deep architectures

Sequence-to-Sequence Architectures

Design sequence-to-sequence systems by separating encoder representation, decoder state, conditioning, alignment, training inputs, and generation behavior.

By the end you can

Seq2seq is a conditional distribution with an interface problem

A sequence-to-sequence model estimates an output sequence conditioned on an input sequence. The encoder builds representations of the source. The decoder predicts target elements under a chosen dependency order. The architecture has to decide what source information stays reachable at every target step. A single fixed vector is one option. It is worth knowing how well that option worked before studying how it broke.

One fixed vector was enough to beat the best translation system of its day. In 2014 Sutskever and his co-authors trained an ensemble of five deep LSTMs and squeezed every source sentence through a single vector. Four layers of 1,000 cells each. 380M parameters apiece in the published version, 384M in the preprint, which also describes an 8,000-dimensional sentence state. Their abstract states the outcome: “Our main result is that on an English to French translation task from the WMT-14 dataset, the translations produced by the LSTM achieve a BLEU score of 34.8 on the entire test set, where the LSTM's BLEU score was penalized on out-of-vocabulary words.” The tabulated figure is BLEU 34.81 at beam size 12 on the WMT'14 English-to-French test set. The phrase-based system it was competing with scored 33.30. Rescoring that baseline's publicly released 1000-best lists with the same ensemble reached 36.5. Felix Stahlberg, reviewing the field years later, calls it “one of the first working standalone NMT systems that did not rely on any SMT baseline”. One fixed vector, and the old technology was behind.

The most instructive number in that paper is not the headline one. Reverse the word order of every source sentence, leave the targets untouched, and test perplexity drops from 5.8 to 4.7. Decoded BLEU rises from 25.9 to 30.6. Stahlberg records the same fact independently: the authors “reported gains from simply feeding the sequence in reversed order”. Nothing about the language changed. Only where in the fixed vector the opening source words ended up. A preprocessing trick that large is a reading on the interface, not on the task.

The failure had a shape, and it was measured before it was named. Cho and three co-authors had the measurement in October 2014. When “the encoder extracts a fixed-length representation from a variable-length input sentence”, the resulting system “performs relatively well on short sentences without unknown words, but its performance degrades rapidly as the length of the sentence and the number of unknown words increase”. The culprit was named the year after, by Bahdanau and his co-authors at ICLR 2015. They “conjecture that the use of a fixed-length vector is a bottleneck in improving the performance of this basic encoder-decoder architecture”, and propose “allowing a model to automatically (soft-)search for parts of a source sentence that are relevant to predicting a target word”. The bottleneck was never in the language. It was in the interface.

The encoder–decoder boundary determines what the generator can consult while producing each output.

Visual

From fixed bottleneck to aligned access

The history changed the source–target interface one step at a time. First a fixed context vector, consumed by the decoder. Then soft alignment, where each decoder step combines source states with learned weights. Then multi-head cross-attention, where several learned projections retrieve source evidence. Then hybrid memory or retrieval, which exposes external or compressed context beyond the base encoder states.

The second step is the one that shipped, and it has a date. On 26 September 2016 Google posted the paper describing its Neural Machine Translation system, with thirty-one authors on it. The system is an LSTM with an 8-layer encoder and an 8-layer decoder. Its attention connects the bottom decoder layer to the top encoder layer. The abstract ends on the measurement: “Using a human side-by-side evaluation on a set of isolated simple sentences, it reduces translation errors by an average of 60% compared to Google's phrase-based production system.”

The following day GNMT went into production for Chinese-to-English in Google Translate — then about 18 million translations a day. The company's own announcement gives the range: “GNMT reduces translation errors by more than 55%-85% on several major language pairs measured on sampled sentences from Wikipedia and news websites with the help of bilingual human raters”. That is what the second step on this timeline was worth. Not a redrawn diagram. A production switch with a date on it, eighteen months after the bottleneck was named.

The boundary to the third step is marked exactly in Stahlberg's review, which takes GNMT as its worked example of a recurrent encoder-decoder: “GNMT (Fig. 13a) uses regular attention”, while the Transformer “uses multi-head attention”. The steps on this timeline are not eras. They are differences in how many learned projections get to consult the encoder states.

FigureTimeline · 4 stops
  1. Fixed context vector

    Encode the source into one vector consumed by the decoder.

  2. Soft alignment

    Let each decoder step combine source states with learned weights.

  3. Multi-head cross-attention

    Use several learned projections to retrieve source evidence.

  4. Hybrid memory and retrieval

    Expose external or compressed context beyond the base encoder states.

Comparison

Teacher-forced training and free-running inference

The decoder sees different histories in the two regimes. Teacher forcing feeds the ground-truth previous target during training: stable supervision, clean histories, and recovery failures that stay hidden. Autoregressive inference feeds the decoder its own generated outputs. That matches deployment, but an early error alters all later context, and the system needs stopping rules and search. Scheduled or mixed strategies expose the model to selected predicted histories during training. That reduces the mismatch and changes the training distribution.

Three regimes were measured side by side on the MSCOCO captioning development set in 2015, by Bengio and three co-authors. The teacher-forced baseline scored BLEU-4 28.8, METEOR 24.2, CIDEr 89.5. Always feeding the model its own sampled token — the regime that matches inference exactly — collapsed to 11.2 / 15.7 / 49.7. The scheduled mixture reached 30.6 / 24.3 / 92.1. So the mismatch is not a nuance for a limitations paragraph. Training the model purely on its own history takes BLEU-4 from 28.8 down to 11.2. The alternative is to tell the decoder, at every step, something it did not actually produce.

The mixture that wins the benchmark carries a defect of its own, found within a year. The critique came in November 2015, from Ferenc Huszar: “Here we show that despite this impressive empirical performance, the objective function underlying scheduled sampling is improper and leads to an inconsistent learning algorithm.” His argument is that the method “is not a consistent estimation strategy”. As the sampling rate goes to zero, the divergence is minimised at the factorised distribution rather than the true joint. Hold the two results together: 30.6 against 28.8 on the leaderboard, and an estimator that does not converge on the thing it is estimating. A benchmark column cannot show you the second fact.

FigureComparison · 3 columns

Teacher forcing

Feed the ground-truth previous target during training.

  • Parallel or stable supervision
  • Conditions on clean histories
  • Can hide recovery failures
  • Useful for efficient likelihood training

Autoregressive inference

Feed the decoder’s own generated outputs.

  • Matches deployment history
  • Errors alter future context
  • Requires stopping and search
  • Can drift after an early mistake

Scheduled or mixed strategies

Expose the model to selected predicted histories during training.

  • Attempts to reduce mismatch
  • Changes the training distribution
  • Can introduce optimization complexity
  • Requires careful evaluation

Example

Seq2seq appears wherever structures change length or representation

The architecture extends far beyond translation, and every destination brings its own baseline to beat. Summarization is the cautionary case. On the CNN/Daily Mail test set, a plain sequence-to-sequence-with-attention summarizer with a 50k vocabulary scored ROUGE-1 31.33. The pointer-generator with coverage that See and colleagues proposed in 2017 scored 39.53. Then the baseline: emit the article's first three sentences unchanged, no model at all, and score 40.34. Lead-3 beat every abstractive system in their table. Their own paper concedes the point: “It may be that news article style makes the lead-3 baseline very strong with respect to any metric”. Two years later a Salesforce Research team found the pattern intact and attributed it to layout bias in news corpora: “State-of-the-art models only slightly outperform the Lead-3 baseline, which generates summaries by extracting the first three sentences of the source document.” The architecture was working. The benchmark was measuring where the sentences sat in the document.

  • Speech recognition: acoustic frames become a shorter symbol sequence with uncertain alignment.
  • Machine translation: source words condition a target sequence whose order and length differ — the setting in which a fixed-vector LSTM ensemble reached BLEU 34.81 against 33.30, and in which GNMT cut errors by an average of 60%.
  • Summarization: a long document becomes a compressed sequence, and on CNN/Daily Mail the seq2seq-with-attention model scored ROUGE-1 31.33 while copying the first three sentences scored 40.34.
  • Program synthesis: a specification conditions structured code whose syntax constrains valid continuations.
  • Time-series repair: corrupted intervals condition a reconstructed sequence with physical continuity requirements.

Key idea

Attention weights are not guaranteed alignments

A decoder can use distributed source evidence, multiple heads, residual paths, or internal language priors. A visually sharp attention map may still be incidental or incomplete. If alignment matters operationally, evaluate it against annotations or interventions. Sequence quality alone does not establish faithful correspondence.

Two groups measured the gap instead of assuming it. Attention probabilities from Edinburgh's WMT16 systems match fast-align's word alignments 14.9% of the time for German-English, carrying 16.0% of the probability mass. English-German matched 77.2%. Czech-English, 78.0%. Russian-English, 72.5%. Same mechanism, same lab's systems, same benchmark year, and a spread that tracks the direction of translation rather than anything visible in the picture. Koehn and Knowles, who scored that overlap in 2017, state their finding 5 without hedging: “The attention model for NMT does not always fulfill the role of a word alignment model, but may in fact dramatically diverge.”

The other route is to treat the most-attended source word as a hard alignment and score it. Ghader and Monz did that in 2017, on the RWTH German-English hand-aligned set. The alignment error rate came out at 0.37 for an input-feeding attention model and 0.60 for a non-recurrent one. GIZA++ scored 0.31. A dedicated alignment tool from the previous technology still won.

The stronger reading has been tested head-on. Jain and Wallace ran that test in 2019, across a range of NLP tasks, and reported that “learned attention weights are frequently uncorrelated with gradient-based measures of feature importance, and one can identify very different attention distributions that nonetheless yield equivalent predictions”. Their conclusion is written as a rule rather than a caveat: “standard attention modules do not provide meaningful explanations and should not be treated as though they do”.

Architectural access and human-interpretable alignment are related but distinct claims.

Steps

Trace a seq2seq failure across the two sides

A poor output can originate in source representation, decoder dynamics, or search. A trace is only useful if it separates them.

1. Check source coverage. Identify omitted, duplicated, or overemphasized input regions.

2. Separate model score from decoding. Compare greedy, beam, constrained and sampled outputs. On one Transformer and one test set, greedy scored BLEU 29.3, beam-10 scored 30.3, and exact search over the same distribution scored 2.1. This step is not a formality you can skip when the numbers look reasonable.

3. Inspect prefix recovery. Introduce one wrong token and measure whether the decoder can return to a valid trajectory. The 11.2 BLEU-4 recorded for pure free-running training on MSCOCO is what the absence of that ability looks like at the extreme.

4. Slice by length and structure. Evaluate long inputs, long outputs, rare reorderings and repeated motifs. Two of the findings above are length findings wearing other clothes: reversing the source moved BLEU from 25.9 to 30.6, and exact search produced a length ratio of 0.06.

5. Test stopping behavior. Measure premature termination, endless loops and length bias. The empty translation is the limiting case of premature termination, and on one standard set it is the model's own global optimum for 51.8% of sentences.

FigureProcess · 5 steps
  1. 1. Check source coverage

    Identify omitted, duplicated, or overemphasized input regions.

  2. 2. Separate model score from decoding

    Compare greedy, beam, constrained, or sampled outputs.

  3. 3. Inspect prefix recovery

    Introduce one wrong token and measure whether the decoder can return to a valid trajectory.

  4. 4. Slice by length and structure

    Evaluate long inputs, long outputs, rare reorderings, and repeated motifs.

  5. 5. Test stopping behavior

    Measure premature termination, endless loops, and length bias.

Analogy

A speaker consulting notes while answering

A speaker answers a detailed question after reading a report. Memorizing one sentence from the report resembles a fixed context vector. Consulting highlighted passages resembles attention over encoder states.

The analogy predicts the reversal result. If all you keep is a single memorized summary, the order in which you read the report changes what survives in it. That is why turning every source sentence backwards, with the targets untouched, moved perplexity from 5.8 to 4.7 and BLEU from 25.9 to 30.6.

A highlighted passage can be quoted and checked against the page. Neural alignment is a weighted computation, not a verified citation. Direct access can reduce pressure on one compressed summary.

Attention changes the source interface from one summary to selective access over many representations.

Position

Attention was introduced to widen a channel, not to explain a decision

Almost everyone meets attention for the first time as a picture: a grid of source positions against target positions, bright where the model was supposedly looking. The paper trail behind the mechanism says what it was built for. Looking is not it.

The mechanism was a repair to a measured failure. Cho and his co-authors had the measurement in October 2014. An encoder–decoder that compresses a variable-length sentence into a fixed-length representation “performs relatively well on short sentences without unknown words, but its performance degrades rapidly as the length of the sentence and the number of unknown words increase”. Bahdanau and his co-authors named the culprit at ICLR 2015. They “conjecture that the use of a fixed-length vector is a bottleneck in improving the performance of this basic encoder-decoder architecture”. Then they phrased the proposal as access rather than insight: “allowing a model to automatically (soft-)search for parts of a source sentence that are relevant to predicting a target word”. That is a fix for a capacity problem. Nothing in that framing claims the resulting weights are the reason for the output.

The explanatory reading arrived afterwards, from readers rather than from the design. Tested, it did not hold. Jain and Wallace reported in 2019 that “learned attention weights are frequently uncorrelated with gradient-based measures of feature importance, and one can identify very different attention distributions that nonetheless yield equivalent predictions”. Sit with the second half for a moment. If some other distribution would have produced the same answer, the bright cells on display were one arrangement among several the model would have accepted. That is not what the word explanation is normally taken to mean. Their conclusion is written as a rule: “standard attention modules do not provide meaningful explanations and should not be treated as though they do”.

The honest description sits between noise and reason. Ghader and Monz put a shape on it. Attention “agrees with traditional alignments to a high degree in the case of nouns”, but “captures other information rather than only the translational equivalent in the case of verbs”. The map is a real record of routing. It coincides with linguistic alignment for some word classes and some language pairs — 77.2% overlap in one direction, 14.9% in another. The picture itself gives you no way to tell which case you are looking at.

The map is still worth drawing, as a routing diagnostic on the architecture's own terms: a picture of how one decoder step weighted the source states available to it. It becomes a claim about why only when something else carries it — an intervention, an ablation, a comparison against annotated alignments of the kind that produced the 0.37 error rate. Where a product tells a user that the highlight is the reason, the promise is the thing to test, not the picture.

If a different distribution would have produced the same answer, the one you were shown is not the reason.

Generation policy is part of the system behavior

Greedy decoding, beam search, sampling, constraints and length penalties can produce different outputs from the same model. The architecture defines conditional scores. The decoding procedure chooses a path.

How far apart can those two things drift? Far enough that the model's own best answer is silence. Stahlberg and Byrne ran exact inference — not a wider beam, exact — over the entire WMT15 English-German news-test2015 set, 2,169 sentences, with a Transformer base model. Greedy decoding scored BLEU 29.3 with 73.6% search errors. Beam-10 scored 30.3 with 57.7%. Exact search, which by construction commits no search errors at all, scored 2.1, at a length ratio of 0.06. The reason is in their abstract: “For more than 50% of the sentences, the model in fact assigns its global best score to the empty translation, revealing a massive failure of neural models in properly accounting for adequacy.” The precise figure is 51.8%. Even a beam of 100 still leaves 53.62% search errors. Eikema and Aziz treat the result as established — “the evidence that Stahlberg and Byrne (2019) provide is strong” — and add a sampling measurement of their own: an empty sequence appears at least once in 1,000 samples for only 7.2%-29.1% of held-out inputs.

Read that as a fact about reporting. A published BLEU of 30.3 there is a joint property of two things: a model whose highest-scoring output is silence, and a search too weak to find it. Credit the number to the architecture and you have credited it to the wrong half of the system.

The milder version of the same effect is routine. Across eight language directions, at beam sizes from 1 to 1,000, quality peaks at a narrow beam and then falls. Koehn and Knowles state it as their finding 6: “Beam search decoding only improves translation quality for narrow beams and deteriorates when exposed to a larger search space.” The optimal beam ranges from 4 for Czech-English to about 30 for English-Romanian, a factor of seven across language pairs. Sentence-length normalisation helped in 5 of the 8 pairs and does not remove the decline. The main cause is that wider beams produce shorter translations. Stahlberg's review reproduces the pattern on a Transformer for English-German WMT15. BLEU peaks at beam size 10, and wider beams give “a steady drop in translation performance because the generated translations are becoming too short”. The optimal beam has to be retuned per architecture, training technique and language pair.

Report both pieces. An unreported beam size can move a result further than an architecture change.

Sequence architecture and decoding algorithm form one observable generator.

Key takeaways