Encoder-only vs Decoder-only vs Encoder-Decoder
Three transformer families and what each is optimized for
Encoder-only understands text (BERT); decoder-only generates it (GPT, Llama); encoder-decoder maps input to output (T5, translation). Most modern LLMs are decoder-only.
Encoder-only
Glossary →Bidirectional attention over the input, then a task head. Used for understanding: classification, embedding, extractive QA. BERT is the archetype.
Best for: Text understanding: embeddings, classification, NER.
Decoder-only
Glossary →Causal (left to right) self-attention. Trained to predict the next token; generates by unrolling. GPT, Llama, Mistral, Claude are all this family.
Best for: Open-ended generation and general LLMs.
Encoder-Decoder
Glossary →Encoder reads the input bidirectionally, decoder attends to it while generating output. Original 'Attention Is All You Need' architecture, used by T5 and translation models.
Best for: Structured input to output tasks like MT and summarization.
At a glance
| Dimension | Encoder-only | Decoder-only | Encoder-Decoder |
|---|---|---|---|
| Attention pattern | Causal | Encoder-decoder cross-attention | Bidirectional |
| Training objective | Next-token prediction | Denoising (T5) or seq2seq | Masked language modeling |
| Generation | Native | Via decoder | None |
| Understanding tasks | Via prompting | Yes | Yes (strong) |
| Prototypes | GPT, Llama, Mistral, Claude | T5, BART, mT5 | BERT, RoBERTa |
| Modern default | Chat and general LLMs | MT + summarization | Embeddings + classification |
Key differences
- 1Encoder-only sees the full input at once (bidirectional); decoder-only sees only prior tokens (causal)
- 2Decoder-only generates; encoder-only can only classify or embed
- 3Encoder-decoder separates the input-understanding and output-generation stages
- 4Modern LLMs are almost all decoder-only because scaling and generation matter most
- 5For embeddings, encoder-only or decoder-only embedding heads (E5, BGE) are both used today
In the interview
- Saying encoder-only models can generate text
- Not knowing modern chat models are decoder-only
- Confusing 'encoder-decoder' with 'bidirectional' (they're not the same)
How to choose
Generation → decoder-only. Understanding → encoder-only. Structured mapping → encoder-decoder.
Common misconceptions
Myth: Encoder-decoder is the default modern LLM architecture.
Reality: GPT-style decoder-only stacks dominate modern LLMs. Encoder-decoder still wins on translation-shaped tasks.
Myth: Decoder-only can't do classification.
Reality: It can, via prompting or via decoder-only embedding heads (E5-Mistral, BGE-decoder). It's just not the historical shape for that task.
Memory aid
Encoder-only: reads. Decoder-only: writes. Encoder-decoder: reads, then writes.
Can you combine them?
Retrieval stacks routinely mix them: encoder-only embeddings for retrieval, decoder-only LLM for generation. The rare 'unified' stacks (RAG plus rerank plus generation) touch all three.