esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Encoder-Only vs Decoder-Only vs Encoder-Decoder?

Encoder-only, decoder-only and encoder-decoder models: what each one reads and writes, and which design fits which job, explained for your AI interview.

In short

An encoder-only model reads text to label or score it, like BERT. A decoder-only model writes text one word at a time, like the GPT family. An encoder-decoder reads an input first and then writes an output, like the original Transformer or T5.

11 min readIntermediateVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

The three designs wire the Transformer differently. An encoder-only model, like BERT, reads everything at once and labels it, such as tagging a complaint email. A decoder-only model, like GPT, writes one word at a time, seeing only the words before it. An encoder-decoder, like the original Transformer or T5, reads an input and writes an output, which suits translation. I pick by the job: a label, free writing, or a rewrite of one text into another.

What are encoder-only, decoder-only and encoder-decoder models, in plain words?

A Transformer is the network design behind these models. The 2017 paper that introduced it builds on attention alone: each word weighs the other words around it.

Think of an insurance claims team. One clerk reads the whole claim file before writing a one-line decision. That is an encoder: it takes in everything first. A second clerk drafts a letter to the customer one sentence at a time, looking only at what is already on the page. That is a decoder. A third clerk reads the adjuster's notes and then writes the letter from them. That is the encoder-decoder pattern.

The same three roles show up in AI. A bank's complaint tool reads each email whole and tags it. A reply drafter writes its answer word by word. A translator for a machine maker reads the English manual, then writes the German one.

Key words

Encoder
The part that reads the input and builds a rich picture of each word.
Decoder
The part that writes output one token at a time.
Token
A chunk of text the model works on, often a word or part of a word.
Masking
A rule that hides the words a position is not allowed to look at. BERT's training also hides words, but that is a training trick, not this rule.

How does each design read and write text?

The designs differ on two points: whether a word may see words on both sides of it, and whether the model reads, writes or does both. The chart puts each design in its own column.

Three designs and how text flows through them

Encoder-only

Whole input

Every word arrives at once

Encoder

Each word reads both sides

Label or span

A tag, a score, or a picked-out phrase

Decoder-only

Words so far

Your prompt, then its own

Decoder

Sees only the words before

Next word

Added, then read again

Encoder-decoder

Source text

For example, a manual in English

Encoder

Reads the whole source

Decoder

Writes, reading the source back

Target text

For example, the German manual

  1. 1The whole input goes in at once, so every word can see every other word.
  2. 2The model returns a label or a span as its answer.
  3. 3The words so far go in, and the decoder may not look ahead.
  4. 4It picks one next word, which is added and read again.
  5. 5The source text goes in whole.
  6. 6The encoder hands its reading across to the decoder.
  7. 7The decoder writes the target one token at a time.
Each column is one design, read top to bottom. The encoder-only design reads everything and returns a label. The decoder-only design writes one word at a time. The encoder-decoder reads a source first, then writes a target.

Encoder-only models use the reading side alone. BERT's name says it: Bidirectional Encoder Representations from Transformers. It reads context from both sides in every layer. It is first trained on large amounts of plain, unlabelled text, then given one extra output layer for a task such as question answering.

BERT learns by hiding some words and guessing them from the words around them. The T5 paper calls BERT an encoder-only model, and its training goal is to rebuild the hidden tokens at the encoder's output. So it is built to fill in and classify.

Decoder-only models use the writing side alone. OpenAI's GPT-2 post says the model was trained simply to predict the next word in 40GB of Internet text. Its decoder is masked, so each word can look only backwards. The original Transformer paper says the rule exists to preserve the auto-regressive property, which means each new word depends only on the words already written.

Encoder-decoder models use both sides. The original Transformer was an encoder-decoder built for sequence-to-sequence tasks. The encoder reads the whole input. The decoder writes the output one token at a time, and each decoder layer has attention over the encoder's output.

Here is the masking rule in plain Python, on one refund note. Each line is one word, and a Y means that word may read the word in that column.

Python
# A refund note, read by two designs. Which words may each position look at?
words = ["Refund", "approved", "for", "the", "duplicate", "charge"]

def show(title, can_see):
    print(title)
    for i, word in enumerate(words):
        row = "".join("Y" if can_see(i, j) else "." for j in range(len(words)))
        print(f"{word:<10} {row}")

