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

Softmax and its numerics

Watch 6 scores turn into weights, and see why softmax subtracts the max first.


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.02 · SOFTMAX BAY6 SCORES · MAX 2.89 · FLOAT32
01
Stage 1 of 6 · The scores
The query "sat" gives 6 scores s, one per key (9.01). Softmax turns them into weights that add up to 1.
Explain it simply

Each row is one key. Its bar is the score: how well that key matches the query "sat". A score can be negative or large. Here the largest is 2.89, on "the". Softmax turns the row into positive weights that add up to one. Scores are rounded to 2 decimals, so weights may differ from 9.01 in the third decimal.

Six rows, one per key. The scores are 2.89, 1.52, −1.50, −0.96, −0.29, 0.62. The largest is on "the".

scores, terms and weights amax minf and NaNrounds to 0
thecatsatonamatscores smax 2.892.891.52−1.50−0.96−0.290.62m = max s = s₁ = 2.89 · next s₂ = 1.52thecatsatonamatscores smax 2.892.891.52−1.50−0.96−0.290.62m = max s = s₁ = 2.89 · next s₂ = 1.52
Toy: the query "sat" of 9.05's 6 tokens · 1 head · scores to 2 decimals · random weights, not trained
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
si=q⋅kid\sy{s}{out}{s_i} = \frac{q \cdot k_i}{\sqrt{d}}
s=(2.89, 1.52, −1.50,−0.96, −0.29, 0.62)\begin{gathered}s = (2.89,\ 1.52,\ -1.50,\\ -0.96,\ -0.29,\ 0.62)\end{gathered}

Each score says how well key i matches the query.

Common mix-ups

MYTHSoftmax splits the weight in proportion to the scores.

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

Predict, then reveal
3 CHECKS · PRO
Q01With no shift at 10·s, what does float16 give?

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.