THIS EXPLANATION
THE ROOM
CDA·111 Computing, Data & AI 7 MIN · 8 STATIONS

How does a neural network learn?

A Socratic walk-through of neural-network learning — reasoned out one step at a time, not lectured.

abcdefgh
a

The question we started with

THE QUESTION #

How does a neural network learn?

If a neural network begins with poor guesses, what would it need in order to improve? It would need a way to measure how wrong it was and a way to decide which internal settings contributed to that error. The first is easy to imagine. The second is the hard one, and it is worth sitting with: a network may hold millions of adjustable numbers, and the error it produced is a single number at the end. How could blame for one number be apportioned among millions?

b

Reasoning it through

REASONING #

The network transforms an input through layers of weighted calculations and produces a prediction. A loss function compares that prediction with the desired result and turns the mismatch into a number. Lower loss means the current settings performed better on that example.

Now ask the obvious question: which way should a weight move? You could try nudging one weight up, re-running the whole network, and seeing whether the loss fell. That works, and it is hopeless — with a million weights you would need a million re-runs to take one step. What we actually want, for each weight, is a slope: if this weight rose slightly, would the loss rise or fall, and how steeply? That collection of slopes, one per weight, is the gradient. It is not a mysterious object. It is a very long list of answers to a very simple question, and it points in the direction of steepest increase of the loss — so moving against it reduces error.

The saving grace is that the network is a composition of simple steps, and the chain rule of calculus says the slope through a chain of steps is the product of the slopes of each step. So you can compute the slope at the output, hand it backwards to the layer beneath, multiply, and continue. That is backpropagation: not a separate learning algorithm but a bookkeeping method that gets every weight's slope in roughly the cost of one forward pass, instead of one pass per weight. The entire practicality of deep learning rests on that accounting trick.

Having a direction is not the same as knowing how far to go. The step size is the learning rate, and it is the setting people spend the most time on. Too small, and training crawls, or settles into the first shallow dip it finds. Too large, and the step overshoots the bottom of the valley and lands higher up the far side — repeat that and the loss climbs instead of falling, sometimes to infinity within a few dozen steps. There is no correct value in the abstract; it depends on the problem, and much of modern optimizer design is machinery for adjusting it as training proceeds.

There is one more requirement, and it is easy to miss because it looks like a detail. Between layers sits a non-linear function — something that bends the signal rather than merely scaling it. Why does that matter? Suppose it were absent, and every layer only multiplied and added. Then a stack of layers is a linear map applied to a linear map, which is itself just a linear map: a hundred-layer network would collapse, exactly, to something a single layer could compute. All the depth would be decoration. The bend between layers is what makes the composition of many simple steps able to express something no single step can, and it is the reason depth buys anything at all.

One correction is rarely enough. Training repeats the cycle across many examples, gradually finding weights that capture useful statistical patterns. What has been learned, then, is not a list of stored answers but a configuration that tends to produce suitable outputs for similar inputs.

c

The analogy

THE ANALOGY #
THE FIGURE

Picture a sound engineer adjusting hundreds of knobs on a mixing board. After hearing how far the mix is from the target sound, the engineer estimates which knobs should move and by how much, then listens again. Training is a vast, automated version of that repeated adjustment.

WHERE IT BREAKS DOWN

A human engineer judges by ear and turns a few knobs at a time. Training computes an exact direction for every knob at once — millions of them — against a numeric score nobody hears. And the engineer knows what a vocal is; the network's knobs have no meanings attached, only slopes.

d

Clarifying the model

THE MODEL #

A neural network does not necessarily reason as a human brain does, despite the biological inspiration of its name. Put more bluntly: what happens here is curve fitting. The system is adjusting parameters of a very flexible function so that it passes near the examples it was shown. That it does so at enormous scale, and that the resulting behaviour can be strikingly useful, does not change the kind of thing it is — nothing in the procedure above requires or produces understanding of the subject matter, and the network has no representation of being right, only of scoring well.

