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

Sliding-window and local attention

Watch a window slide over 16 tokens and cut attention to a band.


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.08 · WINDOW BAYFULL · 136 SCORES
01
Stage 1 of 6 · Full attention
In full causal attention, each row reads every earlier token. One layer computes 136 scores.
Explain it simply

Each row of the grid is one word, and each column is an earlier word it can look at. The size of a square shows how much weight that word gets. With 16 words there are 136 squares, and that count grows with the square of the length.

A 16 by 16 grid. Row i holds one square for each token from 1 to i, sized by its weight. 136 squares in all.

Weights are random, not trained.
tokensattention weightswindowdropped weightmasked, full cost
the 11 thecat 22 catsat 33 saton 44 onthe 55 themat 66 matbecause 77 becauseit 88 itwas 99 waswarm 1010 warmand 1111 andthe 1212 thesun 1313 sunwas 1414 wasout 1515 out“.” 1616 “.”query ↓key →row 16 “.”: weights.041.052.073.024.045.106.077.048.109.1210.0411.0412.0413.1014.0515.0916sum 1.00full causal attention16 · 17 / 2 = 136 scoresthe 11 thecat 22 catsat 33 saton 44 onthe 55 themat 66 matbecause 77 becauseit 88 itwas 99 waswarm 1010 warmand 1111 andthe 1212 thesun 1313 sunwas 1414 wasout 1515 out“.” 1616 “.”query ↓key →row 16 “.”: weights.041.052.073.024.045.106.077.048.109.1210.0411.0412.0413.1014.0515.0916sum 1.00full causal attention16 · 17 / 2 = 136 scores
Toy: one 16-token sentence, model width 4
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
aij=softmax⁡j ⁣(qi⋅kjd),j≤i\sy{a}{out}{a_{ij}} = \operatorname{softmax}_j\!\left(\frac{\sy{q}{data}{q_i} \cdot \sy{k}{data}{k_j}}{\sqrt{d}}\right),\quad j \le i
n(n+1)2=16⋅172=136\tfrac{n(n+1)}{2} = \tfrac{16 \cdot 17}{2} = 136

Row i spreads its weight over every token up to i.

Common mix-ups

MYTHA token can never use words outside its window.

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

Predict, then reveal
3 CHECKS · PRO
Q01With a sliding window of 8 tokens, how many of the 136 scores remain?

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.