INTRODUCTION

How a neural network learns — explained from the beginning, with no prior knowledge and none of the formulas you can do without. Backprop Lab comes along so you can play as you read.

Contents

  1. 1The basic idea
  2. 2What a neuron does
  3. 3A neuron draws a line
  4. 4Many neurons together
  5. 5The kink that makes it possible
  6. 6What “learning” means
  7. 7Downhill in the fog
  8. 8Backpropagation
  9. 9Epoch, batch, learning rate
  10. 10Understanding or memorising
  11. 11And the large models?
  12. 12Ten minutes at the device
  13. 13Glossary

1The basic idea

Normally you tell a computer how to do something. With a neural network you only tell it what should come out — and leave the how to it.

Take a small task. On a sheet of paper there are points, some green, some orange. Green lies inside, orange outside, but nobody has ever written that down. You could work the rule out yourself and program it: “distance from the centre less than three — then green.” That would solve the task, but the computer would have learned nothing; the human would have done the work.

A neural network goes about it differently. It starts from pure chance and guesses. For every point it compares its guess with the truth, measures how wrong it was, and shifts itself a tiny bit in the direction that makes the error smaller. Then the next point. And the next. A few hundred thousand times.

At heart there is no more to it than that: guess, measure the error, adjust a little. Everything else in this text only explains what the network is made of and how it knows which way to shift.

2What a neuron does

An artificial neuron has about as much to do with a nerve cell as an aeroplane has with a bird: the idea comes from there, the construction is entirely different. In truth a neuron is a small mixing desk.

Several numbers come in. Each has a slider of its own — the weight. The neuron turns each input up or down according to its weight, adds everything together, adds one more standing value (the bias) and sends the result through a final function that squashes it into a manageable range.

x₁ x₂ 1 weight w₁ weight w₂ bias b add up z = w₁x₁ + w₂x₂ + b squash a = f(z) a output
A neuron. The inputs x₁ and x₂ are multiplied by their weights, added together and shifted by the bias; the function f squashes the result into a range between −1 and +1. Only the weights and the bias are learned — those are the numbers the training turns.

That is all. A neuron can multiply, add and squash. The whole ability of a network arises from having very many of them side by side and one behind the other.

3A neuron draws a line

What can a single neuron make of our points? Astonishingly little, and that is instructive. It can do exactly one thing: divide the sheet in two with a straight cut and say “green here, orange there”.

The weights decide how the cut is tilted, the bias how far it is shifted. A neuron has no other options. For two clouds of points lying diagonally beside each other that is quite enough. For a circle it is not — with a straight line you never separate the inside cleanly from the outside.

4Many neurons together

The way out: take several neurons, give each of them the same points and let each lay its own cut. A further neuron behind them combines the answers.

Neuron A one cut + Neuron B a second cut = both together a stripe
Two neurons each lay one straight cut. A third neuron that demands “green only if both agree” turns them into a stripe. Four cuts make a rectangle, many cuts a circle — with enough neurons any shape can be approximated.

This is how the division of labour arises: each neuron of the first layer takes care of one aspect, the next layer puts the partial answers together, the one after that combines their results again. These groups behind one another are called layers, and the fact that there are several of them is the “deep” in deep learning.

In Backprop Lab you can watch the neurons doing exactly this: each carries a small tile showing how it colours the sheet. In the first layer these are mostly plain light-to-dark gradients; further back the patterns grow more tangled.

5The kink that makes it possible

A detail from earlier decides everything: that “squashing” at the end of the neuron, the activation function. It sounds like technical trimming, but it is the reason the whole thing works at all.

Without it every neuron would be a multiplication followed by an addition — and when you put such calculations one behind the other, what comes out at the end is again nothing but a single multiplication with an addition. A hundred layers would give the same straight line as one neuron. The entire effort would be wasted.

Only the kink in the function — the transition from “barely responds” to “responds strongly” — makes every layer a real gain. In the app you can reproduce this in twenty seconds: set the activation to linear, build three layers of eight neurons, train. It stays a straight dividing line, however large the network is.

If you remember one thing from this text: a network without a kink is not a network but a very laboriously written straight line.

6What “learning” means

So far we have a machine with a great many sliders. Now somebody has to set them — and that somebody is not a human being but a measurement.

You show the network a point and compare its answer with the truth. If +1 should come out and it says +0.3, that is an error of 0.7. You square that error (so the sign does not matter and large errors count for more) and average over all the points. The result is the loss — a single number saying: this is how bad you are right now.

With that, “learning” has turned into something very sober: find the setting of the sliders at which this one number is as small as possible. That is no longer philosophy, that is searching.

7Downhill in the fog

Except that trying everything is out. Even our tiny network has some forty sliders, and each can take any value. Going through all the combinations takes longer than the universe has existed.

Instead, picture the loss as a landscape: every possible setting is a place, and the height above the ground is the error. What you are looking for is the deepest valley. You are standing somewhere in thick fog and can see nothing — but you can feel with your foot which way it goes downhill here. So you take a step that way. Then you feel again. And again. That is gradient descent, and there is nothing more behind it.

