Backpropagation Through One Neuron
A neuron does three things: weigh the input, squash it, and get compared with the answer. So the gradient of the loss with respect to a weight is three small derivatives multiplied together: how much the loss cares about the output, how steep the squashing is right now, and the input that weight was multiplied by.
What the symbols mean
- Weight
How strongly the input counts.
- Bias
A shift that sets how easily the neuron turns on.
- Sigmoid
σ(z) = 1/(1 + e^(−z)), squashing any number into (0, 1).
- Target
The right answer for this example.
What the symbols mean
- How the loss reacts to the output
For squared error it's 2(a − y): the error, doubled.
- Slope of the activation
σ′(z) = σ(z)(1 − σ(z)), at most 1/4.
- Input on that weight
Since z = wx + b, this is just x.
Explanation
Backpropagation through one neuron is simply the chain rule applied to the three steps a neuron takes: weigh the input (), squash it (), and compare with the right answer (). The name backpropagation means "propagating the error backward": you start at the loss and walk back toward the weights, one step at a time. The formula is three small derivatives multiplied: (how much the loss cares about the output), (how steep the activation is at this moment) and (which turns out to be just the input ). Each one is a one-line derivative you already know. The only skill is keeping them in order.
The neuron as a graph. From The Artificial Neuron, a neuron computes and then . Add the loss from Loss Functions and you get a chain: , with and also feeding . One path from to , so by last lesson's rule we multiply the three local derivatives.
Each factor means something.
- is the error, doubled. Its sign says which way the output should move: negative means "too low, go up".
- , from Activation Functions. Think of it as a volume knob. It's largest, , at , where the neuron is undecided, and nearly when is far from and the neuron is saturated.
- . This makes a lot of sense: a weight sitting on a big input had a big effect on the output, so it gets a big share of the blame. A weight on an input of did nothing at all this time, so it gets no gradient.
And , so the bias gets the same signal without the .
Compute the middle once. The first two factors are shared by every weight in the neuron, so give their product a name: , the neuron's error signal. Then
With several inputs, the whole gradient is just times the input vector. Computing once and reusing it is the habit that makes backprop fast; the next lesson does the same thing for whole layers.
Then take the step. With the gradient in hand, Gradient Descent moves every weight a little against it: . A negative gradient means "increasing lowers the loss", so the minus sign makes go up.
Why cross-entropy pairs so well with the sigmoid. With squared error, a neuron that's confidently wrong (say when the answer is ) has , so it barely learns, right when it most needs to. Binary cross-entropy, , fixes that. Its , and multiplying by gives
The cancels completely. The error signal is just "prediction minus truth", with no volume knob in the way. This single neuron with cross-entropy is exactly Logistic Regression.
A common mistake. With squared error it's tempting to write and stop, because that's what the derivative would be without an activation (and with cross-entropy the answer really is that simple, ). With a sigmoid and squared error you need the middle factor too. Leaving it out gives gradients up to four times too big when the neuron is undecided, and wildly too big when it's saturated. Always walk the whole chain: loss, then activation, then the weighted sum.
See it
Worked examples
A sigmoid neuron has , , , and the target is , with loss . Find and , then take one gradient step with .
- 1
Forward pass, the weighted sum: .
A sigmoid neuron with two inputs has , , and target , with binary cross-entropy loss. Find , and .
- 1
Forward pass, the weighted sum: .
Practice
Type your answer and check it. Solve them all to complete the lesson.
A sigmoid neuron has , , and target , with loss . Find .
A sigmoid neuron has , , and target , with loss . Find .
A sigmoid neuron trained with binary cross-entropy outputs on an example with target and input . Find .
A ReLU neuron has inputs , weights and bias . Whatever the loss, what is on this example?
A smart building uses one sigmoid neuron to predict whether a room is occupied, trained with binary cross-entropy. Its inputs are a motion reading and a CO₂ reading , with and . The room was occupied (). After one gradient step with , what is the new value of ?
(Activation functions review.) A neuron uses instead of a sigmoid, with , , , target and loss . Find to 4 decimal places.
(Linear approximation review.) A sigmoid neuron has input , weight , bias , target and loss . There and . Use the linear approximation to estimate the loss when becomes (everything else unchanged). Give 3 decimal places.
The hardest one here. Get it, and you've got this lesson.
A sigmoid neuron has inputs , weights , bias , target and loss . Take one gradient descent step with on both weights and the bias, then compute the new loss to 4 decimal places.
Where it's used
A single sigmoid neuron trained with cross-entropy is logistic regression, still one of the most used models anywhere: spam filters, credit decisions, click predictions and medical risk scores. The training loop is exactly this lesson. For each example, compute and , form , and nudge each weight by . That one line, run over millions of examples, is how those models learn which inputs matter.