show("Encoder: every word reads the whole note", lambda i, j: True)
show("Decoder: each word reads only itself and the words before", lambda i, j: j <= i)

Output

Encoder: every word reads the whole note
Refund     YYYYYY
approved   YYYYYY
for        YYYYYY
the        YYYYYY
duplicate  YYYYYY
charge     YYYYYY
Decoder: each word reads only itself and the words before
Refund     Y.....
approved   YY....
for        YYY...
the        YYYY..
duplicate  YYYYY.
charge     YYYYYY

In the decoder block, Refund may read only itself, and each later word may read everything up to its own position. That one rule stops the model from peeking ahead while it writes.

Which design fits which job?

  • Encoder-only

    Tag or score

    A bank's complaint tool reads each email whole and tags it as a fee dispute, a lost card or a branch complaint.

  • Decoder-only

    Draft the reply

    A claims assistant writes a letter to a policyholder from the adjuster's notes, one word at a time.

  • Encoder-decoder

    Map one text to another

    A machine maker translates 2,000 pages of safety manuals from English into German and Polish.

  • “are designed to produce a single prediction per input token or a single prediction for an entire input sequence. This makes them applicable for classification or span prediction tasks but not for generative tasks like translation or abstractive summarization.”

    T5 paper, Raffel et al. (2019)

  • “Thus our design decision comes at the cost of potentially worse performance on tasks which empirically benefit from bidirectionality.”

    GPT-3 paper, Brown et al. (2020)

The trade-off goes both ways. Reading in both directions helps tasks like tagging, and the GPT-3 paper admits its one-way design may cost quality on tasks that gain from both directions. An encoder-decoder has two stacks to run.

Tip

Say the job first, then the design. A label from one input usually points to encoder-only, though a prompted decoder-only model can return a label too, so name the trade-off. Free-form writing points to decoder-only. Turning one long text into another points to encoder-decoder.

How would you choose a design for a new bank product?

A bank wants one tool that tags complaints and drafts replies. Here is how I would split the choice.

  1. 1

    Name the output

    A label, score or span from the input means encoder-only. Free text means decoder-only. Turning a long input into a new text means encoder-decoder.

  2. 2

    Check what labelled data you have

    Past complaints with labels suit a small encoder you can train further on your own examples. A decoder can start from a prompt alone. GPT-3 was applied that way, with no retraining.

  3. 3

    Test on your own emails

    Measure each design on real complaints from your own bank, with the costly wrong answers marked, before you trust any public test score.

My answer would be two models with two jobs: an encoder that tags complaints, and a decoder that drafts replies, which a person checks before anything is sent.

What does the interviewer want to hear?

A strong answer covers

  • The encoder reads the whole input and labels it. The decoder writes one token at a time.
  • BERT is encoder-only. GPT-style models use only the decoder. The original Transformer and T5 are encoder-decoder.
  • The key difference is attention direction: an encoder word reads both sides, a decoder word reads only the words before it, and masking enforces that.
  • Pick by the job: a label, free writing, or one text rewritten into another.
  • Name the trade-off, and don't call any one design the best for everything.

Common traps

  • Trap"BERT can write a reply too, just more slowly."

    BetterBERT is built to read and label. Its training fills in hidden words, and T5's authors say encoder-only models are not for generative tasks.

  • Trap"Decoder-only is always the best choice."

    BetterIt depends on the job. OpenAI's GPT-3 paper admits the one-way design may cost quality on tasks that need both directions.

  • Trap"Encoder-decoder is two models glued together."

    BetterIt is one network with two parts. Each decoder layer looks back at the encoder's output while it writes.

Can you spot the wrong design?

Spot the mismatch

Which of these four pairings of design and job is wrong?

Quick check

A hospital wants each discharge note tagged 'follow-up needed' or 'no follow-up'. Which design is built for this job, with no free text in the output?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q050What is causal (masked) attention?10 min
  2. Q051What is cross-attention?10 min
  3. Q055What is the KV cache, and why does it speed up generation?12 min
  4. Q062How does BERT differ from GPT?11 min
  5. Q063Masked vs causal language modelling?11 min
  6. Q073Walk through one decoder block's forward pass.12 min

Learn it in depth

Last updated on 26 November 2026

Choosing a model design for your product?

I design and build AI products and agents, including the system behind them. Book a short call and tell me what your model needs to read, write or label.