Appendix B — The Encoder vs. Decoder Cheat Sheet

Technical course on encoder LLM mechanics — Appendix to all lessons.


Where this fits

This appendix collects every contrast drawn across the ten lessons into one place, organized by where in the stack the difference lives. Use it as a lookup table when you need the short answer, with a pointer back to the lesson that derives it. The single root cause to keep in mind: a decoder is causal and generates the next token; an encoder is bidirectional and emits representations. Every row below is a consequence of that one difference (Lesson 1).


One deleted mask, and everything that follows from it

Figure 1. One deleted mask, and everything that follows from it.

The master table

AspectDecoder (GPT/Llama-style)Encoder (BERT-style)Lesson
Core object$f(x;\theta)\to\Delta^{V-1}$ (next-token distribution)$g(x;\theta)\to\mathbb R^{n\times d}$ (contextual vectors)1
Directioncausal (left-to-right)bidirectional (both sides)1, 3
Factorizationautoregressive $\prod_t P(x_t\mid x_{\lt t})$none (no valid joint)1, 7
Purposegenerate textunderstand / represent text1
Tokenizertypically BPEtypically WordPiece (## marks)2
Input embeddingtoken + positiontoken + segment + position2
Special tokensminimal (chat markers)[CLS], [SEP], [MASK], [PAD]2
Position schemeRoPE / ALiBi (extrapolates)learned-absolute, ≤512 (ModernBERT: RoPE)2
Attention maskcausal + paddingpadding only (no causal)3
Attention matrixlower-triangularfull $n\times n$3
Block normtrend pre-LNoriginal post-LN4
Privileged positionlast token (sees whole prefix)[CLS], position 0 (by convention)4
Pretraining objectivenext-token predictionmasked language modeling (denoising)5
Signal density100% of positions scored~15% of positions scored5, 8
Coherence signalimplicit in next-tokenNSP (dropped) / SOP5
Output headone vocabulary projection, everywheretyped heads per task (pooled / per-token / span)6
Sequence summarylast hidden state (automatic)pooling choice ([CLS] / mean)6
Intrinsic metricperplexity (well-defined)undefined; pseudo-perplexity stand-in7
Primary evaluationzero-/few-shot generation qualityGLUE/SQuAD/MTEB after fine-tuning7
Inference shape$n$ sequential passes + KV cache1 parallel pass, no KV cache1, 3
AdaptationSFT / RLHF / DPO / promptingattach typed head + supervised FT9
Needs labeled data to adapt?often no (few-shot)yes9
Output typesampled textstructured label / tags / span / vector6, 9
Can it generate?yes (its whole point)no1, 3

The master contrast, selected rows

Figure 2. The master contrast, selected rows.

The one-paragraph summary

A decoder hides the future with a causal mask so it can be trained to predict the next token, which makes it a generator: it factorizes sequences autoregressively, runs an $n$-step KV-cached loop at inference, routes every task through one vocabulary head, is measured by perplexity, and is adapted by alignment or prompting. An encoder deletes that mask, so every token sees the whole sequence; this kills next-token training (the answer is visible), forcing the masked-language-modeling denoising objective that scores only ~15% of positions; it emits a matrix of contextual representations rather than a distribution, so it needs typed heads and pooling to make predictions, has no perplexity (no valid joint), runs in a single parallel pass with no KV cache, and is adapted by supervised fine-tuning on labeled data. Decoders generate; encoders understand; encoder–decoders transform; and real systems (RAG) use them together.


Decision rule, compressed

flowchart TD Q{"Do you need to
produce new text?"} Q -->|yes| G{"Transform a long
given input into output?"} Q -->|"no — classify, tag,
extract, or embed"| E["ENCODER
(single pass, typed head)"] G -->|yes| ED["ENCODER–DECODER
(T5 / BART)"] G -->|"no — free-form
chat / completion"| D["DECODER
(autoregressive)"] E --> RAG{"Building search
or RAG?"} RAG -->|yes| BOTH["BOTH:
encoder retrieves,
decoder generates"]

The decision rule, compressed

Figure 3. The decision rule, compressed.


← Course index · Extends every lesson

Appendices: A — Encoder Family · B — Encoder vs. Decoder Cheat Sheet · C — Acronyms


The figures in this lesson follow the shared figure key , which explains what every shape, line style and colour means.