Prefix Language Modeling › Prefix Language Modeling

Michael BrenndoerferUpdated July 14, 20252 min read
Language AI HandbookAll chapters
Part 22 of 67Pre-training Objectives
Chapter 159Prefix Language Modeling › Prefix Language Modeling
Reading section 1 of 16 · Prefix Language Modeling · 2 minSection 1 of 16 · 2 min

Book contents

Section 1 of 16 · 2 min read

Prefix Language Modeling › Prefix Language ModelingOne section · Sections in this chapter1 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

What if you could have the best of both worlds? Causal language modeling excels at generation but sees only left context. Masked language modeling captures bidirectional context but cannot generate text autoregressively. Prefix Language Modeling (Prefix LM) bridges this gap by treating part of the input bidirectionally and the rest causally, enabling models that both understand context deeply and generate fluently.

The key insight is simple: when generating a continuation of a prompt, the prompt itself is fully known. There's no reason to hide later prompt tokens from earlier ones. Only the generation, which unfolds token by token, requires causal masking. Prefix LM formalizes this intuition into a training objective that powers models like T5, UniLM, and UL2.

In this chapter, we'll explore the prefix LM formulation, understand its distinctive attention pattern, implement the objective from scratch, and examine how it enables unified models for both understanding and generation.