LLM & Transformer Fundamentals·Question 8 of 109Basic

What's the difference between causal language modeling and masked language modeling as pretraining objectives?

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

Causal LM (CLM): predict token t+1 given tokens 1..t, at every position, with attention causally masked. The loss is cross-entropy summed over all positions - an n-token sequence yields n prediction problems per forward pass, and 100% of tokens contribute signal.

Full worked answer

Causal LM (CLM): predict token t+1 given tokens 1..t, at every position, with attention causally masked. The loss is cross-entropy summed over all positions - an n-token sequence yields n prediction problems per forward pass, and 100% of tokens contribute signal.

Masked LM (MLM): corrupt the input by masking a subset of tokens (BERT masked ~15%) and predict the originals using bidirectional context. Only the masked positions produce loss, so per forward pass you get signal from ~15% of tokens.

Implications:

  • Generation: CLM models generate natively - sampling from the model is the objective's inference mode. MLM models can't generate coherently; there's no left-to-right factorization of the joint distribution.
  • Representation quality: MLM sees both sides of every position, which historically gave better representations per parameter for understanding tasks - why BERT dominated classification benchmarks in 2019-2020 and why embedding models still favour bidirectional attention.
  • Scaling and universality: CLM turned out to be the objective that scales into general-purpose capability. Next-token prediction over diverse data implicitly requires syntax, world knowledge, reasoning, and style - and in-context learning falls out of it. The 15%-signal inefficiency of MLM plus its lack of a generative mode made it a dead end for frontier-scale general models.
  • Train/inference mismatch: MLM's [MASK] token never appears at inference - a distribution shift BERT-era papers worked around; CLM has no such mismatch (though it has exposure bias: training always conditions on ground-truth prefixes, inference conditions on its own possibly-erroneous outputs).

Also worth knowing: T5-style span corruption is an encoder-decoder middle ground (mask contiguous spans, generate them), and some diffusion-style text models revisit non-autoregressive objectives, but CLM remains the backbone of every frontier model.

What a good answer covers

  • Causal LM (CLM): predict token t+1 given tokens 1..t, at every position, with attention causally masked
  • The loss is cross-entropy summed over all positions - an n-token sequence yields n prediction problems…
  • Masked LM (MLM): corrupt the input by masking a subset of tokens (BERT masked ~15%) and predict the…
  • Only the masked positions produce loss, so per forward pass you get signal from ~15% of tokens
  • Generation: CLM models generate natively - sampling from the model is the objective's inference mode

Key terms: Causal LM (CLM) · Masked LM (MLM) · Generation · Representation quality · Scaling and universality · Train/inference mismatch · span corruption

Interviewer follow-ups to expect

  1. What is exposure bias and how much does it matter in practice?

  2. Why does in-context learning emerge from next-token prediction?

  3. When would you still pretrain or fine-tune with MLM today?

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