Log inStart free
LESSON 9.10 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Linear attention

Watch attention trade its 16 × 16 weight grid for one small running state.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 9.10 · ATTENTION BAYROW 10 · SOFTMAX PEAK 0.32
01
Stage 1 of 6 · Softmax weights
Softmax attention fills a 16 × 16 grid of weights. Row 10 peaks at 0.32 on “warm”.
Explain it simply

Each row is one token looking back at the tokens before it. A strong shade means a large weight. Softmax raises e to the power of each score, so large scores get much more weight. The grid has a cell for every pair of tokens, so twice the length means four times the cells.

A grid of softmax weights, 16 rows by 16 columns, with the future masked. Row 10 gives 0.32 to token 10, warm.

above 0: weights, state, outputbelow 0q, k, v, KV cachedecay γmasked future
softmax weights a(t, j)key j →t ↓12345678910111213141516the 1cat 2sat 3on 4the 5mat 6because 7it 8was 9warm 10and 11the 12sun 13was 14out 15. 16masked: futurerow 10 “warm”: the weight on each key jthecatsatonthematbecauseitwaswarmandthesunwasout.0.240.32q₁₀o₁₀o = Σ a·v (softmax)0.281.600.05−0.06−0.160.950.11−0.65row 10: 10 scores q·k/√4, then softmaxpeak 0.32 on 10 “warm”whole grid: 136 weightssoftmax weights a(t, j)key j →t ↓12345678910111213141516the 1cat 2sat 3on 4the 5mat 6because 7it 8was 9warm 10and 11the 12sun 13was 14out 15. 16masked: futurerow 10 “warm”: the weight on each key jthecatsatonthematbecauseitwaswarmandthesunwasout.0.240.32q₁₀o₁₀o = Σ a·v (softmax)0.281.600.05−0.06−0.160.950.11−0.65row 10: 10 scores q·k/√4, then softmaxpeak 0.32 on 10 “warm”whole grid: 136 weights
Toy: the 16 tokens of 9.C2, one causal head, random untrained weights
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
atj=softmax⁡j ⁣(qt⋅kjd),ot=∑j≤tatj vj\sy{a}{out}{a_{tj}} = \operatorname{softmax}_j\!\Big(\tfrac{\sy{q}{data}{q_t}\cdot \sy{k}{data}{k_j}}{\sqrt{d}}\Big),\quad \sy{o}{out}{o_t} = \sum_{j\le t} a_{tj}\,\sy{v}{data}{v_j}
a10,10=0.315,∑ja10,j=1a_{10,10} = 0.315,\quad \textstyle\sum_j a_{10,j} = 1

The output mixes the values with softmax weights of scaled dot products.

Common mix-ups

MYTHLinear attention gives the same weights as softmax attention.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01If the decay is 0.5, how much does token 1 still count at token 16?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.