Basis Lab

From a Straight Line to Backpropagation

Putting a Bend in the Model, and Differentiating Through It

Last timeHow Far to Step

A squashing function after the line makes the model a composition, so the derivative becomes a product of four local slopes, worked here by hand on one measurement.

The twelve measurements have already been fitted exactly. Two derivatives set

to zero gave two equations, the two equations gave w=3w = 3 and b=2b = 2, and at

that answer the total squared error is 12, a mean of 1 per measurement. Nothing

in it was approximate and nothing in it was iterative.

A line pays for that exactness by having one slope and using it everywhere.

Whatever it does at the left-hand end of the data it does again at the

right-hand end. Most measured quantities do not behave like that: a response

that grows and then levels off, a dose that stops helping, a queue that only

gets slower until the machine saturates and then goes vertical. A model that

cannot flatten will fit the middle and be wrong at both ends, and no amount of

solving rescues it, because the failure is in the shape of the model rather

than in the values of its parameters.

So the model gets a bend in it. The bill arrives immediately, because the

closed form goes and does not come back, and the only thing left is the slope

of the error where you happen to be standing. This page computes that slope,

slowly, on one measurement.

A bend you can control

The bent model itself is already established: the input scaled as u=x/12u = x/12,

the old straight line rebuilt on the scaled input as a=wu+ba = wu + b, the squashed

value t=tanh⁡at = \tanh a lying between minus one and one, and p=vt+cp = vt + c putting

that back on the scale of measurements running from 6 to 39. Two things about

it are settled and are not argued again here: that ww sits inside the

squashing function, so the twelve terms of a derivative cannot be collected and

there is no formula for the answer, and that dividing the input by twelve is

what keeps the arguments off the flat part of the curve. The one fact needed now

is the shape. Four steps separate the input from the prediction, each with one

input and one output, and that is what makes the derivative a product.

FIG 1The model with a bend in it
the input scaled into the range from one twelfth to one, so the squashing function is not asked to work where it is flat
the input weight, which sets how fast the squashing function is traversed as x grows
the input offset, which decides which part of the squashing curve the data lands on
the pre-activation, which is the old straight line in the scaled input
the squashed value, somewhere between minus one and one
the output weight, which scales the squashed value back up to the size of the measurements
the output offset, which moves the whole curve up or down
the squared error on measurement i on its own, so the total error is the sum of twelve of these
Four parameters now rather than two, and four steps between the input and the prediction. The scaling of the input is fixed rather than fitted, and the index i runs over the twelve measurements.

Where the scaling earns its place is in that product, and this is the first

page on which that can be shown rather than asserted. The slope of the

squashing function, derived in the next section as

4/(ea+e−a)24/(e^{a} + e^{-a})^{2}, is 4/(54.5982+0.0183)2=4/2982.96=0.00134/(54.5982 + 0.0183)^{2} = 4/2982.96 = 0.0013 at

a=4a = 4, against about one near zero, and it is one of the four factors in the

derivative with respect to ww. Feed the raw xx in with ww near one and the

whole derivative is multiplied by a thousandth, so the parameter sits almost

still however wrong it is.

The lesson stops here

8 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

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

The rest of this course

  1. 01Measuring How Wrong a Straight Line Is, on Twelve Points
  2. 02The Two Equations That Pin Down the Best Lineopening only
  3. 03When the Derivative Equations Stop Being Solvableopening only
  4. 04The Largest Step This Data Allowsopening only
  5. 05Putting a Bend in the Model, and Differentiating Through Ityou are here
  6. 06Every Derivative of a Two Unit Network, by Handopening only
  7. 07One Sweep Back Instead of Seven Chainsopening only
  8. 08Running It, and Reading the Curve It Producesopening only

Read alongside