jaxverse
Contents

jaxverse

A little universe of learning machines, designed and built by Neo Mohsenvand.

Chapter 2 · Representation · ≈13 min

Bending Space

Why does deep learning work at all? Because a network is a smooth deformation of space — watch it untangle spirals until a straight line can tell them apart.

In the last chapter a network bent a line into any curve you asked for. That was approximation. Classification sounds like a different job — here are two families of points, ultramarine and vermilion, tangled into each other; tell them apart — and the standard picture of it is a network drawing a boundary between the classes, the way you might draw a fence between two herds.

That picture is wrong in a quietly important way, and this chapter exists to replace it. A neural network does not draw a boundary around the data. It picks the data up — all of space, with the data embedded in it — and deforms the whole sheet until the two classes stand on opposite sides of a straight line. The boundary you see in the input is just the crease left behind.

Look at what one layer actually computes:

h  =  σ(Wx+b)h \;=\; \htmlClass{eq-op}{\sigma}\big(\htmlClass{eq-model}{W} \htmlClass{eq-world}{x} + \htmlClass{eq-model-2}{b}\big)

The affine part Wx+b\htmlClass{eq-model}{W}\htmlClass{eq-world}{x} + \htmlClass{eq-model-2}{b} rotates, stretches, and shifts the plane. Then the bend σ\htmlClass{eq-op}{\sigma} warps each coordinate — the classic tanh\htmlClass{eq-op}{\tanh} squashes it smoothly toward the interval (1,1)(-1, 1), though it pays for that gentleness in training time; the plates below open with gelu, which bends nearly as smoothly and learns in a fraction of the steps. Nothing here can cut or tear: the map is continuous, so points that started close together end up close together. And when W\htmlClass{eq-model}{W} is invertible and the bend is smoothly invertible, as tanh is, the layer gives up even more than that — it becomes a homeomorphism, a deformation with a continuous inverse, the kind of move you could perform on a sheet of soft rubber without ever pressing two parts of it together.

Plate I What one layer does
xthe planea ring around a diskWx + bthe affine partturned, stretched, shiftedσ(Wx + b) · hthe bendall of it, inside (−1, 1)²Wx + bσ
One layer, drawn on the sheet it acts on rather than on the data sitting upon it. Left: the plane, with a ring around a disk. Middle: the affine part has turned, stretched and shifted the whole sheet, and every line of the grid is still straight — an affine map cannot make a straight line bend, which is the entire reason a stack of them alone would collapse into one. Right: the bend, applied to each coordinate on its own. The lines curve now, and the whole infinite plane has been drawn inside a square two units across: that square is this panel's teal border, which is why the grid crowds against it and why the panel is magnified twice over the other two. Nothing was cut and nothing was pulled apart, and the ring still surrounds the disk — which is exactly the trouble the next plate walks into.

A deep network is a chain of such moves, finished by one boring linear classifier:

f(x)  =  linear cuttrivial    σ(WL)σ(W1)the deformation  (x)f(\htmlClass{eq-world}{x}) \;=\; \underbrace{\text{linear cut}}_{\text{trivial}} \;\circ\; \underbrace{\htmlClass{eq-op}{\sigma}(\htmlClass{eq-model}{W_L} \cdot) \circ \cdots \circ \htmlClass{eq-op}{\sigma}(\htmlClass{eq-model}{W_1} \cdot)}_{\text{the deformation}}\;(\htmlClass{eq-world}{x})

So the entire intelligence of the machine lives in the deformation. The final layer can only cut once, with a straight line; the layers before it must rearrange the world until one straight cut is enough. Watch it happen.

Plate II The experiment — rings, and a network two numbers wide
waking the network… it trains right here, on your machine — nothing leaves this page
Left: the data as it is, with the network's current verdict washed behind it. Middle: the same points — the same grid — after the network's deformation, and the one straight cut the final layer makes. Right: the network itself, live — every edge is one weight. Train, and watch it strain: a ring inside a ring cannot be pulled apart without leaving the plane. Then flip hidden from 2-D to 3-D and watch the same cut succeed. Hover the middle view and press unfold to replay the deformation.

Why it failed, and what fixed it

With two hidden units, the network's inner world is itself a plane, and you watched it try every move it has. It cannot win, and the reason is not effort.

Take the smooth case first, because it is the clean one. With tanh\htmlClass{eq-op}{\tanh} and an invertible W\htmlClass{eq-model}{W}, every layer is a homeomorphism: the sheet stretches and bends as far as you like, but it is never cut and never folded back onto itself, so what was inside stays inside. The vermilion ring encircles the ultramarine disk before the deformation and encircles it after, and no straight line can have a disk on one side of it and a whole ring around that disk on the other. The network is not being slow. It is attempting something that cannot be done, and the plateaued loss curve is the honest report.

