Pre-training Objectives: CLM, MLM & Beyond

The fundamental pre-training tasks: causal language modeling, masked language modeling, prefix LM, denoising objectives (T5), UL2, and how the pre-training objective determines downstream capability.

Intermediate

Prerequisites

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. Causal Language Modeling (CLM)
  5. Masked Language Modeling (MLM)
  6. Prefix Language Modeling
  7. Denoising Objectives (T5/BART)
  8. UL2: Unifying Language Learning
  9. Contrastive Pre-training (CLIP)
  10. Choosing the Right Objective
  11. Common Pitfalls
  12. Summary
  13. Exercises

Learning Objectives

  1. Derive CLM and MLM loss functions and their information-theoretic interpretations.
  2. Explain why CLM dominates for generative models while MLM excels at understanding.
  3. Describe T5's span corruption and BART's denoising objectives.
  4. Explain UL2's mixture-of-denoisers approach.
  5. Choose the pre-training objective for a given downstream application.

Notation

  • x<tx_{<t} — tokens before position tt (causal context)
  • x\Mx_{\backslash M} — tokens with masked positions excluded
  • M\mathcal{M} — set of masked positions

Core Intuition

The pre-training objective defines WHAT the model learns from raw text. CLM (predict next token) teaches left-to-right generation — ideal for chatbots and code completion. MLM (predict masked tokens) teaches bidirectional understanding — ideal for classification and information extraction. The choice fundamentally shapes the model's capabilities, and modern approaches (UL2) combine multiple objectives.

Pretraining Objectives

MLMThe[MASK]catcatsatsatononmat[MASK]Mask random tokens, predict from bidirectional context (BERT)
Objective
0
MLMCLMPrefix LM
Explore: MLM uses bidirectional context (encoder), CLM is causal/autoregressive (decoder), Prefix LM combines both for seq2seq pretraining.

Causal Language Modeling (CLM)

Objective: Predict the next token given all previous tokens:

LCLM=t=1Tlogpθ(xtx<t).(1)\mathcal{L}_{\text{CLM}} = -\sum_{t=1}^T \log p_\theta(x_t | x_{<t}). \tag{1}

Properties:

  • Autoregressive: Each token depends only on previous tokens (causal mask).
  • Exact likelihood: Provides exact log-probability of sequences.
  • Generation: Natural fit for text generation (sample token by token).

Information-theoretic view: Minimizing CLM loss = maximizing the log-likelihood = minimizing the cross-entropy between model and true data distribution = minimizing KL divergence DKL(pdatapθ)D_{\text{KL}}(p_{\text{data}} \| p_\theta).

Models: GPT series, LLaMA, Mistral, Claude, Gemini.

Efficiency: Every token is a training signal (100% token utilization). For a sequence of length TT: TT predictions per sequence.


Masked Language Modeling (MLM)

Objective (BERT): Predict randomly masked tokens from bidirectional context:

LMLM=tMlogpθ(xtx\M).(2)\mathcal{L}_{\text{MLM}} = -\sum_{t \in \mathcal{M}} \log p_\theta(x_t | x_{\backslash\mathcal{M}}). \tag{2}

Masking strategy (BERT): 15% of tokens masked:

  • 80%: Replace with [MASK].
  • 10%: Replace with random token.
  • 10%: Keep original (model must decide if token is correct).

Properties:

  • Bidirectional: Each prediction uses FULL context (left AND right).
  • Not generative: Cannot naturally generate text (masking is artificial).
  • Understanding: Excels at classification, NER, QA — tasks needing comprehension.

Token utilization: Only 15% of tokens provide training signal (vs 100% for CLM). Need more data/steps for same effective training.

Models: BERT, RoBERTa, DeBERTa, ELECTRA.


Prefix Language Modeling

Hybrid: Bidirectional encoding of a prefix, autoregressive generation of the rest:

LPrefix=t=L+1Tlogpθ(xtxL,xL+1:t1),(3)\mathcal{L}_{\text{Prefix}} = -\sum_{t=L+1}^T \log p_\theta(x_t | x_{\leq L}, x_{L+1:t-1}), \tag{3}

where xLx_{\leq L} is encoded bidirectionally and x>Lx_{>L} is generated autoregressively.

Attention mask:

  • Prefix tokens (tLt \leq L): Full bidirectional attention.
  • Generation tokens (t>Lt > L): Causal attention (can see prefix + previous generated).

