Skip to content
AI-grafen
EUniversityTransformer architecture· about 60 min· evolving, reviewed regularly· verified 2026-09-20· EN

Encoder–decoder transformers

Be able to explain the T5/BART architecture and when encoder–decoder suits better than decoder-only.

Prerequisites

Intuition

Three families of transformers, with different jobs:

TypeAttentionTrained withExamplesGood at
Encoder-onlyfull, bidirectionalmasked tokensBERTunderstanding: classifying, extracting
Decoder-onlycausalthe next tokenGPT, Llamagenerating
Encoder–decoderthe encoder full, the decoder causal plus crossdenoising / seq2seqT5, BART, Whispertransforming A → B

Cross-attention is the key in the third: the decoder's queries fetch from the encoder's keys and values. The decoder therefore generates its answer while being able to «look at» the whole input the whole time — bidirectionally, in its entirety.

Formal

In an encoder–decoder block the decoder has three substeps:

  1. Causal self-attention over what has been generated so far: Q,K,VQ,K,V from the decoder's own states, with a triangular mask.
  2. Cross-attention: QQ from the decoder, KK and VV from the encoder's output HencH_{enc} — no mask, the whole input is visible.
  3. A feedforward layer.

That means the input is processed bidirectionally (the encoder sees the whole source text in both directions) while the output is generated autoregressively.

Why decoder-only dominates anyway: a sufficiently large decoder-only model can solve transformation tasks by having both the input and the output in the same sequence («translate into English: … →»). That gives a single simple architecture, simpler scaling and simpler training on unstructured text. Encoder–decoder keeps its advantage when the input and the output have clearly different roles and the input is long — translation, summarisation, speech-to-text (Whisper).

Mastery means

  • Explains the encoder–decoder architecture and cross-attention
  • Chooses between encoder-only, decoder-only and encoder–decoder

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences