A multilayer perceptron bends space until the answer is a straight line

One neuron can only draw a line. Stacking them lets the network redraw the map first.

A single artificial neuron does two things: take a weighted sum of its inputs, then squash that sum through a curve. Weighted sum alone is just a line — such a neuron can only split the world into two halves with a straight cut, which is why the perceptron famously choked on XOR.

The fix is embarrassingly simple: put a layer of neurons in between. Each hidden neuron draws its own line; the next layer takes their outputs as new coordinates and draws a line in that space. Geometrically, the hidden layer warps and folds the input space until the two classes can be separated by something flat.

That's the whole idea. Everything else — depth, activations, backprop — is machinery for making the warping learnable. With enough hidden units, an MLP can approximate any continuous function, which is the universal approximation theorem.

Graph 1 · Anatomy

input hidden layer 1 hidden layer 2 output

Every neuron computes the same thing: output = squash( w₁x₁ + w₂x₂ + … + bias )

Fully connected — every neuron sees every neuron of the previous layer. The squash (tanh, ReLU) is what makes depth worth having: without it, stacking linear layers collapses back into a single linear layer, no matter how many you use.

Graph 2 · Watch one learn

Two inputs (x, y), one output (which colour). The background shows the network's current prediction everywhere. Start with 0 hidden layers on XOR or spiral — it can only manage a single straight cut and stalls near 50%. Add one hidden layer and the boundary starts to curve.

class A class B shading = network confidence
epoch 0 loss – accuracy –
data
depth
width
squash

Training loss. Backprop nudges every weight in the direction that lowers it.

Graph 3 · What the hidden units actually learned

Each tile is one neuron of the first hidden layer, showing where it fires across the input space. Every tile is a straight-edged half-plane — that's all a single neuron can be. The next layer adds and subtracts these slabs, and their overlap is the curved boundary above. Complexity is built from very dumb parts.

Train the network above and watch the tiles rotate into position. With ReLU the edges are hard creases; with tanh they're soft ramps.

How it learns: backprop

  1. Forward: push an example through, get a prediction.
  2. Compare: measure the error against the true label.
  3. Backward: use the chain rule to ask every weight "how much of this error is yours?"
  4. Nudge: move each weight a small step against its share. Repeat a few thousand times.

What to remember

Width buys you more folds; depth lets folds compose, so deep-and-narrow usually beats shallow-and-wide for the same parameter count.

The MLP is still the workhorse layer inside almost everything modern — roughly two-thirds of a Transformer's parameters sit in plain feed-forward MLP blocks between the attention layers.