3.1.9 · D2Neural Network Fundamentals

Visual walkthrough — Backpropagation algorithm derivation

1,722 words8 min readBack to topic

Step 0 — The picture we are working on

WHAT. A tiny neural network is a chain of boxes. Numbers flow left→right (the forward pass), get compared to a target, and a single number called the loss measures "how wrong we were."

WHY draw it first. Every symbol on this page lives on one wire or one box of this diagram. If you can point at where a symbol sits, the algebra stops being scary.

PICTURE. Below: circles are neurons (little number-holders). Each arrow carries a weight — a dial that multiplies whatever passes along it.

Figure — Backpropagation algorithm derivation

The superscript just means "belonging to layer ." It is a label, not a power.


Step 1 — The one quantity we chase: delta

WHAT. We invent one bookkeeping number per neuron, called delta:

Reading the symbols. The (curly-d) means "how much does the top wiggle when we wiggle the bottom a tiny bit, holding everything else still." So answers: "if I nudge the input-voltage of neuron in layer by a hair, how much does the final loss change?" That is exactly how much blame neuron deserves.

WHY this quantity and not directly? Because — as the picture shows — every weight feeding into neuron shares the same downstream story. If we know the blame at once, we get all those weight-gradients for free. is the shared sub-answer we cache. This "solve-once, reuse-everywhere" is dynamic programming over the graph.

PICTURE. A single neuron with a "blame meter" reading hanging off its input wire.

Figure — Backpropagation algorithm derivation

Step 2 — Blame at the very end (BP1)

WHAT. Start where blame is easiest to see: the output neuron. The loss touches through exactly one path: . One path means one plain chain rule, no sums:

Term by term.

  • — "if the output brightens a hair, how much worse is the loss?" For MSE this is simply : the raw error.
  • — the slope of the squashing curve at this neuron's voltage. It gates the error: a flat region of lets almost no blame through.

Stacking all into vectors: Here = Hadamard product = multiply matching entries (entry 1 × entry 1, entry 2 × entry 2). We use it, not matrix-multiply, because each neuron's error and its own slope pair up one-to-one.

WHY can silence a neuron. Look at the picture: on the flat tails of the S-curve, , so blame is multiplied by nearly zero. That single fact is the seed of vanishing gradients.

Figure — Backpropagation algorithm derivation

Step 3 — Why blame must fan-IN when we go backward

WHAT. Now step one layer earlier. Here the plain chain rule breaks: does not reach the loss through one path. It fans out to every neuron in the next layer, so it reaches through many paths.

WHY a sum appears. The multivariable chain rule says: total sensitivity = add up the sensitivity along each path. So

PICTURE. Forward, one neuron fans out to many (splits). Backward, those many blames fan in to that one neuron (merge). The green arrows reverse the blue ones.

Figure — Backpropagation algorithm derivation

Step 4 — The backward wire is the transpose (BP2)

WHAT. We need the "how strongly feeds " factor. Since and , wiggling only touches the term:

Plug in and pull out of the sum (it doesn't depend on ):

The key visual. Forward we used row , column of : entry . Backward the sum uses the column — i.e. we read the matrix the other way, which is exactly the transpose (rows↔columns). In matrix form:

Read it aloud, pointing at the picture:

  • route next layer's blame backward through the flipped weight grid.
  • gate it by each neuron's own local slope.
Figure — Backpropagation algorithm derivation

Step 5 — From blame to weight-gradients (BP3, BP4)

WHAT. We wanted , not . But now it's one short step. A weight enters multiplied by , so . Chain once more:

WHY this shape (outer product). A weight is guilty in proportion to (the blame of the neuron it feeds) × (how loud the input it carried was). A weight carrying a silent input () gets zero gradient — it couldn't have caused anything.

The bias gradient is just because (the bias is added straight in, weight of one). These gradients feed straight into Gradient descent.

Figure — Backpropagation algorithm derivation

Step 6 — Edge cases the picture must cover

WHY. A derivation you can trust must survive its degenerate inputs. Three that bite in practice:

  1. Dead neuron (). On the flat tail of the S-curve the gate in BP1/BP2 multiplies by . Blame stops. Multiply many such gates down a deep net → vanishing gradient. The picture shows blame shrinking each backward hop.
  2. Silent input (). BP3 gives that weight gradient — correct: an input that never fired can't be blamed.
  3. ReLU kink (). For , is for , for , undefined at exactly . In code we simply pick (or ) there — a measure-zero event. This is also why you must evaluate at , not : for ReLU the sign of is the whole story, and it's lost once you only keep .
Figure — Backpropagation algorithm derivation

The one-picture summary

WHAT. Two sweeps over the same graph. Blue goes forward computing . Yellow/red comes backward computing , and at each neuron BP3/BP4 harvest the weight and bias gradients. The whole algorithm is: forward to fill the wires, backward to pour the blame.

Figure — Backpropagation algorithm derivation
Recall Feynman retelling — the whole walkthrough in plain words

A network is a relay of message-passers (Step 0). We want to know how much each dial (weight) is to blame for the final mistake. Instead of tracing each dial's guilt from scratch, we give every neuron a single blame-meter (Step 1). We fill it first at the exit, where blame is a plain one-path chain rule: raw error times the local slope (Step 2, BP1). Then we move backward. A neuron's voltage affected many neurons ahead, so its blame is the sum of blames coming back along every wire (Step 3) — and reading the weight grid backward is transposing it, then we gate by the neuron's own slope (Step 4, BP2). Once each neuron holds its blame, a dial's guilt is just (blame of the neuron it feeds) × (loudness of the input it carried) — an outer product (Step 5, BP3), and the bias just inherits (BP4). We check the corners: flat curves kill blame (vanishing), silent inputs get zero guilt, and ReLU's kink is why must be read at (Step 6). Two passes, everything reused — that's backprop.

Recall Self-test

Where does live, on the wire or the wire? ::: On the pre-activation : . Why a sum in BP2 but not BP1? ::: Output neuron reaches the loss by one path (no sum); a hidden neuron fans out to many next-layer neurons (multivariable chain rule → sum). What geometric operation turns the forward weight grid into the backward one? ::: Transpose (swap rows and columns) — reading the same matrix in the reverse direction. Why does a silent input give a weight gradient of zero? ::: BP3 multiplies by ; if that input was , the weight carried nothing and gets no blame. Why evaluate at not ? ::: The slope is a function of the pre-activation; for ReLU it depends on , information lost if you keep only .