01
One mistake, five parameters
A forward pass turns inputs into a loss. Keep its intermediate values: the backward pass will need them.
Who should change?
A small network predicts 1.5 when the target is 2. The prediction is too low. That tells us the direction of the output error, but it does not yet tell us how to change an earlier weight. That weight’s effect passes through other operations—and may reach the output by more than one route.
Backpropagation computes how sensitive one scalar loss is to each parameter. An optimizer uses those sensitivities to propose new parameters. We will do both operations by hand before letting the lab repeat them.
You need arithmetic and the idea that a model has adjustable numbers. We introduce derivatives and vector shapes when they become useful. If you already know losses, treat the half-squared error below as our fixed measuring rule.
A network you can hold in your head
Imagine a normalized electricity-demand feature and a target . Our numbers are invented and dimensionless. There is no timestamp, real grid data, fitted forecast or physical unit behind them. The demand story motivates inspecting a learning mechanism.
The five adjustable parameters are . Every variable here is a scalar: one number. First form an affine value (multiply, then add); apply a rectified linear unit, or ReLU, to get the hidden activation :
ReLU passes a positive input unchanged and outputs zero for a negative input. The same is used in two branches, and , which rejoin at prediction :
This deliberately redundant readout could be collapsed to . Keeping its branches separate makes one shared value’s two uses visible. These are not two different hidden neurons.
Forward arrows show dependency. Both branches use the same h. Invented values; BP-C09–10.
Start with and . Forward values are . Arrows record dependencies. PyTorch’s autograd mechanics describes how recorded operations form the graph used for differentiation. BP-C01, BP-C09–10
End at one number
Define residual and loss :
Here , so . The factor one-half is a convenience: differentiating cancels the square’s factor two. This is a loss for one example, not a batch mean.
Record intermediate values rather than only the final answer. To differentiate , we will need the values of both and from this forward pass. Backpropagation travels backward through dependencies; it does not run the prediction formula in reverse to recover the input.