lowest point A step size that fits The steps grow smaller by themselves as the ground flattens out. Steps that are too large The valley is jumped over every time; the error grows instead of shrinking.
The step size is called the learning rate. Too small and you will not arrive before knocking-off time; too large and you leap over the valley and land higher than before. In the app both show up at once on the loss curve: 0.001 leaves it almost horizontal, 1 makes it jump.

8Backpropagation

One question is still open, and it is the decisive one: how does a single slider deep inside the network know which way to turn? It does not see the result — there are two more layers between it and the output.

The answer is a procedure called backpropagation, and it works like the post-mortem on a botched relay race. At the finish one thing is settled: two seconds too slow. The last runner knows how much of that is down to them and what deficit they took over with — and they pass that deficit back to the runner before them, who does the same. So the blame travels backwards through the team until everyone knows their share.

input hidden layer output Forward: compute and guess Backward: share out the error There, then back. Forward produces the answer, backward each weight's share of the error.
Two passes per data point. Forwards the numbers flow from left to right and produce a prediction. Backwards the error flows from right to left, and every weight learns on the way how strongly it was involved.

Mathematically this is the chain rule from school calculus, no more — only applied tens of thousands of times. What matters is the conclusion: after the backward pass every single slider in the whole network knows its own direction “downhill”. All of them turn a little at the same time, and the next data point comes up.

Backpropagation is, by the way, the reason this app is called what it is. The sequence — guess forwards, share out blame backwards, adjust a little — is the same whether the network has forty weights or forty billion.

9Epoch, batch, learning rate

Three words keep turning up, and all three are harmless:

No training determines these quantities; you set them by hand. That is why they are called hyperparameters: settings above the learning, as opposed to the weights, which the network finds by itself.

10Understanding or memorising

Now comes the place where most of the misunderstandings sit. A network with enough neurons can assign every training point correctly — even when it has never grasped the rule behind them. It has then simply stored the points. That is the difference between a pupil who has understood the grammar and one who knows the example sentences by heart: as long as you examine them out of the book, both are equally good.

This is why part of the data is held back from the start and never shown to the network — the test data. How good a network really is can only be decided on those. If the error on the training data keeps going down while the error on the test data rises again, the memorising has begun. That is called overfitting.

And there is a second, finer sign: a network that has grasped the rule behaves sensibly even where there are no points at all. Its boundary is smooth and follows the shape of the task. A network that has memorised draws tongues and islands around single points. Both are immediately visible in the app — which is the real reason it draws the decision surface instead of only showing an accuracy figure.

Getting every point right is no seal of quality. What tells you something is how the network deals with points it has never seen.

11And the large models?

The language models everyone is talking about are made of the same parts: weighted sums, an activation function with a kink, layers behind one another, a loss, gradient descent, backpropagation. Anyone who has understood this page knows the underlying principle.

Three things are different. First the order of magnitude: our network has a few dozen weights, large language models have billions to hundreds of billions. Second the task — not “green or orange” but “which piece of a word comes next”, trained on enormous amounts of text. Third the wiring: such models use additional building blocks, above all what is called attention, with which every word can reach deliberately for other places in the text.

That is an enormous difference in scale and sophistication — but not a different basic idea. There too something is guessed, the error measured, and a tiny bit adjusted.

12Ten minutes at the device

Reading brings only half the insight. Open the app and go through this in order — each step shows exactly one of the statements above:

This works in the browser as well as on the phone: the same exercise exists as an Android app. Tapped instead of clicked, and in landscape the buttons stand in the top bar. The only thing missing there is the weight readout on hover — without a mouse pointer there is none; the line thickness remains the clue.

If you want to look something up while out and about, the app carries a short help: menu symbol at the top left, then Help — six sections at phone size. Section 14 of the manual describes that version in more detail.

  1. Press Reset, then Train. Watch a circle emerge from the random fog of colour. That is the whole process in thirty seconds.
  2. Set the activation to linear and train again. It stays a straight line — the kink is missing (section 5).
  3. Back to tanh, learning rate to 1. The loss curve jumps: steps too large (section 7).
  4. Learning rate back to 0.03, data set Spiral. With four neurons the network fails; add layers and neurons until it works. That is what capacity feels like.
  5. While the training runs, click a thick connection and cut it. The error jumps up — and the network redistributes the task within seconds.
  6. Noise to 50 %, Show test points, train for a long time. The boundary grows tongues and the test curve climbs again: overfitting (section 10).

After that the manual is worth reading: it says what every control does and what to do when nothing learns any more.

13Glossary

TermIn one sentence
NeuronComputes a weighted sum of its inputs and squashes the result.
WeightThe slider on an input; it is what the training adjusts.
BiasA neuron's standing value, independent of the inputs.
ActivationThe function with the kink at the output; without it everything would stay a straight line.
LayerA group of neurons that sees the same inputs.
ParametersAll the numbers that are learned: every weight and bias together.
LossA number measuring how wrong the network currently is.
GradientThe direction a weight has to be turned for the loss to fall.
BackpropagationThe procedure that shares the error out backwards and gets all the gradients from it.
Learning rateHow far the turn goes at each step.
EpochOne complete pass through all the training data.
BatchThe portion of data points after which the weights are adjusted once.
Test dataPoints held back that the network never gets to see.
OverfittingThe network has stored the training points instead of learning the rule.
FeatureA number that goes in at the front — here the coordinates of a point and values derived from them.