Drag each answer to line up with its matching prompt
Encoder-only (BERT, ModernBERT)
Masked language modeling, predict tokens hidden behind a [MASK] using bidirectional context
Decoder-only (GPT, Llama, Claude)
Span corruption denoising, replace spans with sentinel tokens, decoder reconstructs the original spans
Encoder-decoder (T5, FLAN-T5)
Supervised audio to text seq2seq, encoder reads spectrograms, decoder autoregressively emits text
Encoder-decoder cross-modal (Whisper)
Causal next token prediction, predict each token from only the tokens that preceded it
Each architecture family has a canonical objective that fits its attention mask. Encoder-only uses MLM (bidirectional). Decoder-only uses next-token (causal). Text encoder-decoder uses span corruption.
Think of each transformer family like a different kind of student with a different study method. The encoder-only student (BERT) reads the whole sentence at once with some words hidden behind sticky notes, then guesses what is under each sticky note, this is masked language modeling. The decoder-only student (GPT, Llama) reads one word at a time and tries to predict the next word, never peeking ahead, this is next-token prediction. The text encoder-decoder student (T5) reads a sentence with whole phrases hidden, then has to write out the missing phrases one by one in a separate notebook, this is span corruption. The cross-modal student (Whisper) listens to an audio recording and writes down what was said in text form, this is supervised audio-to-text. Each method matches the architecture's attention pattern, which is why the pairings are not arbitrary.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The four transformer architecture families (encoder-only, decoder-only, encoder-decoder, cross-modal encoder-decoder) each have a canonical pretraining objective. The pairings are not arbitrary; they are determined by the attention mask of the architecture and what kind of supervised signal can be extracted from raw data given that mask. Getting the pairings right is the foundation for understanding why decoder-only models dominate modern LLM development, why encoder-only models still matter for retrieval, and why cross-modal applications need encoder-decoder structure.
Encoder-only with MLM
BERT and its descendants pretrain with masked language modeling. The recipe: randomly mask 15% of input tokens (replace with [MASK] in 80% of cases, with a random token in 10%, leave unchanged in 10%), then use bidirectional attention to predict the original tokens.
Why MLM works for encoder-only. The encoder's attention has no causal mask. Every token can attend to every other token in both directions. This lets the model use left context (tokens 1 to i-1) AND right context (tokens i+1 to L) to predict token i. The bidirectional signal is what makes MLM effective: predicting 'cat' in 'the [MASK] sat on the mat' is much easier when you can see 'sat on the mat' than when you can only see 'the'.
Why MLM does not work for decoder-only. A causal mask blocks attention to future positions. With a causal mask, MLM on token i could only use tokens 1 to i-1, which is just causal language modeling with extra steps. The 15% masking would just be discarded signal, no benefit.
Variants and modern usage. ELECTRA replaces MLM with replaced-token detection (RTD), more sample-efficient. ModernBERT (2024) revives the encoder-only family with MLM plus modernized tokenization (BPE), RoPE positional encoding, and a 8k context window. Encoder-only models are still the foundation for retrieval embeddings (Sentence-BERT, ColBERT) where bidirectional understanding matters more than generation.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- BERT-base (2018): 12-layer encoder pretrained with MLM on Wikipedia + BookCorpus. The model that established MLM as the canonical encoder-only objective.
- Llama 3.1 (2024): 8B / 70B / 405B decoder-only models pretrained with causal next-token on 15T+ tokens. The current open-weight standard for decoder-only + next-token.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does next-token prediction give more training signal per token than MLM?
Next-token treats every token in the sequence as a prediction target (L predictions per L-token sequence). MLM masks 15% of tokens so only ~0.15L predictions per L-token sequence. At trillion-token scale, the 6x signal density compounds into a real sample-efficiency advantage that favors decoder-only models.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Assuming any architecture can use any objective. The objective has to match the attention mask: causal masks force next-token prediction, bidirectional masks enable MLM, encoder-decoder masks enable span corruption.
60 second bullets to scan on the way to the call.
Why bidirectional attention enables MLM and forbids next-token prediction
Why causal masks enable next-token prediction and forbid MLM
Primary sources. Browse if you want the original framing.
- Devlin et al., BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (MLM)
- Radford et al., Language Models are Unsupervised Multitask Learners (GPT-2, next-token at scale)
- Raffel et al., Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (T5, span corruption)
- Radford et al., Robust Speech Recognition via Large-Scale Weak Supervision (Whisper)
Same topic, related formats. Practice these next.