← All labs

One training step

How does a single update change a prediction?

Back to journey scene 8
A tiny model with one output layer guesses which of four words comes next. Training compares the guess with the correct word, computes the loss, the gradient, and nudges the weights. This website never trains Qwen; only these toy weights change.

One example, one update at a time

Toy calculation· 3 inputs, 4 candidate words
Correct next word:
Prediction (shares)
  1. cat21.7%
  2. dog ◎25.5%
  3. car35.1%
  4. sun17.8%

Loss = −log p(target) = 1.3679

∂loss/∂score = p − target
0.220-0.7510.3520.183
Update rule

W ← W − η · hᵀ(p − target)

Every weight moves a little in the direction that lowers this example's loss.

Predict: after one update p(dog) will…
Predict first

If p(target) is already 99%, how big is the gradient for the target's score?

Predict first

Does generating text with a model update its weights?

From this toy to Qwen
Qwen3-8B-Base was pretrained with the same idea (predict the next token, cross-entropy loss, gradients through every layer by the chain rule, an optimizer step) applied to all 8,190,735,360 parameters over a very large corpus. Instruction-tuned and preference-optimized versions add further training stages; they are not claimed for the base checkpoint shown here.