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

Sinusoidal positional encoding

Watch sine and cosine waves give every position its own vector.


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 · 10.04 · POSITION BAY8 TOKENS · “THE” ×2 · SAME COLUMNS
01
Stage 1 of 6 · No order
Each token gets its embedding column. The two columns for “the” are equal, so attention cannot tell them apart.
Explain it simply

Each column of boxes is one word's list of 8 numbers, its embedding. Look at the framed columns for the word the. They hold the same numbers. Attention compares only these numbers, so it can't tell the first the from the second.

8 token columns of 8 numbers. The columns for “the” at positions 0 and 4 hold equal numbers.

tokenswaves, shiftbelow 0above 0, dot
−0.6−0.4−0.10.30.1−1.00.10.3−0.30.6−0.50.8−1.0−0.30.4−0.8−0.60.0−0.2−0.5−0.3−0.20.1−0.80.40.20.80.40.4−0.30.7−0.8−0.6−0.4−0.10.30.1−1.00.10.3−1.00.4−0.9−0.6−0.5−0.5−0.40.90.90.90.40.0−0.5−0.10.80.60.4−0.40.50.70.60.4−0.4−0.3“the” at 0 and “the” at 4: the same column, distance 0the0cat1sat2on3the4mat5at6night7dim 0dim 1dim 2dim 3dim 4dim 5dim 6dim 7token embeddingsx of position p = e(token at p): no position yet−0.6−0.4−0.10.30.1−1.00.10.3−0.30.6−0.50.8−1.0−0.30.4−0.8−0.60.0−0.2−0.5−0.3−0.20.1−0.80.40.20.80.40.4−0.30.7−0.8−0.6−0.4−0.10.30.1−1.00.10.3−1.00.4−0.9−0.6−0.5−0.5−0.40.90.90.90.40.0−0.5−0.10.80.60.4−0.40.50.70.60.4−0.4−0.3“the” at 0 and “the” at 4: the same column, distance 0the0cat1sat2on3the4mat5at6night7dim 0dim 1dim 2dim 3dim 4dim 5dim 6dim 7token embeddingsx of position p = e(token at p): no position yet
Toy: 8 or 16 positions, width 8, seeded embeddings (not trained)
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
xp=e(tp)\sy{x}{data}{x_p} = \sy{e}{data}{e(t_p)}
∥e(t0)−e(t4)∥=0\lVert e(t_{0}) - e(t_{4}) \rVert = 0

The vector at position p is only its token's embedding.

Common mix-ups

MYTHA later position gets a larger position vector.

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

Predict, then reveal
3 CHECKS · PRO
Q01With base 10, do the bottom two rows of the table change more or less?

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.