Compare encoder-only, decoder-only, and encoder-decoder architectures. What is each used for?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Encoder-only (BERT lineage): bidirectional self-attention - every token sees the whole sequence - trained with masked-LM. Produces rich contextual representations but has no natural generation mechanism. Today it survives where representation quality per FLOP matters: embedding models for retrieval, rerankers, classifiers, PII/toxicity filters. Small, fast, cheap to serve.
Full worked answer with diagram
Encoder-only (BERT lineage): bidirectional self-attention - every token sees the whole sequence - trained with masked-LM. Produces rich contextual representations but has no natural generation mechanism. Today it survives where representation quality per FLOP matters: embedding models for retrieval, rerankers, classifiers, PII/toxicity filters. Small, fast, cheap to serve.
Decoder-only (GPT, Llama, Claude, Gemini): causal self-attention, trained on next-token prediction. This is the architecture of essentially every modern general-purpose LLM. Why it won: (1) generation is native; (2) every token position provides training signal in each pass, so it's data-efficient at scale; (3) one architecture and one objective handle every task via prompting - no task-specific heads; (4) it scales cleanly, and the entire tooling ecosystem (KV caching, serving stacks, RLHF pipelines) is built around it.
Encoder-decoder (original transformer, T5, Whisper, many translation models): the encoder reads the input with bidirectional attention; the decoder generates autoregressively while cross-attending to encoder outputs. Strongest fit when there's a clear input→output transform with a fixed input: translation, speech-to-text, structured summarisation. The bidirectional encode of the source is a genuine advantage there. Drawbacks for general chat: the input/output split is awkward for multi-turn conversation, and you can't incrementally extend "the input" the way a decoder-only model just appends to context.
Going further: follow-up territory
A nuance worth adding: decoder-only models can emulate the encoder-decoder pattern - the prompt plays the role of the encoded input - and prefix-LM variants allow bidirectional attention over the prompt while generating causally. In practice the industry consolidated on decoder-only for generative workloads and encoder-only for embeddings/reranking, with encoder-decoder holding niches like ASR (Whisper) and translation.
Worth sketching. Draw what attends to what rather than three labelled boxes: the attention pattern is the actual difference.
flowchart LR
IN["input tokens"] --> BI["bidirectional self-attention"]
BI --> REP["contextual vectors,<br/>no generation path"]
IN2["prompt plus tokens so far"] --> CA["causal self-attention"]
CA --> NXT["next token, appended"]
NXT --> IN2
SRC["source sequence"] --> ENC["bidirectional encoder"]
ENC --> XA["decoder cross-attends<br/>while generating causally"]
XA --> TGT["target sequence"]
What a good answer covers
- Encoder-only (BERT lineage)
- Produces rich contextual representations but has no natural generation mechanism
- Today it survives where representation quality per FLOP matters
- Decoder-only (GPT, Llama, Claude, Gemini): causal self-attention, trained on next-token prediction
- This is the architecture of essentially every modern general-purpose LLM
Key terms: Encoder-only · Decoder-only · Encoder-decoder
In the glossary: Encoder-only · Decoder-only · RLHF · Encoder-decoder · Attention · Reranking
Interviewer follow-ups to expect
Why do embedding models still use bidirectional attention?
What's a prefix LM?
If you were building a translation system today, would you pick encoder-decoder or a decoder-only LLM, and on what criteria?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep