Backpropagation computes the derivatives of a neural network's loss function with respect to its weights and biases by applying the chain rule from the output layer toward the input (Rumelhart et al. 1986). It is an application of reverse-mode automatic differentiation (Baydin et al. 2018).
Consider a feedforward network with fixed input column vector ,
layers, weight matrices
, and bias column vectors
. At layer
, let
|
(1)
| |||
|
(2)
|
where the activation function acts componentwise and is differentiable at the values
used. For a differentiable scalar loss
, define the column vector
. Writing
for componentwise multiplication and
for transpose, the chain rule
gives
|
(3)
| |||
|
(4)
|
with the second equation applied for . The derivative with
respect to the weight
is
and the derivative with respect to the bias
is
. These derivatives can
be used by the method of steepest descent
to update the parameters.
For example, take a two-layer scalar network with no biases, input , hidden activation
, output
, and loss
. At
and
, the forward calculation
gives
and
. The backward calculation gives
and
,
so
and
. 3Blue1Brown (2017) illustrates
the chain rule for a network with scalar layers.