Multi-Layer Perceptron (MLP)
Depth turns one boundary into infinitely many curves
An MLP stacks layers of neurons with nonlinear activations, allowing curved decision boundaries. With one hidden layer it already universal-approximates; adding depth trades efficiency for expressiveness.
What you will learn
- Describe the anatomy of an MLP and how layers combine
- Explain why one hidden layer already gives universal approximation
- Estimate parameter counts and capacity trade-offs
What is this?
A Multi-Layer Perceptron is several perceptron-style layers chained (input → hidden → hidden → output), each with a nonlinear activation between linear transforms. Because each nonlinear layer re-shapes the input space, the final layer sees a transformed representation where even XOR is linearly separable. One hidden layer can approximate any continuous function; depth primarily makes it efficient and learnable to fit.
Why do you need it?
- MLPs solve the perceptron's XOR blind spot by adding only one middle layer.
- They're the backbone of tabular deep models and the head on top of CNNs/transformers.
- Parameter math is simple — you can predict capacity before training.
- Every deeper model your career touches has an MLP at its output stage.
Mental model
A team of translators, each relaying in a new language
An MLP's hidden layers
The input arrives in raw coordinates; the first translator rewrites it, the second rewrites again, and by the output layer the meaning (class) has been re-expressed in a form the final judge can easily read off.
How it works
- Layer 1: z1 = X·W1 + b1, then h1 = activation(z1), producing internal features.
- Layer 2 (and more): repeat; hidden layers re-map the input toward separability.
- Output layer: one linear map per class (logits), then softmax/sigmoid to probabilities.
- Parameters: (in·h1 + h1) + (h1·h2 + h2) + ... — width grows the count fastest.
- Training via backprop adjusts all weights to minimize the final loss end-to-end.
An MLP with one hidden layer.
In production
- Tabular classifiers where gradient models (GBDT) fail: multi-class heads, embeddings, mixed features.
- Any classifier/regressor as the readout head on CNN/transformer embeddings.
- Small serveable models on edge/MCU-class devices with 1-2 hidden layers.
Best practices
- Normalize inputs (standard scaling) and use reasonable init within each layer.
- Start with one hidden layer at moderate width; add depth/width only when validation demands it.
- Use softmax/CE for classification, identity/MSE for regression, matching activation to loss.
- Regularize (weight decay, dropout) once width exceeds data size.
Common mistakes
- Making hidden layers deeper than data warrants — an overparameterized curve-fit on small tables.
- No normalization: MLPs are notorious for punishing unscaled, huge-magnitude features.
- Treating width as the only dial and ignoring LR/regularization — capacity isn't free.
- Reading validation accuracy as proof of generalization when the test set was reused for tuning.
Common issues
MLP does no better than logistic regression despite hours of tuningData too small or too noisy, or features not normalized
Normalize/scale features, add regularization; be honest that shallow models may own the tabular baseline.
Sigmoid-heavy MLP gets stuck around 0.5 confidenceSaturated hidden activations from deep chain + no normalization
Switch to ReLU hidden layers with proper init and batchnorm/layernorm.
Validation accuracy spikes and crashes between runsUncontrolled seed/shuffle with small data
Fix seeds, cross-validate, and average results over a few random restarts.
Debugging tips
- Check the first layer's weight/activation scale after a few steps using a printout — normalization holds clues.
- Overfit one batch to double-check plumbing, then introduce the full set.
- Compare against the single-perceptron baseline; if no better, the MLP is overfitting or starved for data.
- Count parameters vs samples; if params >> rows, expect training-time memorization on the val curve.
Interview checkpoint
Quick quiz
Where does an MLP's power over a single perceptron come from?
An MLP with one hidden layer can approximate any continuous function with enough units.