Answers · How models work
What is actually new in a neural network compared with linear regression?
In shortOnly three things are new: the slopes are computed by working backwards, the score is no longer a bowl, and the model builds its own inputs. The prediction, the loss, the step and the held out check are unchanged.
A neural network is a prediction, a score, a slope for every knob and a step against the slope, which is exactly the four parts a fitted straight line already has. Three things are genuinely new: the slopes are computed by working backwards through the layers, the score is no longer a bowl, and the inputs are built by the model rather than chosen by a person. Everything else is the same machinery at a larger size.
- the output of unit m, which becomes an input to the next layer
- the knob unit m puts on input j, so a layer of M units over k inputs has M times k of them
- a squashing function applied to the total
- unit m's offset
The same machinery, counted
For one input, the line has knobs. Three hidden units reading two inputs carry weights and 3 offsets, and one output unit reading those three adds 3 weights and 1 offset, so 13 knobs in all. Watch what happens to a knob, old or new. Take with target , start at , , step size . The prediction is 1, the error is , the squared score is 4. The slope in is , so becomes . A second pass: prediction 1.4, error , score 2.56, slope , so becomes . A network runs that same sequence, with the prediction computed as one pass forward through the layers, the same squared error on top, and the same subtraction at the end.
The guess that fails is that a network is a different kind of object, so the shared parts go unrecognised. Linear regression is not a cousin of a network, it is the last layer of one, and everything in front of that layer exists to hand it a better set of inputs. The extra layers add repetitions, not a new ingredient, and the repetition only counts as depth because of the squash. Without it, two layers multiply out into one line.
The three things that are new
With , , , that stack is , a single line with two knobs' worth of freedom and no more, however many layers you add.
The first new thing is how the slopes are computed. A knob in an early layer reaches the score only through everything after it, so its slope is a product of one factor per layer crossed. Each factor is shared by every knob below it, and working backwards from the score computes each factor once instead of once per knob. The backward pass costs about twice a forward pass, so one fitting cycle costs three forward passes' worth of arithmetic: at knobs that is 3,000,000,000 multiply and add operations per cycle, and no more than that, which is why a model that size is fittable at all.
The second is the shape of the score. With a straight line and squared error the score is quadratic in the knobs and the bottom can be solved for in one line. Nesting multiplies knobs together, and a product has more than one bottom: is zero at and again at . Nothing can be solved for, so stepping downhill is the only method, where the fit ends up depends on where it started, and the answer is a good setting rather than the best one. Starting every knob at zero is wrong in a specific way: with all weights zero every unit in a layer outputs , so the units are identical, receive identical slopes, and stay identical at every step thereafter.
The third is that the inputs are learned, and it is the reason networks get used. Four measurements into a straight line is knobs, and a person chose those four. A million pixels into a thousand units is knobs, and not one of them usefully multiplies a single pixel on its own. The early layers build the description that the last layer reads, so what gets fitted is the relationship and the variables it is stated in, not just the relationship.
Where the equivalence runs out
The reduction is exact for prediction, loss, slope and step, and it stops being useful when depth buys nothing. On a table of a few thousand rows and four columns the hand chosen inputs are already the right ones, and a straight line with a penalty on the size of its knobs is often as good as anything deeper. The landscape point cuts both ways as well: with very many knobs the poor stopping points turn out to be rare, and most places the fitting settles score about as well as each other, so the lost guarantee costs less in practice than a picture of a lumpy surface suggests.
Worth keeping
- A network's last layer is a linear model, so the prediction, the loss, the step against the slope and the held out check are the same four things a straight line uses.
- Three features are genuinely new: slopes computed backwards through the layers, a score that is no longer a bowl, and inputs the model builds for itself.
- Delete the squash between layers and any depth of stack collapses into one straight line, so the squash is what makes depth mean anything.
Where this goes next
This question is one step of The Simplest Model That Learns, a course that works through its subject from the beginning. The page that teaches this part of it is The Same Four Parts, Much Bigger, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why does logistic regression use a sigmoid instead of a straight line?The sigmoid turns an unbounded straight-line score into a probability between zero and one, and it pairs with the log score so fitting keeps the same gradient shape.
- What is the difference between the inputs and the weights in a linear model?The input is supplied by each example and changes from row to row; the weights are the model's adjustable numbers, chosen once by fitting and shared by every example.
- How do I know if I should increase or decrease the slope to reduce the error?The sign of how fast the loss changes with the slope tells you: positive means lower the slope, negative means raise it.
- Why does linear regression square the errors instead of just adding their absolute values?Squaring makes large errors count much more than small ones, so it picks a different line from absolute value; absolute value is a different choice about costs, not a mistake.
- Why does the model get stuck repeating the same sentence over and over?The model is not stuck in a memory loop: once it has written a phrase, that phrase is in its context and makes writing it again more likely, so a decoder that always picks the top word cannot leave.
- Why does diffusion add Gaussian noise instead of any random corruption?Diffusion adds Gaussian noise because Gaussian errors combine exactly: each step keeps the spread fixed and gives a closed-form noisy picture at any later step, which makes the reverse step learnable.