Prefix Language Modeling › The Prefix LM Intuition

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

Book contents

Section 2 of 16 · 3 min read

Prefix Language Modeling › The Prefix LM IntuitionOne section · Sections in this chapter2 / 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

Consider a translation task: "Translate to French: The cat sat on the mat." The input prompt is complete and known. When generating "Le chat s'est assis sur le tapis," each French word depends on the entire English prompt plus previously generated French words. There's no benefit to hiding "mat" from "cat" in the English prompt.

Prefix LM captures this asymmetry. The sequence is split into two parts:

  • Prefix: The conditioning context (prompt, input, instruction). Tokens here can attend to each other bidirectionally.
  • Target: The continuation to be generated. Tokens here can attend to the full prefix plus their own left context, following causal constraints.

This hybrid attention pattern preserves the generation capability of causal LM while allowing richer representation of the prefix through bidirectional attention.

Out[4]:
Visualization
Diagram showing a sequence split into prefix and target regions with different attention patterns indicated by arrows.
Prefix language modeling splits the sequence into two regions. The prefix (blue) uses bidirectional attention where all tokens can see each other. The target (orange) uses causal attention, seeing the full prefix plus left context only. This hybrid approach combines the representational power of bidirectional models with the generation capability of autoregressive models.

This structure matches many real-world scenarios. In question answering, the question is the prefix and the answer is the target. In summarization, the document is the prefix and the summary is the target. In dialogue, the conversation history is the prefix and the next response is the target. The bidirectional prefix captures the full context, while the causal target enables coherent generation.