ContentsThe library

Backpropagation in Full

There Are No Layers, Only Operations

Before any derivative can be taken, the computation has to be broken into pieces small enough that each one has a derivative you already know. What is left is a graph.

Everyone learns the chain rule twice: once in a calculus class, where the

functions are named and the composition is two deep, and once here, where the

composition is ten million deep and nothing is named at all. The second time is

easier, but only after the computation has been written down in the right way.

Small enough to differentiate

Take a single unit: multiply an input by a weight, add a bias, squash the

result. That is three operations, not one, and the whole point of splitting them

is that each has a derivative you already know.

FIG 1One unit, taken apart
Three operations where a diagram of a network would show one unit. This is the level at which derivatives are actually taken, and every framework works here whatever it shows you.

The choice of pieces is not sacred. A framework might treat the whole multiply

and add as one operation because it is faster to do so, and it would then need

that combined operation's derivative. What cannot change is that at some level

the pieces have to be small enough to differentiate directly.

Edges, and what it means when one splits

An edge means a value was used. A value used by two operations has two edges

leaving it, and that will matter shortly.

FIG 2A value used twice
Sharing is the ordinary case rather than the exception: every weight used at more than one position of a sequence, and every parameter in a layer applied repeatedly, looks exactly like this.

A derivative is a question about paths

Here is the whole subject in one sentence, stated before any of it is derived:

the effect of an early value on the final number is a product along each route

and a sum across routes.

FIG 3The forward pass through the unit above
stepvalue producedinputs usedmust be kept for the backward passwhat happened
1201The input, x equals 2. Kept, because the derivative with respect to the weight will need it.
20.501The weight, w equals 0.5. Kept, because the derivative with respect to the input will need it.
3120The multiply, u equals 1. The product itself is not needed later, only its inputs.
41.320The add, v equals 1.3 with a bias of 0.3. Addition needs nothing kept at all.
50.86211The squash, y equals about 0.862. Kept, because the derivative of this function is cheapest to write in terms of its own output.
5 steps
The last column is the beginning of the memory problem that a later lesson is about. Some operations need their inputs, some need their outputs and some need nothing, and a deep network holds all of it until the backward pass arrives.

The order takes care of itself

Nothing in the graph points backwards, and no operation can run before its

inputs exist. That is enough to guarantee an order in which everything is ready

when its turn comes, and running that order is the forward pass. Reverse the

same order and every operation finds the results it needs waiting for it, which

is the backward pass. No cleverness is involved in either.

The graph is a recording

One last thing that surprises people: the graph is not worked out ahead of time

by inspecting the program. It is recorded as the program runs. Each operation,

as it executes, writes down what it did and stashes the values it will need

later. If the program contains a loop whose length depends on the data, the

recording simply comes out a different length that time.

That is why a model whose shape changes with its input is no harder to

differentiate than a fixed one, and why the backward pass never reads any code.

By the time it runs, the code has finished and all that is left is the record.

What to hold on to

Differentiation does not see layers. It sees a graph of small operations, edges

showing which value went where, and a structure in which a derivative is a

product along each path and a sum across paths. The graph is recorded while the

forward pass runs, together with whatever each operation will need on the way

back.

Recap

  • A network is not a stack of layers as far as differentiation is concerned; it is a graph of elementary operations, each with two or three inputs and a derivative anyone can write down.
  • The graph records which value was used by which operation, and that record is the only thing the backward pass consults: the code that built it is irrelevant by then.
  • A derivative of the final number with respect to an early one is a question about every path between them through this graph, which is why the structure matters more than the names of the layers.

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

NextComposing Derivatives →

The rest of this course

  1. 01There Are No Layers, Only Operationsyou are here
  2. 02Multiply Along, Add Acrossopening only
  3. 03Two Ways to Accumulate, and Only One Is Affordableopening only
  4. 04Four Rules That Cover Most of a Networkopening only
  5. 05The Matrix Everybody Writes Down and Nobody Buildsopening only
  6. 06Why the Last Two Steps Are One Stepopening only
  7. 07What the Forward Pass Has to Leave Behindopening only
  8. 08A Product of Many Small Numbersopening only

Read alongside