Gradient descent and backpropagation
Trace an error back to each adjustable coefficient.
On this page
A prediction error is a single number, whereas a network may contain many adjustable coefficients. Training needs a way to determine how each coefficient contributes to that error. The gradient supplies the local sensitivities, backpropagation computes them efficiently through shared intermediate calculations, and an optimizer turns them into parameter updates.
Gradient descent updates parameters using a loss derivative. Backpropagation computes derivatives by applying the chain rule through a computation graph. These are distinct operations: one determines gradients, while the other uses them in an update rule.
1. A scalar objective
Consider with fixed and target . Using squared loss without a factor of gives:
The derivative follows from the outer square and the inner affine function:
At , the loss is 16 and the derivative is . Increasing by a sufficiently small amount therefore lowers the loss; the update calculation below determines how the chosen step size affects the result.
2. Updates and convergence conditions
Gradient descent with fixed learning rate uses:
For and , this gives , prediction and loss . With , the update instead gives and loss 784.
The convergence condition can be derived exactly for this quadratic. Defining the error relative to the minimizer as yields:
For a nonzero initial error, convergence requires , equivalent to:
At , the error becomes zero after one update. The stability interval follows from the curvature eight and the specified loss scaling. [1]
3. The local descent argument
For a differentiable scalar objective and a small displacement :
Substituting makes the linear term . At a nonstationary point this term is negative for . The remainder is negligible relative to the displacement only in the local limit, so finite-step behavior still depends on step size. At a stationary point, the first-order argument alone establishes no strict decrease.
4. Batch linear-regression gradients
Let , , and . Define:
Unlike the scalar example, this objective includes . Expanding the sum of squared residuals and differentiating each term gives:
Adding adds to the weight gradient. A minibatch version replaces the full-data average with a selected batch average. The differentiation is unchanged in form, while the statistical properties of the estimated gradient depend on the sampling procedure.
5. Backpropagation through a hidden layer
A scalar-output network with hidden units can be specified by:
Here , , , and . Let . Differentiation from the output gives:
Propagating through the activation and first affine layer gives:
Here denotes coordinatewise multiplication. ReLU has no classical derivative at zero; assigning zero to its backward multiplier there is an implementation convention. Away from the kink, the mask is the ordinary derivative. The weight gradient has shape , as required for an update of .
This reverse accumulation is backpropagation. A rule such as is the subsequent optimization step. During ordinary inference, parameters remain fixed and only the forward computation is required. [2]