Multilayer Perceptron
Multilayer Perceptron — Stack neurons into layers to learn nonlinear boundaries.
Stack neurons into layers and a network can carve any boundary at all. The multilayer perceptron is the workhorse feedforward network — the thing “deep learning” scaled up.
- Class 0
- Class 1
- First-layer neuron lines
MLP controls
The idea in plain words
Stack neurons into layers and a network can carve any boundary at all. Each hidden neuron learns its own line; together they combine into a complex curved boundary that a single perceptron never could — solving circles, XOR, even spirals.
Watch the boundary reshape as the network trains, and click a first-layer neuron to see the line it learned. Too few neurons can’t bend enough to separate a hard dataset; the loss curve stalls high.
Now, the math
An MLP composes layers of nonlinear transformations:
- the nonlinear activation — what makes stacking meaningful.
- the weight matrices of the hidden and output layers.
▸ Show the derivation
The universal approximation theorem says a single hidden layer with enough neurons can approximate any continuous function — but “enough” can be huge. Extra depth lets the network build features hierarchically, solving hard shapes like the spiral with far fewer neurons per layer. It’s trained by backpropagation.
Trace it by hand
One fixed 2-2-1 network, ReLU hidden layer, sigmoid output, evaluated at two inputs. Hidden weights: both rows (1, 1) with biases -0.5 and -1.5, so the two hidden neurons share a direction but fire at different thresholds. Output weights (6, -16), bias -2. Outputs rounded to 4 decimal places, computed with the repo's MLP core.
Hidden layer for the input (1, 0)
Both hidden neurons measure the same quantity x1 plus x2, but only the low-threshold neuron fires here.
Output for (1, 0)
Above 0.5, so the point (1, 0) is classified as class 1.
Hidden layer for the input (1, 1)
Moving further along the same diagonal wakes the second, high-threshold neuron — and its output weight is strongly negative.
Output for (1, 1) lands on the other side
Below 0.5: class 0. The second neuron's -16 weight overpowers the first, folding the boundary back.
The full picture is XOR-shaped
So the four corners score 0.12, 0.73, 0.73, 0.27 — low, high, high, low. No single straight line can produce that pattern.
What just happened: Two hidden neurons watching the same direction with different thresholds let the output layer subtract one stripe from another: (1, 0) scores 0.7311 while (1, 1), further along the very same diagonal, scores 0.2689 — a bent, XOR-solving boundary no single perceptron can draw.
Now Break It
Try this: Too few hidden units can’t bend enough to separate a spiral; too many overfit the noise.
Control: Hidden units slider (set to 1)
What happens: Not enough capacity! With one hidden unit the network can only draw a line — it can’t separate the spiral.
Where multilayer perceptron is used
The multilayer perceptron (MLP) stacks neurons into successive layers so that hidden layers learn intermediate features and the whole network can carve nonlinear decision boundaries that a single neuron never could. This architecture is the foundation of practical deep learning: the universal approximation theorem shows that an MLP with even one sufficiently wide hidden layer can approximate any continuous function to arbitrary precision. MLPs classify handwritten digits, estimate house prices, detect fraud, and appear as the feed-forward blocks inside transformers that power modern language models. Once researchers paired the multilayer structure with backpropagation in the 1980s, the layered network stopped being a curiosity and became the engine behind a huge share of applied machine learning.
A common misconception is that the universal approximation theorem means a shallow MLP is always enough; in practice a single hidden layer might need an impractically enormous number of neurons, whereas adding depth lets the network reuse features and learn the same function far more efficiently. Another pitfall is forgetting that the hidden layers must use nonlinear activations, because without them the multilayer structure collapses back into a plain linear model regardless of how many layers you stack. Beginners also overbuild, assuming more layers always help, but excessively deep or wide MLPs overfit small datasets and can be harder to train without regularization, normalization, and enough data.
Frequently asked questions
What is a multilayer perceptron?
How is an MLP different from a single perceptron?
What is a hidden layer?
What is the universal approximation theorem?
Why use deep networks instead of one wide layer?
How does an MLP make a prediction?
Written & reviewed by the ML Visualization team · Last updated .