Part 6 of 6 · Chapter 4 of 5

Neural Networks

A neural network is not a brain. It is the straight-line fit you already understand, stacked, with one small bend between the layers — add hidden units one at a time and watch a flat boundary learn to curve.

Advanced14 min read

Worth reading first: How a Model Learns, Gradient Descent


Call it a neural network and it sounds like it thinks. It does not. Take the word apart and what is left is machinery you already built by hand, earlier in this track — copied several times over, with one deliberate kink wedged between the copies. This chapter is that machinery, with the mystique stripped off.

What is actually inside one

Start with a single unit — one circle in any diagram you have ever seen of a network. Inside it: a weighted sum of its inputs, plus a bias — z = w1·x1 + w2·x2 + … + b. That is the exact shape of the model you built in How a Model Learns, just admitting the one term that example deliberately left out. Nothing about a single unit is neural in any sense a biologist would recognise. It is a straight-line fit, drawn as a circle instead of a graph.

A network is many of these, arranged in layers, each layer’s output feeding the next layer’s input. So try the obvious question: what happens if you stack two of these weighted sums, with nothing in between?

Stacking two linear layers, with nothing between them
layer 1:  h = W1x + b1layer 2:  y = W2h + b2        = W2(W1x + b1) + b2        = (W2W1)x + (W2b1 + b2)

The last line is a weighted sum and a bias. Nothing else survives. Layer two just relabelled layer one’s numbers — W2W1 is one matrix, W2b1 + b2 is one bias — and ten stacked layers collapse the same way, in one more step each. A network built entirely from this circle, however deep, can compute nothing that a single weighted sum could not.

Which means the activation function — the one piece not yet mentioned — is not a detail bolted onto the design. It is the entire reason stacking layers does anything at all.

The bend that changes everything

The activation most networks reach for by default is called ReLU, and the name is more intimidating than the definition. The whole of it: negatives become zero. Feed a unit’s weighted sum through ReLU and anything above zero passes through untouched; anything below zero is clamped to exactly zero.

One unit, run through that, gives you one fold in an otherwise straight line — flat on one side, sloped on the other. That alone breaks the collapse from the last section: a fold is not a weighted sum, so relabelling stops working, and stacking starts buying you something.

One fold is not a curve. But a handful of them, each oriented and positioned differently by training, cut the input into a patchwork of flat pieces that — looked at from far enough away — trace something that bends. A network never has a circle or a curve operation available to it. It only ever has straight pieces, glued together at a growing number of folds. Watch that happen below: an inner ring and an outer ring that no straight line can separate, and a decision boundary built entirely out of ReLU folds, one hidden unit at a time.

Add hidden units one at a time

An inner ring and an outer ring, 180 points in total. The shading is the region the network currently calls each class. Circles are the inner ring, squares the outer one; filled marks are what it trained on, hollow marks are the 60 it never saw.

inout

No hidden layer: a straight weighted sum, same as How a Model Learns.

  • inner ring
  • outer ring
  • filled = trained on, hollow = held back

no hidden units — a straight line

Training accuracy

62.5%

over the 120 points it trained on

Validation accuracy

61.7%

over the 60 it never trained on

Width, depth, and what each one buys

At zero hidden units the widget above is exactly the straight-line model from the first section, and it shows: 62.5% on the points it trained on, 61.7% on the ones it did not — barely past guessing, because half of each ring sits on either side of any line you could draw. One or two units bend that line slightly and buy almost nothing (69.2%, then 85.0% training accuracy, with validation trailing well behind at 63.3% and 68.3%). By three units the fold count catches up with the shape: 99.2% training accuracy, 93.3% held back. Five is where this particular ring stops needing help — 98.3% on data it never trained on, the best any width reaches here. Pushing on to eight buys nothing further: training accuracy tops out at 100%, and validation sits exactly where it sat at five. The extra capacity is not fitting the ring any better. It is chasing individual training points that happened to land where they did.

That is width — more units in the same layer, each one a fresh fold available at once. Depth is the other axis: more layers, stacked, so a fold in a later layer can bend a fold the earlier layer already made.

More width

More independent folds side by side in one layer. Cheap to reason about, and exactly what the widget above is varying — every extra unit is one more straight edge available to carve the input with.

More depth

Later layers get to compose what earlier layers already folded. A bend of a bend can trace shapes that would need far more width to fake with a single layer — which is why deep networks, not just wide ones, became the default.

What they cost you

None of the above is an argument against networks. It is the case for reading this section before reaching for one, because everything that made the models earlier in this track pleasant to work with, a network mostly gives up.

What you are actually signing up for

  • Far more data. The ring above lives in two dimensions and still needed 120 training points to fit well. A network doing anything real is fitting thousands or millions of numbers, and each one needs examples to pin it down. The trees, forests, and neighbour models earlier in this track were routinely trained on dozens of rows.
  • Many more knobs, and no formula for most of them. How many units, how many layers, which learning rate, how long to train, how the weights start — each is set before training begins, usually by trial. Regularisation, the complexity rent from the last chapter, is still one lever among a dozen others here, tuned the same trial-based way.
  • Much harder to interrogate when it is wrong. A decision tree can name, in one sentence, which split sent a case down the wrong branch. Ask a network the same question about one wrong prediction and the honest answer is that thousands of numbers shared the blame, in proportions nobody has agreed how to compute. Finding out why a network is wrong is a research problem, not a debugging session.
  • Frequently beaten on the data you actually have. Feed a rows-and-columns dataset — the shape every model in this track has trained on — to a well-tuned gradient-boosted tree, and it routinely beats a neural network of any width or depth, for less tuning and none of the data appetite. Reaching for a network on tabular data is usually solving a problem you do not have.

The next chapter does not touch the model at all. It assumes you already have one that scores well and asks the harder question: what happens to that number on Tuesday’s data, six months from now, once nobody is watching it. The model was never the hard part. Keeping it working is.

Key takeaways

  • A unit is a weighted sum and a bias — the same shape from How a Model Learns — and stacking that shape with nothing between the layers collapses straight back into one linear layer.
  • ReLU is the entire trick: negatives become zero. Every curve a network draws is straight pieces, folded together in growing numbers.
  • Width adds independent folds side by side; depth lets later folds bend what earlier ones already bent.
  • The universal approximation theorem proves the right weights exist. It says nothing about whether gradient descent can find them or how much data that would take.
  • On ordinary spreadsheet-shaped data a well-tuned gradient-boosted tree usually beats a network outright. Reach for one because the problem needs it, not because it sounds more advanced.