family · architecture
encoderâdecoder (seq2seq)
An encoder reads the source sequence; a decoder generates the target while cross-attending to it â the original Transformer wiring for translation, summarization, and T5/BART. Decoding is autoregressive, but pretraining objectives vary.
encoder+decoder+output head + autoregressive
âž open this recipe in the builder
An encoderâdecoder (or seq2seq) model splits the work of reading and writing between two separate networks. The encoder processes the full input at once and produces a contextual representation. The decoder then generates the output one token at a time, attending to the encoderâs representation at every step via cross-attention. This architecture handles variable-length inputs and outputs naturally â a 5-word source sentence can produce a 12-word translation â and it was the design that drove machine translation, summarization, and dialogue from the mid-2010s onward.
How it works
In the transformer form, the encoder is a standard bidirectional stack: every input token attends to every other, producing rich contextualized representations. The decoder runs autoregressively â each new token attends only to previously generated tokens (causal masking), plus it runs a cross-attention layer over the encoder output at each step. That cross-attention is the bridge: it lets the decoder ask âwhich parts of the source are relevant to what Iâm generating right now?â at every position.
The training objective is not fixed and varies by use case. Translation systems are typically trained with next-token prediction on target sentences directly (standard autoregressive loss). T5 and BART use span-denoising instead: corrupt the input by masking spans, then train the decoder to reconstruct those spans. The same architecture supports both, which is what makes encoderâdecoder models versatile.
Why the explicit split matters
Decoder-only large language models dropped the encoder entirely â they process prompt and response as a single autoregressive sequence. This simplification works at scale because a large enough decoder stack can implicitly encode an input while also generating an output. But the encoderâdecoder wiring is not obsolete: it remains the natural fit for translation-style tasks, produces stronger cross-lingual representations, and is easier to condition on structured inputs (code, tables) through the cross-attention interface.
Where youâll see it
T5 and BART are the dominant pretrained encoderâdecoder models; Flan-T5 and mT5 are multilingual extensions. The architecture also appears in speech (Whisper uses it to map audio encoder states to text decoder outputs) and in multimodal systems where an image or audio encoder feeds a text decoder through cross-attention.
Related concepts
- encoder â the reading half; processes source input bidirectionally
- decoder â the generating half; autoregressive, cross-attends to encoder output
- attention mechanisms â cross-attention is the glue between the two halves
- large language models â the decoder-only simplification of this architecture
- recurrent neural networks â the original seq2seq implementation before transformers
- bert â the encoder-only endpoint: drop the decoder entirely
Sources
- Attention Is All You Need (Vaswani et al., 2017) paper
- Sequence to Sequence Learning with Neural Networks (Sutskever et al., 2014) paper
- Neural Machine Translation by Jointly Learning to Align and Translate (Bahdanau et al., 2014) paper
- Visualizing a Neural Machine Translation Model (Jay Alammar, 2018) explainer