MLGuerrillaStart M1 →
Architectures·18 min read·Updated 24 September 2026

Encoder-only, decoder-only and encoder-decoder

These are the three ways a transformer can be wired. An encoder reads a whole input at once, a decoder writes one token at a time, and an encoder-decoder does one of each.

Encoder and decoder name two ways of reading a sequence. In an encoder, every position can read every other position, including the ones that come later. In a decoder, each position can read only what came before it. The BERT paper puts the naming in a footnote, where the bidirectional version "is often referred to as a Transformer encoder while the left-context-only version is referred to as a Transformer decoder since it can be used for text generation".

That one rule about what each position can see decides what the model is good for, how it's pretrained, what comes out of it and how you fine-tune it. This page covers all four, and it ends on how people are building their own version of Jev out of open models, which is the same question in a current form.

What it is

An encoder reads a whole input at once, and a decoder writes one token at a time

The original transformer (Vaswani et al., 2017) was built for translation and had both halves. An encoder turned the French sentence into vectors, and a decoder wrote the English sentence one token at a time while reading them. Everything since is built from one half of it, or from both.

A figure titled "The three shapes differ in what each position is allowed to read", with three stacked cards. The first card, Encoder-only, says every position reads every other position in both directions, and shows six token chips reading the, export, button, throws, a, 500, with the third chip highlighted and arcs connecting all six to it, captioned "the highlighted position reads all six". Its attention mask is a 6 by 6 grid with every cell filled, labeled "all open". What comes out is one vector per token, with a head on top that turns them into your labels, and the models built this way are BERT, RoBERTa, DeBERTa, ModernBERT, embedding models and rerankers, and ViT, the CLIP and SigLIP towers and DINOv3. The second card, Decoder-only, says each position reads only the positions before it, and shows the same six chips with the fifth highlighted and arcs reaching it only from the four on its left, captioned "position 5 reads 1 to 4, and nothing after it". Its attention mask is a lower triangle. What comes out is a probability for every next token, read at the last position or used to keep writing, and the models are GPT, Claude, Gemini, Llama, Qwen, reasoning models and agents, and almost every model sold as an LLM. The third card, Encoder-decoder, shows four input chips labeled "encoder, bidirectional" with an arrow into three output chips labeled "decoder, causal", noting that cross-attention carries the encoder's output into every decoder position, with one full mask and one triangular mask side by side. What comes out is a generated sequence conditioned on everything the encoder read, and the models are T5, Flan-T5, BART, mT5, Whisper, translation models and T5Gemma 2. The caption reads: the original transformer had both halves, and every model since is one half, the other half, or both.
The layers themselves are identical in all three. What changes is the attention mask and what you read off the end.

The three shapes differ in what they hand back.

  • An encoder returns one vector per input token. Those vectors are a representation of the text, and on their own they answer nothing. Something has to turn them into an answer, usually a head, which is a small output layer trained on your task that turns the vectors into a label or a score.
  • A decoder returns a probability for every token that could come next, at every position. Read that distribution at the last position and you have a one-step answer. Feed the chosen token back in and you have generation.
  • An encoder-decoder runs an encoder over the input and a decoder over the output, joined by cross-attention, which lets every decoder position read the encoder's finished vectors. The input gets read in both directions, and the output still gets written one token at a time.

Keep reading

The rest of this article is free with an account

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

  1. 02Which models are which shape
  2. 03The mask decides the shape, and the pretraining objective follows from it
  3. 04Fine-tuning changes with the shape
  4. 05Choosing a shape
  5. 06What the shape does not fix