Prefix Language Modeling › Comparing Attention Patterns
Language AI HandbookAll chapters Prefix Language Modeling › Comparing Attention PatternsOne section · Sections in this chapter5 / 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
To understand prefix LM's unique position, let's compare it with causal and masked LM attention patterns:



The visual comparison reveals the key differences:
| Aspect | Causal LM | Masked LM | Prefix LM |
|---|---|---|---|
| Prefix attention | Causal | Bidirectional | Bidirectional |
| Target attention | Causal | Bidirectional | Causal |
| Generation | Yes | No | Yes |
| Context richness | Limited | Full | Hybrid |
| Use case | Pure generation | Understanding | Conditioned generation |
Prefix LM occupies the middle ground. It enables generation like causal LM while providing richer prefix representations like masked LM.

This plot quantifies the representational advantage of prefix LM. In the prefix region (positions 0-7), each token has full access to all 16 positions, just like masked LM. In the target region (positions 8-15), the attention span follows the causal pattern, growing linearly. The shaded area represents the additional context each prefix position gains compared to causal LM, which translates to richer representations that inform target generation.