Chapter 09 · Learning theory
Why does it work on data it has never seen?
Memorizing the examples is easy; getting unseen ones right is not. Learning theory studies when and why a model trained on some data generalizes to other data. Its classical theorems are elegant… and deep networks defy them.
In this chapter
A student who memorizes last year's exam answers scores full marks on that exam and fails this year's. The same happens with machines: what matters is not the error on the training data but on new data. That ability is called generalization, and it is the property that distinguishes learning from memorizing.
Empirical risk and true risk
Suppose the examples come from an unknown distribution . For a model (or hypothesis) chosen from a class and a loss function , there are two errors:
The true risk is what we care about, but we cannot compute it. The empirical risk is what we measure on the data. Training is almost always empirical risk minimization, a principle Vladimir Vapnik placed at the centre of the theory. The question is when a small guarantees a small .
The figure illustrates the bias–variance decomposition (Geman, Bienenstock and Doursat, 1992). For squared loss, the expected error at a new point splits into three terms:
Simple models have high bias and low variance; complex ones, the reverse. Classical wisdom says to look for the sweet spot in between.
PAC learning
In 1984 Leslie Valiant gave a formal definition of “learning” with a deliberately modest name: probably approximately correct (PAC). We do not demand always being right; it is enough that, with high probability over the sample, the model has small error.
A class is learnable if there is an algorithm and a function such that, for every distribution and all , with examples the algorithm returns with
For a finite class, the answer comes from combining two classic tools.
If is finite and the loss takes values in , then with probability at least over the sample, for every simultaneously,
Proof
For a fixed , is the mean of independent variables in with expectation . Hoeffding's inequality (1963) says that : the law of large numbers with an exponential rate. By the union bound, the probability that some of the hypotheses deviates is at most . Setting it equal to and solving for gives the bound.
The bound captures the intuition of Occam's razor: the price of choosing among many hypotheses grows with , roughly the number of bits needed to describe the chosen hypothesis. More data compensates for it as .
The VC dimension
The interesting classes are infinite: there are infinitely many lines in the plane. In 1971 Vladimir Vapnik and Alexey Chervonenkis found the right measure of their capacity. A class is said to shatter a set of points if it can produce every possible labelling of them.
The VC dimension of is the largest such that some set of points is shattered by . If sets of every size can be shattered, it is infinite.
For binary classification, is PAC-learnable if and only if its VC dimension is finite. In that case the number of examples needed is
and empirical risk minimization is an algorithm that achieves it.
This result, built by Vapnik and Chervonenkis (1971) and Blumer, Ehrenfeucht, Haussler and Warmuth (1989), is one of the peaks of the theory: it reduces the question “can this be learned?” to a combinatorial number. In the 1990s it inspired support vector machines (Boser, Guyon and Vapnik, 1992; Cortes and Vapnik, 1995), which maximize the margin to control capacity and were the star method before deep learning.
No free lunch
Averaged over all possible target functions, every learning algorithm has the same mean error outside the training sample. No method beats another on every problem.
Generalizing requires assuming something about the world, an inductive bias. Convolutions assume that what matters in an image does not depend on its position. Attention assumes that any word can depend on any other, with a weight computed from the content. Choosing the architecture is, to a large extent, choosing the right assumptions.
The mystery of deep networks
In 2017 Chiyuan Zhang and his colleagues ran a devastating experiment: they trained standard vision networks on images whose labels had been randomly shuffled. The networks memorized them perfectly. Their capacity is therefore enough to fit anything, so VC-based bounds are useless for them: they predict errors above 100%. And yet, with the true labels, those same networks generalize beautifully.
Belkin and his colleagues (2019) also documented double descent: if model size is increased beyond the point where it fits the data perfectly, the test error, which had got worse following the classic U-shaped curve, goes down again. LLMs live far to the right of that curve.
There is still no complete theory of why overparameterized networks generalize. The candidate explanations are the implicit regularization of stochastic gradient descent (which tends towards “simple” or small-norm solutions), a preference for flat minima, PAC-Bayes bounds (which do give non-trivial guarantees in some cases) and the structure of real-world data itself.
With the right data, architecture and optimization algorithm, generalization arrives. For language, the architecture that changed everything appeared in 2017.
References
- V. N. Vapnik and A. Y. Chervonenkis (1971). “On the Uniform Convergence of Relative Frequencies of Events to Their Probabilities”. Theory of Probability and Its Applications, 16(2).
- W. Hoeffding (1963). “Probability Inequalities for Sums of Bounded Random Variables”. JASA, 58(301).
- L. G. Valiant (1984). “A Theory of the Learnable”. Communications of the ACM, 27(11).
- A. Blumer, A. Ehrenfeucht, D. Haussler and M. K. Warmuth (1989). “Learnability and the Vapnik-Chervonenkis Dimension”. Journal of the ACM, 36(4).
- S. Geman, E. Bienenstock and R. Doursat (1992). “Neural Networks and the Bias/Variance Dilemma”. Neural Computation, 4(1).
- D. H. Wolpert (1996). “The Lack of A Priori Distinctions Between Learning Algorithms”. Neural Computation, 8(7).
- C. Zhang, S. Bengio, M. Hardt, B. Recht and O. Vinyals (2017). “Understanding Deep Learning Requires Rethinking Generalization”. ICLR.
- M. Belkin, D. Hsu, S. Ma and S. Mandal (2019). “Reconciling modern machine-learning practice and the classical bias-variance trade-off”. PNAS, 116(32).
- S. Shalev-Shwartz and S. Ben-David (2014). Understanding Machine Learning: From Theory to Algorithms. Cambridge University Press.