C.W.K.
Stream
Lesson 09 of 10 · published

Encoder, Decoder, Encoder-Decoder — Three Shapes, Three Roles

~14 min · encoder, decoder, architecture-shapes

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The 2017 Transformer was an encoder-decoder. By 2024 the field has cleanly split into three shapes, and almost all frontier work uses just one of them.

ShapeAttention patternPre-train objectiveExamplesBest for
Encoder-onlyBidirectional (every token sees every other)Masked LM (predict hidden tokens)BERT, RoBERTa, DeBERTaClassification, NER, retrieval embeddings
Decoder-onlyCausal (each token sees only previous)Next-token predictionGPT-4/5, LLaMA 4, Claude, MistralGeneration, chat, code, agents
Encoder-decoderBidirectional encoder + causal decoder + cross-attentionSpan corruption / denoisingT5, BART, Whisper, NLLBTranslation, summarization, ASR

Why decoder-only won the LLM race

Three reasons. First, generation is built in: a model trained to predict the next token can generate by sampling. No separate decoder pretraining needed. Second, you can do classification or retrieval as generation tasks too, just by structuring the prompt. Third, the architecture is simpler — no encoder/decoder split, no cross-attention sub-layer, fewer hyperparameters to retune.

Encoder-only models did not vanish. BGE, E5, and other dense retrieval embeddings used inside RAG systems are encoder-only. But for "the model you talk to," decoder-only is the universal answer.

Code

Causal mask — what makes decoder-only 'decoder-only'·python
import torch
n = 6
mask = torch.triu(torch.ones(n, n), diagonal=1).bool()
# True where we should NOT attend (future positions)
# Position 0 sees nothing future; position n-1 sees everything past + itself.

scores = Q @ K.transpose(-2, -1) / (d_k ** 0.5)
scores = scores.masked_fill(mask, float('-inf'))
weights = torch.softmax(scores, dim=-1)
out = weights @ V

External links

Exercise

For each of the three shapes, find one currently-active production system that uses it and identify which property of the shape made it the right pick. (Hint: chat assistants → decoder-only; semantic search index → encoder-only; ASR → encoder-decoder.) Write 2-3 sentences for each.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.