Linear Attention › Linear Attention
Language AI HandbookAll chapters Linear Attention › Linear AttentionOne section · Sections in this chapter1 / 15 ↓
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
Standard self-attention computes a weighted sum of value vectors, where the weights come from a softmax over query-key similarities. This produces an attention matrix that must be explicitly computed and stored, leading to the quadratic bottleneck that limits transformers to modest sequence lengths. Linear attention takes a radically different approach: by replacing the softmax with a decomposable kernel function, it enables a clever reordering of matrix operations that eliminates the quadratic term entirely.
The main point is mathematical: if we can factor the attention weights into a product of separate functions applied to queries and keys, we can change the order of operations from to . The first form requires computing the full attention matrix. The second form computes first, which has shape (model dimension squared), independent of sequence length. This simple reordering maps complexity into . This makes attention linear in sequence length.
In this chapter, we explore how linear attention achieves this transformation, examine the kernel feature maps that make it possible, implement the mechanism from scratch, and analyze both its theoretical elegance and practical limitations. We also survey variants like Performer that address some of softmax attention's properties that linear attention initially sacrifices.