liveBook · Manning

Chain rule

As explained in Deep Learning with Python, Third Edition

The differentiation rule for composing functions, used to compute gradients through layered neural-network operations.

The chain rule computes the derivative of a composed function from the derivatives of its smaller steps. This matters because neural networks chain tensor operations, allowing gradients to flow backward through complex models. section 2.4.4

From two functions to a gradient chain

Let x1 = g(x) and y = f(x1). Then grad(y, x) = grad(y, x1) * grad(x1, x). Add more operations and the factors extend into a chain: grad(y, x) = grad(y, x3) * grad(x3, x2) * grad(x2, x1) * grad(x1, x). section 2.4.4

loss_value = loss(
    y_true,
    softmax(matmul(relu(matmul(inputs, W1) + b1), W2) + b2),
)

Trace a two-layer network as one composition: matrix multiplication, addition, ReLU, matrix multiplication, addition, softmax, and loss. section 2.4.4

Use the rule as a practical checklist:

  • Break a complex expression into atomic operations with known derivatives. section 2.4.4
  • Multiply local derivatives along the computation path to obtain the overall gradient. section 2.4.4

How Deep Learning with Python, Third Edition covers it

How deep it goes
Derives the composition identity and applies it to computation graphs, stopping before detailed backward-pass calculations.
Examples
Uses composed functions and a two-layer network containing matrix multiplication, ReLU, softmax, addition, and loss.
What it assumes
Assumes familiarity with differentiable functions and basic derivatives.
What you can do after
Apply it via computation graphs to calculate gradients through complex chains of differentiable operations.
How it connects
Connects derivatives, backpropagation, automatic differentiation, computation graphs, and tensor operations.

Also explained in

Compare how 4 books explain chain rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.