Visual explainer
Backpropagation
How the chain rule blames each weight and fixes all of them in one backward sweep.
When a neural network produces an incorrect prediction, the objective function outputs a single scalar loss value, such as . That single number is the culmination of thousands or millions of interconnected weights across multiple layers. The central challenge of deep learning is credit assignment: determining precisely how much each individual weight contributed to the final error without perturbing parameters one by one.
Multiply Local Slopes
Backpropagation resolves credit assignment through the calculus chain rule. For any composite function , the total rate of change decomposes into a product of local slopes: . When the loss gradient with respect to output is and the activation's local slope with respect to weight is , multiplying these local derivatives yields an exact total gradient of .
Walk Forward First
Before any gradient can flow backward, the forward pass must evaluate the network graph from input to output. Given input and initial weight , linear multiplication yields intermediate activation . Measuring against target under squared error loss produces . Crucially, the forward pass caches these intermediate states (), storing the receipts required to compute local derivatives later.
Sweep Back Once
In the backward pass, signals flow in reverse. The upstream loss derivative arrives at the node and multiplies the cached input , producing weight gradient . Applying gradient descent with learning rate adjusts the parameter: . Re-evaluating forward () cuts the loss from down to in a single round trip.
Two Beats a Million
Numerical differentiation using finite differences requires wiggling each parameter independently, demanding forward evaluations for weights—over one million passes for a standard model. Backpropagation (reverse-mode automatic differentiation) shares intermediate computations across the entire graph, computing exact analytic derivatives for every parameter simultaneously in exactly two passes: one forward sweep to cache activations, and one backward sweep to distribute gradients.
Leash Wild Steps
Deep networks with recurring products can experience exploding gradients, causing sudden numerical overflow and NaN loss spikes. Gradient clipping enforces a maximum norm threshold . A calm gradient vector () passes untouched. When a gradient surges to , clipping scales its magnitude down to while preserving its directional orientation, ensuring stable parameter updates.
Where It Breaks
Chaining derivatives across deep networks exposes a severe limitation when using saturating activation functions like Sigmoid, where the derivative peaks at . Chaining ten consecutive layers multiplies these fractional terms: . The error signal reaching early layers decays to a mere millionth of its origin, causing early weights to freeze and stalling deep network training.
The Quick Version
- Scalar loss must be apportioned among thousands of network weights.
- The chain rule computes total gradients by multiplying local slopes.
- The forward pass evaluates outputs and caches intermediate values.
- The backward pass propagates errors and applies gradient descent.
- Reverse-mode autodiff computes all gradients in exactly two passes.
- Gradient clipping bounds exploding updates while preserving direction.
- Chained fractional derivatives decay exponentially, freezing early layers.