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

Masking and causal masking

Watch a mask stop each token from reading later tokens and pad tokens.


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.03 · ATTENTION BAY6 TOKENS · SCORES −7.46 TO 3.39
01
Stage 1 of 6 · Raw scores
Each cell scores how strongly a query token looks at a key token.
Explain it simply

Each row is a token that asks, and each column is a token it could read. The number in a cell is the score: the dot product of the query and the key, divided by 2. A higher score means a stronger pull. Nothing yet stops a token from reading the tokens after it.

A grid of 6 by 6 scores. Rows are queries and columns are keys. The scores run from −7.46 to 3.39.

Weights are random, not trained.
values Vpositive scores, weights, outputs znegative scores, leaked weight, gapblocked cell
scores Skeys →← queriesthecatsatonamat1234561 the2 cat3 sat4 on5 a6 mat−7.46−2.353.392.54−1.28−2.03−3.20−1.010.501.75−3.68−2.642.891.52−1.50−0.96−0.290.621.701.29−0.56−0.870.801.10−1.930.710.570.65−1.70−0.71−1.56−0.820.180.98−1.93−1.53s₃,₁ = q₃·k₁ ÷ √4 = 2.89scores Skeys →← queriesthecatsatonamat1234561 the2 cat3 sat4 on5 a6 mat−7.46−2.353.392.54−1.28−2.03−3.20−1.010.501.75−3.68−2.642.891.52−1.50−0.96−0.290.621.701.29−0.56−0.870.801.10−1.930.710.570.65−1.70−0.71−1.56−0.820.180.98−1.93−1.53s₃,₁ = q₃·k₁ ÷ √4 = 2.89
Toy: 6 tokens, width 4, one head
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
S=Q K⊤d\sy{s}{out}{S} = \frac{\sy{q}{data}{Q}\,\sy{k}{data}{K}^{\top}}{\sqrt{\sy{d}{param}{d}}}
s3,1=q3⋅k14=2.89s_{3,1} = \frac{q_3 \cdot k_1}{\sqrt{4}} = 2.89

Each score is a query times a key, divided by the root of 4.

Common mix-ups

MYTHPad tokens are zero vectors, so they get no weight.

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

Predict, then reveal
3 CHECKS · PRO
Q01With 6 tokens, remove the mask. Does row 2 still match the step-by-step run?

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.