Which is why fitting the training data is a weak result on its own. A function flexible enough to approximate almost anything is flexible enough to trace noise, and a network can memorize its examples or latch onto a correlation that holds in the data and nowhere else — background texture that happens to co-occur with the label, a watermark, an artefact of how the data was collected. The standard guard is to split the data: fit on a training set, and check on a validation set the optimizer never touched. If loss keeps falling on the first while rising on the second, the network is not learning any longer, it is memorizing, and the honest response is to stop. Regularization, representative examples, and careful evaluation help, but none of them make the check unnecessary — and the moment validation data is used to choose settings, it has quietly become training data, which is why a third, untouched test set exists.

e

A picture of it

THE PICTURE #
Neural-network learning
Neural-network learning Enter at the slanted box -- learning starts from examples whose answers are already known, which is the whole reason this works at all. Follow the loop clockwise: predict, measure, apportion blame, nudge, predict again. The cylinder is the only thing that persists between rounds; everything else is thrown away each pass. At the diamond, notice there are two ways to have a small error, and only one of them is learning -- the branch to the right leads to a network that has memorised its answers rather than found the pattern. {"generator":"[email protected]","source":"../Socrates/.diagram-cache/_src/how-does-a-neural-network-learn.md","sourceIndex":1,"sourceLine":4,"sourceHash":"f32ea340442c0c21eec67f5ee1ef213483324c428dbe1626cbf2d379faeeba53","diagramType":"flowchart-v2","layoutVariant":"source","repairedDuplicateIds":[],"motion":"entrance-with-reduced-motion-fallback","presentation":"editorial","attempt":1,"viewBox":{"x":0,"y":0,"width":1102,"height":974},"qa":{"passed":true,"findings":[]}} no the next example arrives yes, and it holds onexamples never seen yes, but only on theexamples it trained on A training example whoseanswer is already known The network makes a prediction Compare the prediction with theknown answer Is the error small enough? Backpropagate -- ask everyweight how much it contributedto this error Weights, each nudged a littleagainst its share of the blame A model that has learned thepattern Memorised, not learned
KINDSsourceprocessdecisionoutcomeriskconnector

How to readEnter at the slanted box — learning starts from examples whose answers are already known, which is the whole reason this works at all. Follow the loop clockwise: predict, measure, apportion blame, nudge, predict again. The cylinder is the only thing that persists between rounds; everything else is thrown away each pass. At the diamond, notice there are two ways to have a small error, and only one of them is learning — the branch to the right leads to a network that has memorised its answers rather than found the pattern.

f

What became clearer

WHAT CLEARED #
WHAT CLEARED

A neural network learns by repeatedly measuring prediction error, assigning influence to its weights, and adjusting those weights to reduce future error. The two things that make it work are unglamorous: the chain rule, which makes assigning blame to millions of weights affordable, and a non-linearity between layers, without which all that depth would collapse to a single layer's worth of power. Everything else — the scale, the architectures, the results — is built on those.

g

Where to go next

ONWARD #
  • How overfitting differs from useful learning.
  • Why training and inference require different amounts of work.
  • Why very deep networks were hard to train before residual connections and normalization.
h

Key terms

TERMS #
TermWhat it means
Weightan adjustable number controlling the influence of a connection.
Loss functiona numerical measure of prediction error.
Backpropagationcalculation of how each weight influences the loss, by applying the chain rule backwards through the layers.
Gradientthe list of slopes — one per weight — describing how the loss would change if each weight changed slightly.
Learning ratehow far to move along that direction on each step; too small stalls, too large diverges.
Activation functionthe non-linear step between layers, without which any depth of network reduces to a single linear layer.
Validation setexamples held back from training, used to check whether the learned pattern generalizes.

Every term the collection defines is gathered in the glossary.

Nearby on the shelf

4