One hidden layer, one nonlinearity, and the wall the perceptron hit falls down.
The escape from XOR — depth plus nonlinearity, trained by the chain rule run backward.
Existence, not a recipe — but it settled the question Minsky and Papert raised.
A perceptron computes one weighted sum: one line. A hidden layer computes several at once, and the output layer draws a line through those — a bent shape back in the original space.
The nonlinearity is not optional. Two stacked linear layers collapse into one line (a product of matrices is a matrix). The tanh in the middle breaks the collapse. Depth without nonlinearity buys nothing; depth with it buys everything.
The hidden layer learns a new set of coordinates where the problem is linearly separable, then separates it there.
Two interleaving crescents, 200 points, no straight line comes close.
Forward: two linear layers, a tanh between, a sigmoid on top.
Z1=XW1+b1A1=tanh(Z1)y^=σ(A1W2+b2)Loss: binary cross-entropy — the output unit is a logistic unit.
L=−N1i∑[yilogy^i+(1−yi)log(1−y^i)]Backprop: the chain rule, output first, then push back through the weights.
δ2=y^−yδ1=(δ2W2⊤)⊙(1−A12)Step downhill and repeat.
W←W−η∂W∂LRandom line → kink → bend → a curve wrapping the crescents. Real weights per frame; loss falling underneath.
Epoch 0 is a badly-placed straight cut. By the end: a curve a single line could never draw, train accuracy ~0.96, loss ~0.07.
The network carves an X — two bent lines — through the four points. Exactly the shape XOR needs and a perceptron cannot make.
XOR: both hit 1.0 — the perceptron scored 0.5. The layer unlocked it. Moons (60 test points): scratch 0.983, sklearn 0.867.
Ours fits harder (full-batch, 4000 epochs); sklearn regularizes and early-stops. Both draw a curve — they just draw slightly different ones. That's nonconvexity.