BackpropagationLesson 5 of 6
A small network, by hand
A hidden layer, ReLU, and all nine parameter gradients
The two-parameter model used multiplication, addition, and a loss. Now add two hidden units and a nonlinear function. The backward rule stays the same: multiply local derivatives, and add contributions from shared paths.
Read the model before the derivatives
Section titled “Read the model before the derivatives”The input is and the target is y = 1. A hidden unit first calculates a weighted sum z, then applies to produce h.
There are nine parameters: four entries of , two of , two of , and the scalar . Biases count as parameters too.
The model is
Read the first equation one row at a time if the matrix notation is unfamiliar. For example, the first hidden unit multiplies x₁ by 0.6 and x₂ by −0.2, then adds 0.1.
Forward: nine parameters, one loss
Section titled “Forward: nine parameters, one loss”| Quantity | Calculation | Value |
|---|---|---|
| 0.3 | ||
| 0.9 | ||
| Both z values are positive | (0.3, 0.9) | |
| 0.05 | ||
| L | 0.45125 |
Backward: begin at the prediction
Section titled “Backward: begin at the prediction”The first loss derivative is
A small increase in the prediction would reduce this loss. Use that derivative to get the output-layer parameter derivatives:
For example, . A weight in a weighted sum receives the downstream loss derivative times the input it multiplies.
Continue through the hidden units
Section titled “Continue through the hidden units”The local derivative of with respect to a hidden value is its output weight:
The second sign is positive because increasing h₂ lowers the prediction through the weight −0.5. At the current prediction, that moves us farther from the target.
ReLU has derivative 1 for positive z and 0 for negative z. Both current z values are positive, so . At z = 0, ReLU has no ordinary derivative; this example’s calculator uses the common backward convention of 0 there.
For the first hidden unit, multiply by each input. For the second, do the same with :
That accounts for every parameter. No parameter has been updated yet.
What happens when a hidden unit is inactive?
Section titled “What happens when a hidden unit is inactive?”Set the top-left weight to −0.8. Then and h₁ = 0. The ReLU derivative is zero, so this example gives zero derivatives for the weights and bias feeding that unit. Its output-weight derivative is also zero because it multiplies h₁ = 0.
A zero contribution through this unit does not erase other paths. The second hidden unit still contributes, and an input or shared parameter could affect the loss elsewhere. “Inactive for this example” also does not mean permanently inactive on every input.
Check a derivative against the loss
Section titled “Check a derivative against the loss”Restore the original parameters. Increase only from 0.6 to 0.601. The new loss is 0.4503005, a change of −0.0009495. The derivative predicts .
A finite-difference check compares these calculations. It is useful for catching errors, but a single matching check is not a proof. Steps that are too large include curvature; steps that are too small suffer rounding error. A step across a ReLU corner needs special care.
Now update all nine parameters
Section titled “Now update all nine parameters”Using the original gradient and gives
A fresh forward pass gives z = h = (0.87, 0.615), prediction 0.9348775, and loss approximately 0.00212047. That is an improvement on this one training example, not evidence of performance on new data.
Your turn: interpret a positive derivative
Section titled “Your turn: interpret a positive derivative”At the original parameters, but . Why do those signs differ?
Work it through
They ask about different changes. Increasing makes its negative value less negative. Since h₂ = 0.9 is positive, this raises the prediction toward the target and lowers L.
Increasing h₂ while holding the negative weight fixed lowers the prediction and raises L. The derivatives describe different inputs to the same multiplication.
Next: connect the calculation to automatic differentiation.