trainschool/00 · What "training" actually is‹ prevnext ›

Lesson 0 · 25 min

What "training" actually is

A model is a box of knobs. Loss is how wrong it is. Training turns the knobs to make loss smaller — and you'll watch it happen for real.

Everything in this course comes back to one loop: guess, measure how wrong, turn the knobs a little, repeat. This lesson shows the loop as pictures, lets you drive it by hand, and then runs it for real on your own CPU.

A model is a box of knobs

A model is a box of knobs1/5 · text goes in
0.0s
Text goes in, a guess about the next word comes out, and 800,000 numbers in between decide which guess. Training is nothing more than turning those numbers.

A language model is a function with a very large number of adjustable numbers — the weights, or knobs. Feed it text and it returns a probability for every possible next token. Nothing about the box is clever on its own: with random knobs it guesses randomly. Every capability you have ever seen from a model is a particular setting of the knobs.

Loss: how wrong was that guess?

Loss is the gap1/4 · the model's guess
0.0s
The model gave the true next word a probability of 0.12. Loss is −log of that: 2.12. Push the probability toward 1 and the loss falls toward 0.

We need one number that says how wrong a guess was, so we can make it smaller. The standard choice is the negative log of the probability the model assigned to what actually came next: loss = −log p(correct). A perfect guess (p = 1) scores 0. A uniform guess over our 97-symbol alphabet scores −log(1/97) = 4.57 — which is exactly where every run in this lesson starts.

Training: turn the knobs downhill

Gradient descent1/6 · the loss landscape
0.0s
The gradient says which way each knob would make loss go up. Take a small step the other way. Repeat. Each step is a fixed fraction of the slope, so the steps shrink as the bowl flattens.

For every knob, calculus gives us the slope of the loss with respect to that knob — the gradient. Moving each knob a little against its slope lowers the loss. How big a step to take is the learning rate: too small and training crawls, too large and you overshoot the bottom of the bowl. That is the entire algorithm. Everything else in this course is about making it work at scale.

Be the optimiser for two knobs

toy · two knobsloss 0.1654 · steps 0

Each step: slope −= 0.5 × ∂loss/∂slope, intercept −= 0.5 × ∂loss/∂intercept.

−101−0.61red = how wrong each point is · loss = mean of red²

Fit the line by dragging the two knobs and watching the loss. Then reset and let the gradient do it: ten steps beat what your hands did. One step already moves both knobs the right way; ten steps land where a careful hand fit does. A language model has 800,000 of these knobs instead of two, and the loss surface is not a clean bowl — but the move is the same.

What a run looks like

A training run1/4 · axes
0.0s
A curve shaped like the run you are about to launch — the endpoints are real: 4.57 → 1.81. Red is loss on the text being trained on; blue is loss on text the model never sees, every 100 steps.

Plotted over steps, loss falls fast, then slower, then flattens. Each step measures loss on a small random batch, which is why the live curve wiggles. Two curves matter: training loss on the data you are optimising on, and validation loss on held-out text. Training loss can fall by memorising. Validation loss only falls if the knobs captured something general — it is the number we care about.

Now do it for real

Train it yourselfpretrain · shakespeare

no run yet

waiting for the first step…

This trains a 4-layer, 128-wide transformer (about 800,000 knobs) on Shakespeare, character by character, on this machine's CPU. Watch four things: the loss starts at 4.57 and should reach about 1.8 in under a minute; the samples go from noise to something that scans like English; the tokens-per-second readout is your throughput; and when it finishes, the cost box prices this exact amount of compute on real GPUs. Change the steps or the learning rate and run it again.

Practice

quiz · Check · 1/4open

In one sentence, what is loss?

predict · Predict, then runopen

Set the learning rate to 0.0000001 — effectively zero — and run 300 steps. What happens to the loss?

task · Taskopen

The default run reaches a validation loss of about 1.81. Beat it: change the model or the schedule so validation loss reaches 1.70 or lower in at most 3,000 steps. Bigger models take longer per step, so the cost box at the end is part of the answer.

goal: val_loss <= 1.7 within step <= 3000

Your attemptpretrain · shakespeare

no run yet

waiting for the first step…
reflect · Why it worksopen
  1. Why does moving the knobs against the gradient lower the loss?

  2. Why not set the knobs to the right values directly?

  3. Why measure loss on held-out validation text and not only on the training text?

levers · How to improveopen

Symptom: training loss keeps falling, but validation loss stopped improving at step 800. Order the levers you would pull, first to last.

  1. train for more steps
  2. shrink the model or add dropout
  3. keep the best validation checkpoint and stop there
  4. add more, or more varied, training text

Next

You have trained a model and watched its loss fall. Next: the text went into that model as numbers — how, and why the choice of numbers changes what the model can learn and what it costs.