Chapter 1 · Neural networks · ≈12 min
The Approximator
A neuron is a bump of influence; a layer is a sum of bumps. Watch a tiny network sculpt itself into any curve you draw.
The prologue left you on a landscape. Every knob of a machine became an axis, wrongness became height, and learning became one small move repeated: measure the slope, step downhill. What it never said is what the machine is. This chapter builds one — the smallest one worth building — and then hands its knobs to gradient descent while you watch.
The working part is small enough to hold in your head. A neuron takes a number in, multiplies it by a weight , adds a bias , and passes the result through a fixed curve called an activation. This book starts with the gentlest activation, the hyperbolic tangent:
That is the whole organism. In one dimension its output is a smooth step: flat, a rise, flat again. The weight sets how steep the rise is and which way it faces; the bias slides it along the input. One step is a poor vocabulary — so we hire more. A layer is a row of neurons reading the same x, each with its own weight and bias: a palette of steps, tilted and placed differently. An output layer mixes the palette, scaling each step by an output weight and adding them all up:
Subtract one step from a slightly shifted copy and you get a bump. Sums of steps are therefore sums of bumps: little hills of influence you can place, widen, and flip. The universal approximation theorem makes this precise — with enough hidden neurons, f can match any continuous curve on an interval as closely as you like.1 It holds from the other direction too: keep the layer narrow, barely wider than the input, and stack it deep enough, and you get the same guarantee.2
Read either of them honestly, though. They say the right weights exist; they say nothing about how to find them, and “enough” can be an absurd number. And a theorem about what a machine could represent is a weaker thing than it sounds — a large enough lookup table is a universal approximator too, and no use to anyone. The question that decides whether a network is worth building is not which curves it could draw in principle. It is which ones it finds easily, from a random start, by walking downhill. That is the previous chapter's business: write the error down as a loss, and send gradient descent looking.
One neuron, three knobs
Before training anything, get your hands on the unit itself. Below is the same neuron twice: on the left as a circuit — the ultramarine edge carries , the violet edge carries , and the blue-cyan edge on the way out carries the amplitude , while the teal curve on the dial between them is whichever is selected — and on the right as , the one shape it can draw. The third knob, , is just another coefficient — an amplitude that stretches the bend taller or flips it upside down. Move each slider until you can predict what both views will do before you touch it. Then swap itself and see which of your intuitions survive: the same three knobs pull very different shapes out of a relu than out of a tanh.
The bend is the whole point
Strip out and a neuron is just — a line. Stack a hundred all-linear layers and the stack collapses: a line of a line is still a line, so the deepest such network can be multiplied out into a single matrix wearing a hundred costumes. The activation is the only part of the machine that refuses to be linear, and everything a network can do that a line cannot — every curve, corner, and decision — is purchased at that little bend.
Training cares about a second, quieter property: the slope. Gradient descent reaches every weight through the chain rule, and the chain rule multiplies by at each layer it crosses on the way back. The field guide below therefore draws every activation twice — the function solid, its derivative dashed. Wherever the dashed curve hugs zero, learning goes quiet. The two classics saturate at both ends, which is how deep sigmoid networks starved for decades — the vanishing gradient, and a large part of why the field spent those decades shallow.3
relu4 is silent across its entire left half instead, which sounds worse and is not: on the right it never saturates at all, so a gradient can cross ten layers without being multiplied down to nothing. The cost is that a unit driven far enough left stops receiving gradient and is called dead; its leaky cousin5 keeps a trickle flowing on purpose. That half of relu's units are silent at any moment turns out to be part of the appeal rather than a defect — the network computes on a changing, sparse subset of itself.6
The last three — gelu7 , silu8 , mish9 — sand the corner off and keep a little slope slightly below zero, which is one reason the transformer era settled on them. Silu arrived twice: once from researchers building reinforcement learners, and again the same year, out of an automated search over candidate formulas that reported it as a discovery under a different name.10 That is roughly how this corner of the field works. Nobody derives an activation from first principles; they are found, measured, and kept if they win.
None of this changes what networks can express — the universal approximation theorem is not picky about the bend. What it changes is the handwriting of the fit and the temperament of training, and you will see both first-hand in the workshop that follows.
squashes to (0, 1) — the original; survives as the gate in LSTMs and GLUs
the zero-centered squash — the gentle default this chapter starts with
the crease that made deep nets train — cheap, sharp, occasionally dead
a trickle of slope below zero keeps dead units trainable
exponential below zero: smooth, and its negative outputs center the layer
relu with the corner sanded off — everywhere in theory, rare in practice
z weighted by the Gaussian CDF — BERT and the GPT line run on it
z gated by its own sigmoid — inside the SwiGLU blocks of the Llama family
self-gated like silu, a touch softer — computer vision’s pick
The curve workshop
Now give the knobs away. The workshop below holds a whole network and trains it live, in a worker beside this page, by the only rule this book uses — — with the loss set to the mean-squared error, the average of over the training points. Every step pulls the network’s curve a little closer to a target.
You see the machine three ways at once. On the left sits the network itself: every edge is one weight, drawn thicker as it grows, ultramarine when positive and vermilion when negative. On the right, the curve it currently draws against the dashed target. And underneath, the palette — the curves the deeper layers output, ending in the last hidden layer’s contributions, each drawn in the color of its output weight’s sign and thicker as that weight grows. Hover any neuron in the diagram to light up its wiring — and, if it owns a tile, the curve it outputs; or hover a tile to find its neuron.
Train on the sine and watch the palette organize — units that began as arbitrary steps drift into position, each claiming a stretch of the curve. Switch the target to bumps mid-training and the units renegotiate. Then take the pen and draw your own curve straight onto the plot: the network will chase it while you drag.
the curves the deeper layers output — the last hidden layer is drawn as v·tanh(…), ultramarine where its output weight v is positive, vermilion where negative, thicker as |v| grows; the fit above is exactly their sum. hover any tile or any node in the diagram — the highlight runs both ways
What width buys, what depth buys
Width buys vocabulary. Every extra hidden unit is one more step the output layer can place, so a wider palette affords finer detail: at width 2 the sine defeats the network — two steps cannot make three bends — while at width 16 it has bumps to spare. Watch the parameter count as you widen, though. Vocabulary is not free.
Depth buys reuse. With one hidden layer, every wiggle must be purchased with its own neurons. Add a second layer and the new neurons stop reading x directly: they read the first layer’s steps, and can bend an already-bent thing — bumps of bumps. A third layer bends the bumps of bumps again. The same budget of parameters goes further because pieces are reused instead of re-made.
That is not just a nicer story; it is a measurable gap. Count the straight pieces a relu network's fit is made of and the count grows roughly in proportion to width, but multiplies with each layer of depth — every layer folds the folds beneath it.11 And there are functions a deep network draws with a handful of units that no shallow network can match without an exponential number of them.12 In one dimension the difference is subtle; in the chapters ahead, where inputs are images, it is most of the story.
The activation sets the network’s handwriting. tanh is a soft wave, so its sums are smooth and rounded everywhere. The rectified linear unit — relu, zero on the left, a straight ramp on the right — creases instead of curves: its sums are piecewise-linear, and you can count the folds in the fit. Switch the workshop to relu on the |x| target and it lands almost at once, because the target is itself two creases. Switch back to tanh and watch it round a corner it can never make sharp. The workshop also carries the modern pair from the field guide — gelu and silu — which crease like relu with the corners sanded smooth; try them and read the difference straight off the palette.
One honest warning before you scale everything up. The workshop samples its target at 256 points packed densely along the interval, so fitting the data and fitting the curve are nearly the same task. They usually aren’t. With few points and many neurons, a network can pass through every training point exactly and still be wrong everywhere between them — wiggling where it should glide. That failure is called overfitting, and nothing in the loss ever asked the network to behave between the points. This book meets it properly once real data arrives.
The old lesson drawn from that is: capacity is dangerous, so keep the model small. The last decade made a mess of the lesson. Take a network that reads photographs well, shuffle the labels so every answer is now noise, and train it again — it fits all of them, perfectly, memorising the lot.13 Its capacity to overfit is total. Hand back the real labels and the very same network generalizes. Whatever stops it from doing the same to those, it is not a shortage of room.
Stranger still is what happens if you keep growing it. Test error rises as the textbook promises, peaks right at the size where the model can just barely fit its training set exactly — and then, as the model gets bigger still, comes down again, often below anything the small models managed.14 The curve has two descents, and the classical one is only the first. The models in the news live far out on the second, in the region the textbook picture calls hopeless, and the same double dip appears in how long you train, not only in how big you build.15 None of this repeals overfitting. It moves the explanation somewhere more interesting: what keeps an over-parameterised network honest is not how few parameters it has, but which of the enormous number of perfect fits gradient descent happens to walk to.
This chapter happened in one dimension on purpose: you could see every neuron, every bump, and the whole sum at once. Nothing was hidden — the palette under the plot is the network, laid out flat.
The next chapter keeps the machine and changes the canvas. In two dimensions a network stops looking like a sum of bumps and starts doing something stranger and better: it bends the space the data lives in, until problems that looked hopeless become straight lines. When you’re ready, go bend space.
Sources
- 1 Approximation by superpositions of a sigmoidal function The universal approximation theorem, for one hidden layer of sigmoids. Read the proof and notice what it never mentions: how many neurons, or how to find their weights.
- 2 The Expressive Power of Neural Networks: A View from the Width The mirror image of Cybenko: hold the width just above the input dimension and stack deep, and you are universal again. Width and depth are two ways to buy the same guarantee.
- 3 Understanding the difficulty of training deep feedforward neural networks Measures the saturation directly, layer by layer, and shows how a badly scaled start drives sigmoid units flat and holds them there.
- 4 Rectified Linear Units Improve Restricted Boltzmann Machines Where the crease enters modern practice.
- 5 Rectifier Nonlinearities Improve Neural Network Acoustic Models Leaky relu — a trickle of slope below zero, so a unit that falls silent can still be argued back.
- 6 Deep Sparse Rectifier Neural Networks The case that relu wins not despite its dead half but partly because of it: at any moment most units are silent, and the network computes on a sparse subset of itself.
- 7 Gaussian Error Linear Units (GELUs) The bend the GPT and BERT lines are built on: weight the input by the chance a standard normal falls below it.
- 8 Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning SiLU, found while building reinforcement learners.
- 9 Mish: A Self Regularized Non-Monotonic Activation Function Self-gated like silu, a shade softer, and the one computer vision kept.
- 10 Searching for Activation Functions The same function found again from the other end — by automated search over candidate formulas, which reported it as Swish before noticing it already had a name.
- 11 On the Number of Linear Regions of Deep Neural Networks Counts the creases. A relu network folds its input space, and each new layer folds the folds — so the pieces multiply with depth and only add with width.
- 12 Benefits of depth in neural networks A function a deep network draws with a handful of units that any shallow network would need an exponential number to match. Depth is not a convenience.
- 13 Understanding deep learning requires rethinking generalization Replace every label in a photograph dataset with a random one. The same networks fit all of it, perfectly. Whatever stops them from memorising real data, it is not a shortage of capacity.
- 14 Reconciling modern machine learning practice and the bias-variance trade-off The double-descent curve. Test error peaks exactly where a model can just barely fit its training set, and then falls again as the model keeps growing.
- 15 Deep Double Descent: Where Bigger Models and More Data Hurt The same second descent in real deep networks — in model size, in training time, and, uncomfortably, in dataset size.