Train a neural network

This is where you get to see how a neural network actually learns. We follow one training example all the way around the loop and watch the error travel backwards through the network, nudging every weight a little.

1
Forward pass
The input is sent through the network, which makes a guess.
2
Loss
We compare the network's guess with the correct answer and work out how big the error is.
3
Backpropagation
Information about the error is sent backwards through the network, so every weight learns how it contributed.
4
Update
Every weight is nudged a little in the direction that reduces the error.
Step 1 of 2 · Choose a task

What should the network learn?

Pick a logic gate. The network has to learn to give the right answer for all four combinations of the inputs x₁ and x₂.

AI-aktiviteter

Train a neural network

Watch the network learn, step by step – from a random guess to a fully trained model.

Svenska
Advanced

What is it we are actually differentiating?

At every calculation step z, a, ŷ and L are concrete numbers – results worked out for a given input and given weights. What gets differentiated, though, is not those individual numbers but the relationship between them: the formula describing how the loss L would change if a weight w were altered slightly.

Hold every other value fixed and let w vary, and a curve appears. The derivative is the slope of that curve at exactly the point where the weight currently sits – not the height, but how steep it is there.

The network knows the equation of that curve, because it is built only from known, differentiable steps (weighted sums and sigmoid). So the slope can be worked out exactly, by plugging the current numbers into the finished formula – instead of guessing.

L → ŷ   dL/dŷ = (ŷ − y)
a → z   da/dz = a(1−a)
z → w   dz/dw = a_in

The chain rule multiplies these slopes together, step by step backwards through the network – which is exactly what Phase 3 · Backprop does.

The steeper the curve, the more sensitive the loss is to changes in the weight. Right at the bottom of the valley the slope is zero – there is no way to reduce the loss further by moving the weight in either direction. So it is at the bottom of the curve, where the derivative is zero, that the loss is at its smallest – and that is where gradient descent tries to take the network, one step at a time.

Try it yourself: the slope at a point
w
w
L(w)
Slope dL/dw
The yellow line is the tangent – the slope of the curve at that exact point. That number is the derivative. The green arrow shows which way gradient descent nudges w: downhill, towards the bottom of the valley.