Training: nudging the weights
Measure how wrong the guess was, find which way each number should move, nudge, repeat.
Hover or tap a token to follow it. In step 5, drag the slider or tap − / +.
Training uses nothing but the four sentences cleaned in module 1: the same tokens and the same IDs. They hold 22 “guess the next token” questions, each with a known right answer.
Each question is a (context, next token) pair. This is self-supervised: the text supplies its own answers.
Training is four moves, repeated. Only the last move changes the model.
forward pass → loss → gradients (backpropagation) → gradient descent step. This next-token training is the only kind of training in this course; other methods are out of scope.
One number scores each guess: small when the right token got a big chance, big when it got a small one.
loss = −log p(right token). Called cross-entropy loss.
Subtract the right answer (1 for “sat”, 0 for the rest) from the chances. Negative → raise that score. Positive → lower it.
∂loss/∂scores = p − y, where y is the one-hot right answer.
The push travels back to the table U: each number moves by (cat's row × push), times a small step size.
∂loss/∂U = hᵀ(p − y); U ← U − η · ∂loss/∂U. The same idea reaches E, P and the W tables, one step further back each time (chain rule).
Drag the slider. Each step nudges every table using all 22 questions at once. The loss falls and “sat” wins.
150 steps of plain gradient descent, η = 0.3. All 26 frames are computed in Python, not in your browser.