Neural NetworksBackpropagation: How Networks Learn
A new network starts with random weights, so its first answers are poor. Training improves the weights one small step at a time, with the same gradient descent you used in Linear Regression:
- Forward pass: feed in an example and work out the prediction .
- Loss: measure how wrong it is, .
- Backward pass: for every weight, work out how much the loss changes when that weight changes a little — its gradient. The gradients are worked out backwards through the graph, from the loss to the first layer: this is backpropagation.
- Update: move every weight a small step against its gradient, .
Here is a tiny network: one input, two hidden neurons with the sigmoid activation, and one output, . Its only training example is with the target , and the learning rate is . The red line under the network records the loss after every forward pass. Run forward and backward passes and complete both missions.
Three rounds of forward and backward took the loss from 0.25 to below 0.001. A real network does exactly the same — for millions of weights and millions of examples, again and again.
The Chain Rule at Work
Let's do the first backward pass by hand. Before it, , and . First, how does the loss change with the prediction?
So
The output is , so when grows by a little, grows by times as much. By the chain rule, the two rates multiply:
So the new weight is
Note
For a weight further back, the chain is longer: changes , changes , and changes . The computer multiplies the rate of every link in the chain, just as you did for — that gave the widget's gradient of −0.098 for .
Backpropagation is the chain rule from Class 12 calculus, applied again and again from the loss back to the first layer, reusing every piece it has already worked out.