Lesson 7.3 · 13 min read · about 1 h 10 min to master at a very slow pace
One Hidden Layer: Deriving Every Gradient
The classic exam derivation: a network with one sigmoid hidden layer and a linear output, trained with squared error. Output-layer gradients, the hidden error signal, input-layer gradients, and a full numerical example.
The network
Inputs ; sigmoid hidden units; one linear output; loss for target .
Step 1: the output error
(The cancels the 2 from the square. The output is linear, so there is no activation-derivative factor.)
Step 2: output-layer gradients
Step 3: the hidden error
Hidden unit affects the loss only through . Chain rule:
Why each factor: the output weight scales how much a change in moves ; the sigmoid derivative scales how much a change in moves .
Step 4: input-layer gradients
The pattern in both layers: gradient of a weight = error signal at its output end × the activation at its input end.
Worked example
, target . Hidden unit 1: weights , bias 0. Hidden unit 2: weights , bias 0. Output weights , bias .
- Forward: , ; ; .
- Output error: .
- Output gradients: ; .
- Hidden errors: ; .
- Input gradients (): unit 1's weights both ; unit 2's both ; biases the same.
Unit 2's gradient is positive because its output weight is negative: making smaller raises towards the target.
Click through the same example step by step, with each neuron drawn as its sum and its activation so you can see where each error signal sits:
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passWhy does the hidden error contain the output weight?
Because a hidden unit's only influence on the loss is through the output, and its effect on the output is multiplied by the weight connecting them. A hidden unit wired to the output with weight 0 can't change the loss at all, so its error signal is 0.
Going deeperWhat changes with several outputs or a sigmoid output?
With several outputs, a hidden unit affects each one, so its error is a sum over outputs: (lesson 7.5). With a sigmoid output and squared error, the output error gains the factor : . The rest of the derivation is unchanged.
First passIs the derivative with respect to the bias always 1?
Only the local one. In , raising by 0.1 raises by exactly 0.1, so always. But the gradient you update with is the loss gradient, and it goes through the chain rule:
| Gradient | Chain rule | Result |
|---|---|---|
| × input | ||
| just |
Example: and give and , not 1. That's why a bias behaves like a weight on an input that is always 1.
Cheatsheet
One hidden layer (sigmoid hidden, linear out, ½ squared error)
The pattern
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.