AI ENGVisual Encyclopedia

MODULE 1: OBJECTIVES & PARADIGM · SCENE 02

Two ways to hide the answer

Causal LM predicts every next token; masked LM fills blanks. The objective decides everything downstream.

8 TARGETS / PASS (100%)
ThequickbrownfoxjumpsoverthelazydogCLM: EVERY POSITION PREDICTS THE NEXT TOKEN (100% LOSS EFFICIENCY)

CLM predicts every next token autoregressively. One forward pass yields N-1 training targets.

TECHNICAL BREAKDOWNModule 1: Objectives & Paradigm

Causal Language Modeling (CLM) vs. Masked Language Modeling (MLM)

The choice of self-supervised training objective fundamentally dictates model architecture, inference latency, and generative capabilities. Masked Language Modeling (BERT) bidirectionally inspects context to fill in hidden tokens, while Causal Language Modeling (GPT / Llama) strictly predicts the next token given preceding context.

CLM Mechanics (Autoregressive)

CLM computes cross-entropy loss on every single token position in a sequence simultaneously using a lower-triangular causal attention mask. The model learns P(x_t | x_1, x_2, ..., x_{t-1}).

MLM Mechanics (Bidirectional)

MLM replaces ~15% of tokens with a [MASK] token. The model sees past and future tokens for unmasked tokens, computing loss only over the masked locations. While powerful for encoder tasks, it cannot generate long text autoregressively without N passes.

Why CLM Won the Generative Era

CLM computes N predictions per forward pass (one for each position in the context), making token-for-token training computational efficiency far higher than MLM (which only calculates loss on the 15% masked positions).

MATHEMATICAL FORMULATION · CAUSAL CROSS-ENTROPY LOSS
Loss_CLM = - (1 / N) * ∑_(i=1..N) log P( x_i | x_1, x_2, ..., x_(i-1) ; Θ )

The global loss is the mean negative log-likelihood of predicting each true token x_i given all prior tokens in the sequence.

REAL-WORLD PRODUCTION ENGINEERING
  • Every modern foundation model (GPT-4, Claude 3.5, Llama 3, Qwen 2.5) uses CLM pre-training.
  • Hybrid models like T5 or UL2 attempt unified objectives, but pure CLM remains the undisputed standard due to KV-cache inference compatibility.