The Geometry of Neural Networks
Explore space folding, network training, and gradient propagation, starting with perceptrons and ReLU.
A single neuron draws one straight cut
predicts circle and otherwise diamond, separated by a straight line. Each perceptron step picks one misclassified point and nudges toward it. Two separable clusters converge quickly; XOR or a center band never does. Adding a third coordinate ( or ) lets the exact same rule converge again.
The arrow is , perpendicular to the boundary and pointing toward the circle class.
Circle: class 1Diamond: class 0; ringed points are misclassified
Each layer folds the space in half again
Follow both geometry and numbers through every layer: nonlinear activations fold or bend the 2D coordinate grid so scattered same-class points converge to the same side, letting the final linear layer separate them with one straight cut.
A trained ReLU network partitions the plane into regions
Each thin line is a hidden neuron's crease (where its pre-activation equals 0). The creases partition the plane into cells where the network score is affine, and the thick line is the final decision boundary. First-layer creases are straight lines; second-layer creases bend wherever they cross first-layer creases.
- Shape
- 2 → 8 → 1
- Params
- 33
- Steps
- 0
- Loss
- 0.730
- Train acc.
- 48%
73×73 grid sampled 28 activation patterns; a single hidden layer of 8 units can cut at most 37 planar regions. Grid sampling can miss tiny regions, and distinct patterns may still share the same output.
CircleDiamond
Why divide dot products by
When entries of and are drawn independently from , the variance of is . In high dimensions, scores spread far apart, softmax puts nearly all mass on the largest score, and gradients through the weights vanish. Dividing by restores unit variance; temperature acts the same way via .
- Score std dev
- 0.78 expected single-score std dev: 1
- Max weight
- 0.294
- Entropy
- 2.62 bits uniform = 3
- 0.372
Residual connections preserve a direct gradient path
During backprop, gradients multiply by each layer's Jacobian, which can shrink or explode across many layers. Adding a residual skip turns the Jacobian into : the identity term offers a direct path, though branch terms can still cancel or amplify. Scaling each branch by improves scale in this fixed demo, without guaranteeing stability for every network.
Reading notes & further questions
Companion interactive experiments for Why Neural Networks Need Depth:
- Single-neuron linear boundary and feature lifting for XOR.
- ReLU depth folding, two-spiral linear regions, √dₖ attention scaling, and residual gradient propagation.