Lesson 7.2 · 9 min read · about 55 min to master at a very slow pace
Backpropagation for a Single Sigmoid Neuron
The derivation you are most likely to be asked for: the gradient of mean squared error for one sigmoid neuron over a batch of examples, step by step, with a numerical example and the matrix form.
Set-up
examples with targets . For each example:
The derivation
Step 1, the error signal. Define . By the chain rule through :
The first factor comes from the squared error, the second is the sigmoid derivative .
Step 2, the weights. depends on through , so . Every example contributes, so sum:
Step 3, the bias. :
Worked example: one example, one update
, , , target , .
- Forward: ; .
- Error signal: .
- Gradients: ; .
- Update with : , .
- Check: new , . Much closer to the target 1.
In code (one example per row)
s = X @ w + b
y_hat = 1 / (1 + np.exp(-s))
delta = 2.0 / N * (y_hat - y) * y_hat * (1 - y_hat)
grad_w = X.T @ delta
grad_b = delta.sum()
What examiners look for
Name each chain-rule factor: the loss derivative , the activation derivative , and the input (or 1 for the bias). Then sum over examples.
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 is there a sum over examples in the weight gradient?
Because the loss is an average over all examples, and every example's prediction depends on the same . The derivative of a sum is the sum of the derivatives, so each example adds its own . The is already inside .
Going deeperWhy does the loss never reach exactly zero for a sigmoid neuron on AND?
only reaches 0 or 1 as , so hitting the targets exactly would need infinite weights. Training keeps growing the weights and the loss keeps shrinking towards 0 without reaching it. Thresholding at 0.5 gives exact 0/1 answers for reporting accuracy, but a step function can't be trained.
Cheatsheet
Single sigmoid neuron (MSE)
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.