Training a Network

Every piece is finally on the table: a network that can compute a prediction, a cost function that scores how wrong that prediction was, backpropagation that turns the score into a gradient for every weight, and gradient descent that uses the gradient to improve. Training is simply wiring those four pieces into one repeating cycle — the very same training loop you met at the start, with every step now filled in with a real algorithm:

  1. Forward — run a batch of examples through the network to get predictions.
  2. Loss — score them against the true labels (cross-entropy or squared error).
  3. Backward — backpropagate to get every weight's gradient.
  4. Update — nudge every weight downhill by the learning rate.
  5. Repeat — go again with the next batch of examples.

That five-step cycle, run over and over — often for hours, sometimes for weeks — is all that "training a neural network" means, from the tiniest toy classifier you can fit on one screen to the largest language models running on stadium-sized data centres. Nothing new gets invented at scale; the exact same loop just runs for far, far longer.

Worked example: three rounds of the full loop

Remember the free-throw shooter from the training loop: shoot, see how far off, adjust, shoot again. Let's replay that cycle once more, but this time every step gets its real, technical name. Take the simplest possible "network" — a single weight m guessing \hat y = m \cdot x — with one training example, x = 3, true answer y = 12. Start with a bad guess m = 1 and a learning rate of 0.1.

RoundForward: \hat y = m xLoss: \tfrac12(\hat y - y)^2Backward: gradientUpdate: new m
1 (m=1)1 \times 3 = 340.5-271 - 0.1(-27) = 3.7
2 (m=3.7)3.7 \times 3 = 11.10.405-2.73.7 - 0.1(-2.7) = 3.97
3 (m=3.97)3.97 \times 3 = 11.910.00405-0.273.97 - 0.1(-0.27) = 3.997

Watch the loss column: 40.5 \to 0.405 \to 0.00405 — collapsing by roughly a hundredfold each round, as m races toward the true value of 4. Every round is forward (predict), loss (score), backward (blame), update (improve) — exactly the loop from the free-throw shooter, just now with a named algorithm doing each job. A real network repeats this same table millions of times, with millions of weights updating together instead of one.

Watch a boundary form

These two classes spiral together — no straight line can separate them. Step through training and watch the network bend its decision boundary into a curve that wraps around the data, while the loss falls. A linear model could never do this; the hidden layers' non-linearity is what makes the curved boundary possible. Each step you drag through is one more round of exactly the forward → loss → backward → update cycle from the table above — just running on a network with far more than one weight.

The vocabulary of scale: epochs and batches

Real training sets rarely fit in memory as one training example — they hold thousands, millions, sometimes billions of examples. Two words describe how that flood of data gets sliced up for the loop:

Put them together: a dataset of 60{,}000 images, split into batches of 100, needs 600 batches — and so 600 weight updates — to complete just one epoch. Train for 20 epochs and the loop has fired 12{,}000 times in total, each one a full forward–loss–backward–update round.

Three flavors of the update step

"How many examples per batch?" turns out to matter a lot, and training comes in three common flavors depending on the answer:

FlavorBatch sizeCharacter
Full-batchthe entire training set, every updatevery stable, accurate gradient — but painfully slow, since nothing updates until the whole dataset has been scanned
Stochastic (single-example)just one example per updateupdates constantly and cheaply — but each gradient is a noisy, jittery estimate based on a single example
Mini-batcha modest chunk (say, 32–256 examples)the practical middle ground almost everyone actually uses: frequent updates, a reasonably smooth gradient, and batches sized to fit neatly on the training hardware

When people casually say a network was trained with "batch size 64," they mean this mini-batch flavor — running steps 1–4 on 64 examples at a time, updating, then moving to the next 64, all the way through the epoch.

The craft of training

In practice, training is part science, part art: choosing the learning rate, the batch size, the network shape, the regularization, and watching the validation loss to stop before overfitting. But the core is always those same four steps on repeat. Everything from a tiny classifier to a giant language model is trained by exactly this loop — just with more data, more weights, and more patience.

Settings chosen before training begins — the learning rate, the batch size, how many epochs to run, the shape of the network itself — are called hyperparameters, to distinguish them from the weights the loop itself learns. Picking good hyperparameters is often a trial-and-error search of its own: train several candidate settings, watch each one's validation loss, and keep whichever configuration generalizes best. A common safety net is early stopping — watching the validation loss epoch by epoch and halting training the moment it stops improving, even if the training loss is still falling, which is often the clearest early sign that overfitting is about to begin.

A falling loss curve is the goal, but training doesn't always cooperate. Three classic failure patterns, each needing a different fix:

There's also a cost to training that has nothing to do with the maths: it's genuinely expensive. Real, large networks need specialized hardware — GPUs or TPUs built to do millions of multiplications in parallel — and even then can take enormous amounts of computer time and electricity to finish.

The tiny examples on this page — one weight, a handful of points, a spiral of two colours — train completely in a fraction of a second on an ordinary laptop. Scale the very same forward–loss–backward–update loop up to a modern large language model, and training can take months of continuous computation across thousands of specialized chips, at a cost that runs into the tens or hundreds of millions of dollars in electricity and hardware time. Same four steps, same loop — just run an almost unimaginable number of times, on an almost unimaginable amount of data.

One habit unites toy projects and industrial-scale training runs alike: engineers stare, for hours, at a graph of the loss (or "loss curve") ticking downward over time — exactly the shrinking numbers you watched in the worked example's table above. Whether the run costs nothing or costs a fortune, that falling curve is the one signal everyone is watching for.

It's a strange kind of patience, watching a number get smaller for weeks on end — but it's exactly how nearly every model you've ever used got built: a search engine's ranking model, a phone's voice-to-text, a translation app, a chatbot. Somewhere, a loss curve like the one in this page's table crept downward, round after round, until someone decided it was good enough to ship.

See it explained