Lesson 1.4foundation3 h

Derivatives, gradients and the chain rule

How a tiny change in a parameter changes the loss

Learning is the question "if I nudge this parameter, does the loss go down?" asked millions of times. The derivative answers it for one variable, the gradient for all of them at once, and the chain rule lets you answer it for a function built from thousands of simpler pieces — which is what a neural network is. Backpropagation (4.4 Backpropagation, fully derived) is the chain rule organized on a graph, autograd (2.4 PyTorch I: tensors, autograd and the training loop) is software that applies it, and gradient descent (1.10 Optimization: from gradient descent to Adam) is what you do with the answer.

You'll be able to

  • Differentiate the functions that appear in models (powers, exp, log, sigmoid, tanh, ReLU) and explain the derivative as a local linear approximation
  • Compute partial derivatives and gradients, and prove that the gradient is the direction of steepest ascent
  • Apply the chain rule through a composition and on a computation graph (multiply along paths, add over paths)
  • Verify an analytic gradient with a central finite difference and interpret the relative error

Key ideas

  1. f(x + h) ≈ f(x) + f′(x)h: the derivative is the slope of the best local linear approximation.
  2. σ′ = σ(1 − σ) with maximum 1/4; tanh′ = 1 − tanh²; ReLU′ is 0 or 1 — the derivatives that govern vanishing gradients.
  3. The gradient ∇f collects all partial derivatives; D_u f = ∇f · u, so ∇f is the direction of steepest ascent and is perpendicular to level sets.
Show 4 more key ideas
  1. Chain rule: multiply derivatives along a path, add over paths — on a computation graph this is backpropagation.
  2. Worked neuron: ∂L/∂w = 2(a − y) · a(1 − a) · x; a gradient step lowered the loss from 0.0723 to 0.0669.
  3. Check analytic gradients with the central difference (f(x+ε) − f(x−ε))/2ε, ε ≈ 1e−5; relative error below 1e−7 passes.
  4. Learning = model + loss + gradient (chain rule) + update θ ← θ − η∇L, repeated.

Suggested path through this lesson