Last chapter's came from one specific design choice: softmax normalizes each query's row of scores independently, so nothing in that row can be known until every score in it exists. What if attention didn't need a full row before it could answer?
Switch queries. Both numbers move together, every time, because they're computing the same thing two different ways — one rescans all four keys from scratch, the other looks up a state that was built before any query even ran.
Drop softmax and score a query against a key with a plain dot product instead — no per-row normalization needed. The double sum every query requires then factors, by ordinary associativity:
- — the query vector for position , the one being scored against every key.
- — the key vector for position , one of the keys a query is compared against.
- — the value vector for position , the payload retrieved when key matches.
- — the index of the query currently being scored.
- — the index ranging over every key (and its paired value) in the sequence.
- The sums don't depend on the query
The parenthesized sums on the right don't mention at all — they're the same for every query, so computing them once (a single pass over the keys, ) and reusing them turns each query into one dot product instead of an rescan.
- Real layers add a feature map for non-negativity
Real linear-attention layers apply a positive feature map (commonly , where ELU is short for Exponential Linear Unit) to and before the dot product, so the "attention weights" stay non-negative the way softmax's do — this chapter uses the identity map to keep every number exact and checkable by hand, but the factoring trick itself doesn't depend on that choice at all.
The bold curve is the same quadratic from last chapter. The dashed one — , not — is what scoring every query the factored way actually costs: one pass to build the running state, one more to evaluate every query against it.
Four keys and values , scored against query :
- The naive way: rescan every key
Scores, one per key:
Weighted sum . Normalizer . Output .
- Build the state once, before any query
Building , one key at a time:
Summing: .
Building : . Neither nor mentions .
- Every query is now one dot product
- .
- .
Output — exactly the naive answer, with the four keys never rescanned.
Find the query, among the three candidates, whose linear-attention output is the largest.
This isn't an approximation of attention — for a linear kernel, it's the exact same number, just computed in a different order. The catch real linear-attention layers have to work around is that a plain dot product isn't guaranteed non-negative the way softmax's weights are, which is why exists in the real formula. The catch this chapter doesn't fix at all: that single running state has to summarize the entire key-value history in a fixed-size vector — it can't grow with the way softmax's full matrix implicitly can. The next chapter turns that constraint into the entire design of a new architecture: a state-space model that carries exactly one hidden state forward, one token at a time, on purpose.