MLGuerrillaStart M1 →
Text and language·15 min read·Updated 23 September 2026

Encoder-decoder models

These models pair an encoder that reads the input with a decoder that writes the output. T5 made every task look like a string in and a string out, and the shape still runs translation and speech-to-text.

An encoder-decoder model has two stacks. The encoder reads the input in one pass with every position able to see every other, and the decoder writes the output one token at a time while reading the encoder's vectors through cross-attention. It's the shape the original transformer was built with in 2017, for translation.

T5 (Raffel et al., 2019) made the shape general by writing every task as text in and text out, including classification, where the model writes the label as a word. That framing is where the name comes from, the Text-to-Text Transfer Transformer.

What it is

The input goes in whole, and the output comes out one token at a time

Both stacks are built from the same transformer blocks. The decoder differs in two places, a mask on its own attention and a second attention layer pointed at the encoder's output.

A three-part figure titled "The encoder reads all 12 tokens at once, the decoder writes one at a time", built from google/flan-t5-base translating one sentence, with 12 encoder blocks, 12 decoder blocks, 768 wide and 12 heads. The top band lays the architecture out left to right. The input, "translate English to French: The export button is broken.", is 12 tokens. It feeds an ENCODER card marked x 12 blocks, whose four stacked layers are self-attention with no mask, add and norm, feed forward 768 to 2048, and add and norm, with a note that 12 vectors come out and are computed once. A dashed terracotta line leaves that output and enters the DECODER card, also marked x 12 blocks, at its cross-attention layer. The decoder's six stacked layers are masked self-attention, add and norm, cross-attention from the encoder, add and norm, feed forward, and add and norm, with a note that it runs one position at a time. The decoder feeds an OUTPUT box, linear plus softmax, giving a probability for each of 32,128 tokens per step. The middle band, labeled ZOOM inside the encoder's self-attention, shows the 12 input tokens as chips, translate, English, to, French, colon, The, export, button, is, broken, period and end-of-sequence, with the chip for export highlighted and arcs connecting it to all eleven others, noting that the highlighted token reads all 12 including the six that come after it, and that every other token does the same in the same pass. The bottom band, labeled ZOOM the decoder, step by step, shows all sixteen decoding steps as chips with the token chosen and its probability: Le 32%, bouton 63%, de 36%, a space at 50%, l 72%, an apostrophe at 80%, ex 97%, port 100%, ation 90%, est 89%, a space at 35%, ren 7%, for 19%, c 92%, e-acute 94% and a period at 99%. The finished sentence reads "Le bouton de l'exportation est renforce", with an accent on the last e. A note says sixteen steps means sixteen forward passes through the decoder against one pass through the encoder, that the last word is wrong, and that step 12 is where it hesitated at 7%. The caption reads: same blocks on both sides, and the decoder adds a mask on its own attention and a second attention pointed at the encoder.
One pass through the encoder against sixteen through the decoder, for this one sentence. A decoder-only model with a KV cache would make the same one pass over its prompt and then sixteen steps, each through its whole stack.

Splitting the work in half has two consequences.

The input is read once, in both directions, and the result is reused for every output token. A decoder-only model with a KV cache also reads its prompt once, in one pass called prefill, and reuses the stored attention keys and values at every step after that, so both shapes pass over the input once. The difference is in how the input is read and what each output step costs. The encoder lets every input token see every other one, where a decoder-only model reads its prompt left to right. And each output step in an encoder-decoder runs only the decoder stack, which can be much smaller than the encoder.

That second point is the reason the halves can be sized independently. Google's T5Gemma release pairs a 9B encoder with a 2B decoder for exactly this reason, because summarization needs a deep reading of a long input and writes a short output.

Keep reading

The rest of this article is free with an account

Create a free account to read the remaining 6 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02Span corruption is what trains both halves
  2. 03Where the shape is still the default
  3. 04The models you'll see, as of September 2026
  4. 05Choosing between this and a decoder
  5. 06How to try it
  6. and 1 more