Use case: Conditional generation — encode a context (question, document) bidirectionally, then generate response autoregressively.

Models: UniLM, GLM, PaLM (partially).


Denoising Objectives (T5/BART)

T5 Span Corruption: Replace random spans with sentinel tokens; predict the spans:

Input: "The <X> sat on the <Y>." Target: "<X> cat <Y> mat </s>"

LT5=tlogpθ(yty<t,xcorrupted).(4)\mathcal{L}_{\text{T5}} = -\sum_{t} \log p_\theta(y_t | y_{<t}, \mathbf{x}_{\text{corrupted}}). \tag{4}

BART Denoising: Multiple corruption strategies + full reconstruction:

  • Token masking (like MLM).
  • Token deletion (model figures out what's missing).
  • Sentence permutation.
  • Document rotation.
  • Span masking.

Encoder-decoder architecture: Encoder processes corrupted input bidirectionally; decoder generates clean output autoregressively.

Advantage: Combines bidirectional understanding (encoder) with generation ability (decoder). Good at both comprehension and generation tasks.


UL2: Unifying Language Learning

Tay et al. (2022): Mix multiple denoising objectives with different "modes":

R-Denoiser (Regular): Short spans, 15% corruption. → Understanding tasks. S-Denoiser (Sequential): Causal prefix → generation. → Generation tasks. X-Denoiser (Extreme): Long spans, 50% corruption. → Long-range reasoning.

Mode tokens: Prepend [R], [S], or [X] to indicate which denoiser is being used. Model learns to adapt behavior based on mode.

Mixture: Randomly select mode per example: p(R)=0.5,p(S)=0.25,p(X)=0.25p(R)=0.5, p(S)=0.25, p(X)=0.25.

Result: Single model that excels at BOTH understanding and generation — matching specialized models on their respective strengths.


Contrastive Pre-training (CLIP)

For multimodal models: Learn aligned representations across modalities:

LCLIP=1Nilogesim(fI(xi),fT(ti))/τjesim(fI(xi),fT(tj))/τ.(5)\mathcal{L}_{\text{CLIP}} = -\frac{1}{N}\sum_i \log\frac{e^{\text{sim}(f_I(x_i), f_T(t_i))/\tau}}{\sum_j e^{\text{sim}(f_I(x_i), f_T(t_j))/\tau}}. \tag{5}

Properties:

  • No text generation (contrastive only).
  • Learns shared embedding space for images and text.
  • Enables zero-shot classification and retrieval.

Choosing the Right Objective

ApplicationBest ObjectiveReason
Chatbot/assistantCLMNeeds natural generation
Text classificationMLM/ELECTRANeeds understanding, not generation
TranslationEncoder-Decoder (T5)Needs both comprehension and generation
SummarizationPrefix LM or T5Encode document, generate summary
Code completionCLMStrictly left-to-right context
General purposeUL2 mixBest of all worlds

Common Pitfalls

Pitfall 1. Using MLM for a generative task. BERT-style models cannot naturally generate text — they can fill blanks but not write continuations.

Pitfall 2. Training CLM with too short context. CLM benefits enormously from long context during pre-training. Truncating to 512 tokens wastes potential.

Pitfall 3. Assuming more pre-training data always helps. With a fixed compute budget, there's an optimal data-to-parameters ratio (Chinchilla scaling). Too much data with too small a model hits diminishing returns.


Summary

  • CLM: Next-token prediction; autoregressive; best for generation (GPT, LLaMA).
  • MLM: Masked prediction; bidirectional; best for understanding (BERT).
  • Prefix LM: Bidirectional prefix + autoregressive generation; good for conditional tasks.
  • T5/BART: Encoder-decoder denoising; good at both understanding and generation.
  • UL2: Mixes all modes; single model excels everywhere.
  • The pre-training objective is the single most important design decision.

Exercises

Exercise 1. Compute the bits-per-character of a CLM model with perplexity 15 on English text.

Exercise 2. For MLM with 15% masking: how many training tokens are needed to match CLM's effective training signal on 1T tokens?

Exercise 3. Design a pre-training objective for a code model that needs both code completion (left-to-right) and code understanding (bidirectional).

Exercise 4. Prove that minimizing CLM loss is equivalent to maximizing the ELBO on the data log-likelihood.

Exercise 5. Compare UL2 vs separate CLM + MLM models: compute the parameter efficiency (performance per parameter) for each approach.