Forward pass
Our network has one input, x = 1, two weights, w1 = 2 and w2 = 1.5, and one hidden neuron with ReLU: it keeps positive numbers and turns negative ones into 0. We want the output to be 1.
The forward pass runs the network from left to right: z = w1 × x = 2, ReLU keeps it, so h = 2, and y = w2 × h = 3. Each step keeps its numbers, because the backward pass will need them.
The loss says how wrong the output is. We use squared error: (y − t)² = (3 − 1)² = 4, where t is the target. Training means making this number smaller by changing w1 and w2.
Backward pass
For each weight we want its gradient: how fast the loss changes when that weight moves a little. Nudging each weight and rerunning works, but costs a forward pass per weight. Backpropagation finds them all in one backward sweep.
Backpropagation starts at the end. The slope of (y − t)² for y is 2(y − t) = 2 × 2 = 4. So if y grew by a tiny amount, the loss would grow by about 4 times that amount.
y = w2 × h, so nudging w2 changes y by h times as much, and nudging h by w2 times. The chain rule multiplies the slopes: dw2 = 4 × h = 8, and h gets 4 × w2 = 6.
ReLU's slope is 1 where its input is positive and 0 where it is negative. Here z = 2 is positive, so the gradient passes straight through: dz = 6. A neuron below zero would pass back nothing.
z = w1 × x, so dw1 = dz × x = 6 × 1 = 6. Every weight now has its gradient, from one sweep backwards. That is backpropagation: the chain rule, applied from the loss back, reusing each result.
We can test it. Nudge w1 from 2 to 2.001 and run forward again: the loss grows from 4 to about 4.006. That is 0.006 for a 0.001 nudge, a slope of about 6, just as backpropagation said.
Learning
Now gradient descent uses the gradients. Each weight moves against its gradient, scaled by a learning rate of 0.1: w1 = 2 − 0.1 × 6 = 1.4 and w2 = 1.5 − 0.1 × 8 = 0.7.
A new forward pass: h = 1.4 and y = 0.7 × 1.4 = 0.98. The loss falls from 4 to 0.0004. Real training repeats forward, backward and update many thousands of times, over many examples.
What happens
;; step 1/11 · network input x = 1 target t = 1 weights w1 = 2 w2 = 1.5 neuron z = w1 * x, h = relu(z) = max(0, z) output y = w2 * h the weights are what training is allowed to change
Real networks have many neurons per layer, a bias added in each neuron and millions of weights, and they average the loss over a batch of examples. The rule at each step is the same: multiply the upstream gradient by the local slope. Backpropagation is reverse-mode automatic differentiation: one backward pass costs a small, fixed multiple of one forward pass, however many weights there are (Baydin et al., 2018).