A neuron that learns
Teach one neuron from its mistakes, then discover gradient descent and backpropagation.
Show a child a few dogs and cats and soon they can tell them apart, with no rule given. Networks learn the same way: from examples. We will follow the smallest learner there is, one neuron with one number.
What is a neuron?
It takes numbers in, multiplies each by its own number (a weight), and adds the results up. That is all.
The weights are the only part that changes. A network is many neurons wired together, and learning means finding good weights.
Learn by example
To teach a neuron, you need examples: inputs, each with the answer you want.
An archaeologist opens a tomb and finds a papyrus: a list of objects and their lengths, in royal cubits. We use metres, so how long was a cubit in those?
So the archaeologist measures the same objects with a tape measure. Now there are examples: each object has a length in cubits (from the papyrus) and in metres (from the tape).
| Papyrus: cubits (input) | Tape measure: metres (the answer we want) |
|---|---|
| 2 | 1.07 |
| 5 | 2.58 |
| 1 | 0.55 |
| 10 | 5.25 |
| 3 | 1.55 |
| 7 | 3.66 |
| 4 | 2.13 |
Metres are roughly half the cubits, but not exactly: scribes’ rods varied, and tape measures slip. No rule fits every row, so we want the best fit.
Let’s train a neuron
Let’s train a neuron to learn the conversion for us. It has one input and one weight :
The weight is what the neuron learns. The right is the conversion: multiply cubits by it and you get metres. We do not know it yet, so the neuron starts with a guess: a cubit is a metre, .
How wrong is it?
For the 2-cubit object it says m. The tape measure says m. It is off by .
We square the error, so that too high and too low cannot cancel out. That is the loss: . Now the goal is clear: make the loss small.
Which way should we nudge it?
We want the loss to get lower, so we need to know which way to push : up or down?
The answer is the gradient : how much the loss changes for a small nudge of . To find it, we look at the two small steps of the forward pass, one at a time:
- Neuron: , so .
- Loss: , so .
The chain rule joins them by multiplying:
| Step | Forward equation | Local derivative | Value here |
|---|---|---|---|
| The neuron | |||
| The loss | |||
| Chain rule | |||
Positive means: raising makes things worse, so lower it. (Sending the error backwards like this is called backpropagation.)
Learning by small steps
Roll the ball downhill:
is the learning rate, the step size. Press Next step and follow one object: forward through the neuron, the loss, then the derivative travelling back. The weight is nudged, and the next object goes through.
Try it yourself: hover over the weight on the connection in the diagram (or tap it) for a slider, and pick a different starting guess. Look at the tabs above the chart, and raise the learning rate to see steps that are too big.
The weight settles near . The loss never reaches zero, because the measurements disagree with each other.
Putting it to work
Nobody told it the conversion. Now the archaeologist can read the rest of the papyrus, which gives the Great Pyramid as 280 cubits tall: m.
Where this comes from
Least squares: Legendre and Gauss, around 1800. Gradient descent: Cauchy, 1847. Backpropagation: Rumelhart, Hinton and Williams, 1986. A neuron with learned weights: Frank Rosenblatt’s perceptron, 1958.
Next: one neuron can only draw a straight line, and only through zero. More inputs, more neurons.