What Networks Can Represent
Universal approximation, width versus depth, and what representing is not.
A network with enough neurons can trace any continuous curve as closely as you like. That is a theorem, and in one dimension you can prove it with a pencil. The interesting questions start right after it: how many neurons, arranged how deep, and why a network that can represent a function may still never learn it.
What you’ll learn
- Prove universal approximation in one dimension by building a ReLU network from hat functions, with the error bound for a -Lipschitz target, and state the general theorems of Cybenko, Hornik and Leshno et al.
- Count linear pieces: at most for one hidden layer of ReLUs on a line and at most for such layers, and use the sawtooth to show that depth can be exponentially cheaper than width.
- State the minimal width at which deep narrow ReLU networks become universal, and what counts of linear regions say about networks in higher dimension.
- Separate three questions that are often confused (do good weights exist, does training find them, do the data pin them down) and explain inductive bias as the set of functions an architecture makes cheap.
Any curve from hat functions
The universal approximation question asks: for which activation functions can a network with one hidden layer approximate every continuous function on a bounded region, to any accuracy, given enough units? Neurons, Layers & Activations showed that one hidden layer of ReLUs computes any continuous piecewise-linear function of one variable. Approximation is then one step away: replace by the piecewise-linear function that agrees with it on a grid.
Let be -Lipschitz: . Cut into equal pieces with knots , , and build the interpolant from hat functions centered on the knots:
Each is a tent of height 1 at that falls to 0 at the neighboring knots, so and is linear between knots. Neighboring hats share their kinks, so the whole sum needs only ReLUs on . With the slope of on the piece and :
On the piece write with . Then is the weighted average , and the Lipschitz bound applies to each part. The worst point is the middle of a piece, :
For a merely continuous the same average gives , where is the modulus of continuity of ; it tends to with because is uniformly continuous on . That proves universal approximation for ReLU networks in one dimension. For a twice-differentiable the classical interpolation bound is sharper: halving quarters the error.
You approximate on by its piecewise-linear interpolant. Using and the bound , how many equal pieces guarantee an error of at most ?
Show the answer
23 pieces
You need , so : 23 pieces, which is 23 ReLUs. The Lipschitz bound with would ask for , so smoothness buys a lot. The bound is nearly tight: at the true error is against a bound of .
Polynomials fail for a simple reason: with every unit is a polynomial of degree in , and so is any sum of them, so no number of units escapes the polynomials of degree . Every non-polynomial activation works, which is why expressivity is not the reason to choose one activation over another (Activation Functions in Depth).
The theorems are existence results. They do not say how many units are needed, and in dimensions the grid idea is expensive: a grid of spacing has cells. For a general Lipschitz function on the number of parameters needed for accuracy grows exponentially with , about up to logarithmic factors even for the deepest ReLU networks (Yarotsky, 2018). This curse of dimensionality lifts only for special classes. For functions of finite Barron norm, one hidden layer of sigmoidal units reaches squared error in any dimension (Barron, 1993).
Counting pieces: width versus depth
One hidden layer suffices, given enough units. Depth earns its place through economy, and in one dimension you can see why by counting linear pieces.
Feed a scalar into a layer of ReLUs whose inputs are piecewise linear in with pieces. On each piece every pre-activation is affine in , so each ReLU can add at most one breakpoint per piece, new breakpoints in all:
The input itself has one piece. So one hidden layer of units gives at most pieces (its output layer is affine and adds none), and hidden layers of width give at most . Adding units adds pieces; composing layers multiplies them.
Composition can actually reach exponential growth. The tent map maps onto itself twice, up and back down. Composing it folds the interval again and again, and at the grid points the values alternate between 0 and 1:
A deep network computes exactly with units in layers of width 2. One hidden layer needs at least units to compute it exactly, and at least even to approximate it within . If , then is below at even grid points and above at odd ones. A linear piece of containing three consecutive grid points would have to rise and then fall, so each piece holds at most two of the grid points:
How many linear pieces does , the tent map composed 10 times, have on ?
Show the answer
1024 pieces
Each composition doubles the pieces: . A deep network computes it with 20 ReLUs in 10 layers of width 2. A single hidden layer needs at least 1,023 units to compute it exactly, one per breakpoint, and at least 512 to stay within of it everywhere.
This is the simplest depth separation. Telgarsky (2016) made it general: for every there are networks with layers of constant width that any network with layers can approximate only with units. Composition also helps with smooth functions. On , , so stopping the sum after terms approximates within using layers (Yarotsky, 2017). Then gives products, and products give polynomials. That construction is the approximation engine of Deep Networks as Statistical Estimators.
In dimensions the pieces become convex polytopes, the linear regions. One hidden layer of ReLUs cuts with hyperplanes, which makes at most regions, a polynomial of degree in . With layers of width , Montúfar, Pascanu, Cho & Bengio (2014) constructed networks with regions, exponential in depth. Typical networks are far more modest. Hanin & Rolnick (2019) proved that at initialization the average number of regions in a fixed input region is bounded by roughly the total number of neurons raised to the input dimension, independently of depth, and found the bound tight during training as well. The maximum shows what depth can do, not what training does.
How narrow can a deep network be?
Turn the classical theorem around: fix the width and let the depth grow without limit. Is a very deep, very narrow ReLU network universal? Only above a threshold width, and the threshold is now known almost exactly:
| Setting | Result | Source |
|---|---|---|
| one hidden layer of any width; any non-polynomial activation | universal, uniformly on compact sets | Leshno et al. (1993) |
| ReLU, every hidden layer of width , any depth | not universal for continuous | Hanin & Sellke (2017) |
| ReLU, width , unbounded depth | universal for continuous , uniformly; width suffices for vector outputs | Hanin & Sellke (2017) |
| ReLU, width , unbounded depth | universal for integrable functions on in ; width is not | Lu, Pu, Wang, Hu & Wang (2017) |
| ReLU, approximation in , | minimal width exactly | Park, Yun, Lee & Shin (2021) |
A ReLU network maps inputs in to a scalar, and every hidden layer has the same width . Which statement about making it arbitrarily deep is correct?
- Width suffices: depth can make up for anything once the width matches the input
- No constant width suffices; the width must grow as the accuracy improves
- Width suffices to approximate every continuous function uniformly, given enough depth
- Width suffices, since a deep enough chain of single ReLUs can bend any way it likes
Show the answer
C. Width suffices to approximate every continuous function uniformly, given enough depth
The minimal width for uniform approximation of continuous scalar functions on is exactly (Hanin & Sellke, 2017). Below it, depth does not help.
Representing is not learning
A universal approximation theorem answers the first of three questions, and the other two are harder:
- Existence. Do weights exist that approximate the target? For a continuous target and enough units, yes.
- Optimization. Will training find them? Nothing guarantees it. Deciding whether a network of just three threshold units can fit a given labeled dataset is NP-complete (Blum & Rivest, 1992), and gradient descent on a nonconvex loss promises only to go downhill.
- Generalization. Do the training data single out weights that work on new data? A network that fits points can usually fit the same points with random labels, so a good fit proves nothing by itself (The Generalization Puzzle).
Counting parameters against data points is therefore a weak guide in both directions. Image classifiers with tens of millions of parameters are trained on ImageNet's 1.28 million images and still generalize, and the curve above shows that the worst place to be is often where parameters and data points balance. Among the many functions that fit the data, which one training returns is decided by the architecture, the optimizer and the data. Much of the rest of this course is about that choice.
Inductive bias: what is cheap to represent
If nearly every architecture is universal, why does the choice matter so much? Universality is about unlimited resources; learning happens with a fixed budget of parameters, data and compute. An architecture's inductive bias is the set of functions it makes cheap: representable with few parameters, and easy for gradient descent to reach from few examples.
| Architecture | Structure built in | Functions it makes cheap |
|---|---|---|
| multilayer perceptron | composition of layers, nothing about the input's layout | compositions of simple pieces; low frequencies before high ones (Spectral Bias & Fourier Features) |
| convolutional network | locality and weight sharing across positions | translation-equivariant maps of images and audio, built from local patterns (Convolutional Networks & Vision) |
| recurrent network, state space model | one update rule applied at every time step | functions of sequences of any length that summarize the past in a fixed-size state (Recurrent Networks & Sequence Models) |
| transformer | attention: interactions between positions weighted by content | functions in which any token may depend on any other, selected by content (Transformers) |
| graph neural network | aggregation over neighbors with shared weights | functions of graphs that ignore how the nodes are numbered (Graph Neural Networks) |
An MLP and a convolutional network are both universal approximators. What does choosing the convolutional network for images actually buy?
- The ability to represent functions of images that no MLP can represent
- A guarantee that the trained network generalizes
- Nothing in principle; only the training speed differs
- Translation-respecting functions become cheap: few parameters and learnable from far fewer examples
Show the answer
D. Translation-respecting functions become cheap: few parameters and learnable from far fewer examples
Both can represent the same functions given enough units. Weight sharing and locality make the functions images need cost few parameters and few examples, and those costs, not representability, decide what training finds with a fixed budget.
Key takeaways
- One hidden layer approximates any continuous function on a compact set exactly when the activation is not a polynomial. In one dimension, ReLUs interpolating on a grid give error at most for a -Lipschitz target.
- Adding units adds linear pieces and composing layers multiplies them: one layer of ReLUs makes at most pieces on a line, layers at most . The tent map composed times takes units in depth but at least in one layer, even to approximate.
- Deep narrow ReLU networks are universal exactly when their width exceeds the input dimension: for continuous scalar functions.
- Existence of good weights, finding them, and generalizing from data are separate questions. Parities are easy to represent but hard for gradient descent, and a network that interpolates its data can still predict badly.
- Architectures differ less in what they can represent than in what they make cheap. That inductive bias is why convolution, recurrence, attention and message passing exist.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
You approximate a 3-Lipschitz function on by its piecewise-linear interpolant on equal pieces. What is the smallest for which the bound guarantees an error of at most ?
Show the answer
B.
gives , so 150 ReLUs. The factor comes from the worst point being in the middle of a piece, where both knots are away.
A ReLU network on a scalar input has four hidden layers of 3 units each. By the counting argument, what is the largest number of linear pieces its output can have?
Show the answer
D.
Each layer of units multiplies the number of pieces by at most , so four layers give at most . A single hidden layer with the same 12 units makes at most 13.
With which activation can networks with one hidden layer not approximate every continuous function on , however wide they are?
- ReLU
- tanh
Show the answer
C.
By Leshno et al. (1993), a locally bounded, piecewise continuous activation gives universal approximation exactly when it is not a polynomial. With , every unit and every sum of units is a polynomial of degree at most 3.
A network with one hidden layer of width can represent the parity of any subset of input bits, yet gradient training on a random parity makes no progress for . Why?
- The gradient is almost the same whichever parity is the target, so it carries almost no information about which one it is
- The network only approximates parities, and the approximation error swamps the signal
- At the network has too few parameters to store the answer
- The network overfits the training set before it can find the parity
Show the answer
A. The gradient is almost the same whichever parity is the target, so it carries almost no information about which one it is
Shalev-Shwartz, Shamir & Shammah (2017) showed that the gradient's variance over the possible parities is at most . Expressivity is not the problem; the training signal is.
Deep ReLU networks of constant width approximate continuous functions in the uniform norm, with unlimited depth. What is the smallest width that works?
Show the answer
C.
Hanin and Sellke (2017) showed the minimal width is exactly : width 11 suffices with enough depth, and width 10 fails at any depth.
Go deeper
- Memorization Capacity · How many parameters it takes to fit any n labels, and why that is fewer than you think.
- Spectral Bias & Fourier Features · Why networks learn low frequencies first, and how coordinate networks get around it.
- Deep Networks as Statistical Estimators · Minimax rates, compositional structure and when depth helps statistically.
Further reading
- S. J. D. Prince, Understanding Deep Learning (MIT Press, 2023), ch. 3 "Shallow neural networks" and ch. 4 "Deep neural networks".
- M. Leshno, V. Y. Lin, A. Pinkus & S. Schocken, "Multilayer feedforward networks with a nonpolynomial activation function can approximate any function," Neural Networks 6(6) (1993).
- M. Telgarsky, "Benefits of depth in neural networks," COLT (2016).
- B. Hanin & M. Sellke, "Approximating continuous functions by ReLU nets of minimal width," arXiv:1710.11278 (2017).
- S. Shalev-Shwartz, O. Shamir & S. Shammah, "Failures of gradient-based deep learning," ICML (2017).