The creasing bends slip out of that argument, and still do not help. relu folds the plane — a continuous map, but not a reversible one — and a fold can perfectly well bring an inside out. What stops it here is duller than topology: two units give the layer two creases, and you cannot enclose a bounded region with two straight cuts. You need three to make a triangle. Switch the activation and watch it fail the other way.

Then you gave it one more dimension, and the impossible became easy. With three hidden units the deformation can lift — raise the inner disk out of the page like a tent pole under a napkin — and in three dimensions a flat plane slides between them cleanly. This is the picture Christopher Olah's essay is famous for1 , and it generalizes: data tangled like linked rings or knotted strings needs room — extra dimensions — to be taken apart, and a network needs enough width to provide that room.

Now the thesis of this whole book, stated in full. The network is a smooth, continuous transformation — that is all it is allowed to be, because gradient descent can only search by feel, and feel requires differentiability. The data arrived tangled by some process in the world. Learning succeeds when the network discovers a smooth map that undoes the tangle — approximately inverts it — so that in the new coordinates the classes are linearly separable. When no such smooth un-tangling exists in the space it has, the network fails, honestly and legibly, the way it just did. Width and depth are not magic: they are degrees of freedom for the deformation.

That the data arrives tangled rather than merely scattered is itself a supposition, and it has a name. The manifold hypothesis holds that data of enormous nominal size — a photograph with a million pixels — in fact lies on or near a surface of far smaller dimension, because whatever generated it had far fewer knobs than it has pixels.2 Everything in this chapter assumes it. So does most of the field.

Plate III The playground — pick your tangle
waking the network… it trains right here, on your machine — nothing leaves this page
Seven tangles, easiest to hardest, under the plot — spirals are the classic stress test. Watch the hidden view: tanh bends space in soft waves; relu folds it along straight creases; gelu and silu fold with the crease sanded smooth. Hover the hidden view and press unfold to replay the deformation. Widths beyond three are shown as a PCA shadow — the true untangling happens in more dimensions than a screen has, and the plane drawn through it is where the classifier’s one straight cut crosses the three directions being shown, not the cut itself.

The representation is the product

Click any point on the left and find its ghost on the right: the same datum, renamed by the network. That renaming is the product. We call the hidden layer's coordinates a representation — a coordinate system invented by training, in which the problem is trivial. The classifier at the end is almost an afterthought.3

You can measure this rather than admire it. Hang a bare linear classifier off each hidden layer of a trained network and score it: separability climbs layer by layer, and the climb is what this page has been drawing.4 Or count the holes. Take data shaped like two interlocked surfaces, push it through a trained network, and measure the topology of what comes out at every layer — the holes close one after another, until by the last hidden layer the two classes are two plain blobs. Networks with a folding bend get there in fewer layers than smooth ones, and the reason is the one the creases already gave: a fold is not reversible, and closing a hole is not something a reversible map can do.5

Every chapter from here is this chapter wearing different clothes. Handwritten digits live in a 784-dimensional input space — one axis per pixel — and a classifier must deform that space until ten regions come apart (Chapter 3). An autoencoder will squeeze the deformation through a two-dimensional bottleneck and hand us the map to look at (Chapter 4). Even the language model of Chapter 5 is moving words around a space until the next token sits in a predictable place. The grid you just watched bend is the only mental image you need.

Sources

  1. 1 Neural Networks, Manifolds, and Topology Olah · 2014 · Essay · colah.github.io The essay that made the rubber-sheet picture stick, and the source of the tangled-rings example this chapter runs live.
  2. 2 Testing the Manifold Hypothesis Fefferman, Mitter & Narayanan · 2016 · Journal of the AMS 29(4) · arXiv:1310.0425 The supposition that real data of very high dimension lies close to a surface of far lower dimension, treated for once as a claim that can be tested rather than assumed.
  3. 3 Representation Learning: A Review and New Perspectives Bengio, Courville & Vincent · 2013 · IEEE TPAMI 35(8) · arXiv:1206.5538 The case, made before it was obvious, that the useful output of a deep network is the coordinates it invents rather than the answer it prints.
  4. 4 Understanding intermediate layers using linear classifier probes Alain & Bengio · 2016 · ICLR 2017 workshop · arXiv:1610.01644 Hang a bare linear classifier off each hidden layer and see how well it does. Separability rises layer by layer, which is the untangling of this chapter measured in a number.
  5. 5 Topology of deep neural networks Naitzat, Zhitnikov & Lim · 2020 · JMLR 21 · arXiv:2004.06093 Measures the holes in the data — literally, by counting them — at every layer of a trained network, and watches them close. Networks with a folding bend simplify the topology far faster than smooth ones.