Part VIII — Neural Network Fundamentals, Backpropagation & Optimizers · Chapter 5

A network is a chain

Hook

Part I's chain rule found the slope of one function composed with another. A network is one neuron feeding the next feeding the next — so isn't that just the chain rule, several times over?

Intuition
h(x) = 0.27, y(x) = 0.55, dy/dx = -0.292

This whole curve is y(x)=σ(w2h(x)+b2)y(x) = \sigma(w_2\, h(x) + b_2), where h(x)=σ(w1x+b1)h(x) = \sigma(w_1 x + b_1) is itself the output of a first neuron. Drag along it — the tangent line you see is the composed function's real slope, and it's built from nothing but two ordinary sigmoid derivatives.

Formalize

Exactly Part I's chain rule, applied once per layer:

dydx=dydhdhdx\frac{dy}{dx} = \frac{dy}{dh} \cdot \frac{dh}{dx}
  • xx — the network's input.
  • hh — the first neuron's output, which feeds into the second neuron as its input.
  • yy — the second neuron's output, the whole composed function's final value.
  • dhdx\frac{dh}{dx} — the first neuron's local slope: its own sigmoid derivative times w1w_1.
  • dydh\frac{dy}{dh} — the second neuron's local slope with respect to its input hh: its own sigmoid derivative times w2w_2.
  1. Each neuron contributes its own local slope
    • dhdx\frac{dh}{dx} is the first neuron's local slope — its own sigmoid derivative times w1w_1.
    • dydh\frac{dy}{dh} is the second neuron's local slope with respect to its input, which happens to be hh — its sigmoid derivative times w2w_2.
  2. Multiply straight through the chain

    Multiply the two and you have the slope of the whole chain, with respect to the very first input.

Play
dy/dh = -0.536 × dh/dx = 0.393 = -0.211

The readout splits the product into its two factors. Neither factor alone is the answer — you need to multiply straight through the chain, exactly the way Part I's chain rule always worked, just with the first function's output value substituted into the second function's slope.

Worked example

At x=0.5x=0.5:

  1. Compute the first neuron's output and slope

    w1x+b1=2(0.5)1=0w_1 x + b_1 = 2(0.5)-1 = 0, so h=σ(0)=0.5h = \sigma(0) = 0.5 and dhdx=σ(0)w1=0.252=0.5\frac{dh}{dx} = \sigma'(0)\cdot w_1 = 0.25 \cdot 2 = 0.5.

  2. Compute the second neuron's slope, at h

    w2h+b2=3(0.5)+1=0.5w_2 h + b_2 = -3(0.5)+1 = -0.5, so dydh=σ(0.5)w20.235(3)=0.705\frac{dy}{dh} = \sigma'(-0.5)\cdot w_2 \approx 0.235 \cdot (-3) = -0.705.

  3. Multiply the two slopes together
    dydx=0.705×0.5=0.353\frac{dy}{dx} = -0.705 \times 0.5 = -0.353

    Matching the tangent line exactly at that point, and matching a plain numerical derivative to five decimal places.

Checkpoint

Drag along the curve until its slope reaches -0.353 — the slope at x = 0.5.

x = -3.00 — dy/dx = -0.001
Drag the point to try it
Summary
dydx=dydhdhdx\frac{dy}{dx} = \frac{dy}{dh} \cdot \frac{dh}{dx}

A two-layer network's gradient is a two-term product; an nn-layer network's gradient is an nn-term product — the exact same chain rule, repeated once per layer. That repeated multiplication, computed efficiently backward through the whole network, is what the next two chapters actually build.