Reassociate a feature-map kernel without claiming exact softmax
Derive feature aggregation, positive normalization, causal prefixes, and the distinction between a new kernel and softmax approximation.
On this page
The question for today
What you’ll understand
- Reassociate a normalized finite-feature attention kernel.
- State positivity and nonzero-denominator assumptions.
- Distinguish exact finite-kernel computation from approximate exponential attention.
The word linear in linear attention refers to sequence-length scaling under a particular feature representation. If a similarity can be written as an inner product of finite feature vectors, associativity lets the key/value side be summarized before each query is applied. This avoids forming every query-key score explicitly. The result is exact for that chosen feature-map kernel, but it is not generally exact softmax attention. Replacing the exponential kernel with another positive similarity changes the operator; using random features to estimate the exponential kernel introduces approximation and numerical questions of its own.
Reassociate numerator and denominator together
Map each query and key into r-dimensional features. Summing feature-key outer products with values produces an r-by-dv matrix, and summing feature keys produces an r-vector. A query feature multiplies both summaries: the first gives its value numerator, the second its normalization denominator. Keeping the denominator is essential for the normalized operator. Omitting it produces an unnormalized feature aggregation whose output scale depends on the key population and feature magnitudes.
Nonnegative similarities and a strictly positive denominator make the output a meaningful weighted average. Nonnegative feature coordinates are one sufficient way to avoid negative pair weights, but zero features or an empty key set can still give a zero denominator. A numerical epsilon changes the operator and should be specified rather than treated as an invisible algebraic fix. The feature-map domain and valid input assumptions belong beside the formula.
Linear in N assumes the feature width is controlled
Given feature vectors, forming the summaries and applying N query features costs on the order of Nrdv arithmetic, with an aggregate state of rdv+r scalars for a streaming causal calculation. Feature construction adds its own cost, and output storage remains proportional to the query count. The attractive scaling assumes r and dv do not grow with N in the comparison. A very large feature width can erase the benefit even though no N-by-N score matrix is stored.
Causal attention uses prefix summaries rather than a summary of every key: after adding key/value j, only queries whose logical position permits that key may read the updated state. This recurrence resembles a recurrent model but does not grant arbitrary masks for free. Sliding windows need removals or another data structure, and general pairwise masks may destroy the single shared-summary factorization. Sequence packing must reset the state at the correct logical boundary.
A kernel estimate does not make the normalized ratio unbiased
The original linear-attention paper studies finite positive feature maps as alternative attention kernels. Performer studies random-feature approximations to the exponential similarity used by softmax-style attention. A finite alternative map can be computed exactly while differing substantially from exponential attention. A random-feature kernel estimate may have favorable expectation or concentration properties, yet dividing a random numerator by a random denominator does not generally yield an unbiased normalized output.
Evaluate error in outputs and gradients, and vary feature width, random seeds, input norms, and sequence length. Small denominators can amplify errors even when individual kernel estimates look reasonable. Also evaluate downstream task quality if the architecture changes. The same implementation can be mathematically correct for its finite feature map and a poor approximation to a target softmax distribution; correctness of reassociation and suitability of the similarity are separate claims.
Work it through
A finite kernel is exact but differs from exponential weights
For nonnegative scalar inputs use φ(x)=(1,x), so similarity is 1+qk. Let q=1, keys k=(0,2), and values v=(2,8). Compute the summarized normalized output, then compare with ordinary softmax using logits qk=(0,2).
Feature keys are (1,0) and (1,2). Their sum is z=(2,2), and their value-weighted sum is S=(10,16) as a two-by-one matrix. The query feature is (1,1), giving numerator 26 and denominator 4.
The finite-kernel output is 26/4=6.5. Direct pair weights are 1+1×0=1 and 1+1×2=3, so direct normalization gives (1×2+3×8)/(1+3)=6.5 as an exact check.
Exponential softmax instead uses weights 1 and e², giving (2+8e²)/(1+e²)≈7.284782. The difference is about 0.784782 because 1+qk is a different kernel, not because the summarized calculation dropped a term.
Reassociation exactly computes the specified positive finite-feature operator. It does not establish equality with exponential softmax attention.
The living notebook
Explore the model
Interactive lab · vectors
Raw dot products do not guarantee positive normalization
Reset, set Angle to 0° and Magnitude to 1. Relative to query (1,0), predict dot product x=1 before Step. Reset, set Angle to 180° and Magnitude to 1, predict dot product x=−1 before Step. Combining those raw dot weights would give denominator zero. This one-vector projection model does not implement feature maps or linear attention.
- x component
- 1.393
- y component
- 0.975
- Magnitude
- 1.7
Playback traces a fixed vector and its projections. Angle and magnitude set the geometry; the moving marker does not change them. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA feature representation needs an explicit positivity and nonzero-denominator contract; arbitrary signed dot products do not provide it.
Pause & reason
Check your understanding
Your turn
Try it yourself
Use the same φ(x)=(1,x), query q=2, keys (1,3), and values (1,5). Compute z, S, numerator, denominator, and normalized output.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Each key contributes its feature vector times its scalar value to S.
Compare with the solution
z=(1,1)+(1,3)=(2,4). S=(1,1)×1+(1,3)×5=(6,16). Query feature (1,2) gives numerator 6+2×16=38 and denominator 2+2×4=10, so output is 3.8. Direct positive weights are 3 and 7, giving (3×1+7×5)/10=3.8. The calculation remains a finite-kernel result rather than an exponential-softmax identity.
Keep the idea
Take it with you
- Finite features permit shared numerator and denominator summaries.
- Positivity, nonempty domains, and controlled feature width are assumptions.
- Exact reassociation is distinct from approximation to exponential softmax.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.