Stability, Compression & PAC-Bayes
Other roads to generalization guarantees.
Uniform convergence demands that every hypothesis in a class behave, including the many your algorithm would never output. Three other routes ask less: that the algorithm not lean too hard on any single example, that its output be rebuilt from a handful of examples, or that it stay close to a distribution chosen before seeing the data. The last of these produced the first nonvacuous generalization bounds for deep networks.
What you’ll learn
- Define uniform stability, prove that it controls the expected generalization gap, and state the high-probability bounds of Bousquet and Elisseeff and their sharper successors.
- Apply stability to regularized ERM and to SGD, and explain what "train faster, generalize better" does and does not mean.
- Derive the sample-compression bound, and state what is known about compressing VC classes.
- Prove a PAC-Bayes bound by the change-of-measure inequality, state its kl form, and explain how optimizing it gave nonvacuous bounds for deep networks.
Stability: no single example matters much
Uniform convergence controls every hypothesis in the class. Algorithmic stability looks only at the algorithm: if removing or replacing one training example barely changes what it learns, it cannot have memorized that example, so its training error cannot be much more optimistic than its test error. Throughout, losses take values in and denotes the hypothesis the algorithm returns on the sample .
Let be a fresh example and the sample with replaced by . The pairs and have the same distribution, so for every
Average over and subtract the expected training error (Shalev-Shwartz & Ben-David 2014, Theorem 13.2):
Each term compares the loss on of a model that never saw with one trained on it: the gap is an average sensitivity to individual examples. If replacing one example never moves any loss by more than (Hardt, Recht & Singer 2016, Theorem 2.2):
An algorithm has uniform stability with , loss in () and . How large is the Bousquet–Elisseeff gap term ?
Show the answer
0.061
and , so the gap is : five times the Hoeffding term of a single fixed hypothesis. With the same formula gives , vacuous. That overhead is what the newer bounds remove.
Which algorithms are stable?
The mechanism is strong convexity: the regularized objective is -strongly convex, so changing one of its terms can move the minimizer only by . The soft-margin SVM (hinge loss, ) and kernel ridge regression with bounded responses are covered. The same argument gives for -Lipschitz convex losses with penalty (Shalev-Shwartz & Ben-David 2014, Corollary 13.6). Stronger regularization buys stability with bias, the bias–variance trade-off in another guise.
Hence the slogan "train faster, generalize better": in the convex case the gap is bounded by the sum of the step sizes, , so fewer and smaller steps generalize better, and combining this with the optimization error gives early stopping a theory. The limits are as instructive. The nonconvex bound grows almost linearly in , and every uniform stability bound is blind to the labels, as Zhang, Bengio, Hardt, Recht & Vinyals (2017) pointed out: the same algorithm run on random labels has the same stability guarantee, while its true gap there is huge (about 90% for ten balanced classes). In the general learning setting, by contrast, stability is exactly the right notion: Shalev-Shwartz, Shamir, Srebro & Sridharan (2010) exhibited problems that are learnable although uniform convergence fails and ERM does not work, and identified stability as the condition necessary and sufficient for learnability there.
Which statement about the convex SGD bound is correct?
- It guarantees that SGD reaches low test error
- It improves the longer SGD runs
- It bounds the expected generalization gap, grows with the total step size, and does not depend on the labels
- It needs the loss to be strongly convex
Show the answer
C. It bounds the expected generalization gap, grows with the total step size, and does not depend on the labels
Stability bounds the difference between test and training error, not the test error itself, which also needs small training error. The bound grows with , so it worsens with more or larger steps, and nothing in it refers to the labels. Strong convexity gives the -independent version; the general convex bound does not need it.
Compression: keep a few examples, rebuild the rest
| Class or algorithm | Size | What is kept |
|---|---|---|
| Thresholds | 1 | the smallest positive example |
| Axis-aligned boxes in | for each coordinate, the two extreme positive examples; the smallest box around them is consistent | |
| Hard-margin SVM | number of support vectors | the support vectors: retraining on them alone returns the same separator, by the KKT conditions |
| Perceptron, margin , radius | at most | the examples on which it erred, in order; replaying them rebuilds the same weight vector (Novikoff's mistake bound) |
Fix a length and an index sequence . The hypothesis rebuilt from those examples is independent of the at least others. If , it labels all of them correctly with probability at most
The returned hypothesis is one of the , and it is correct on every example outside . A union bound over the at most sequences of length :
Choose so that each length contributes at most , and take a union over so that the size may depend on the data. With probability at least , a consistent reconstruction of size satisfies
This is Littlestone and Warmuth's union-bound argument (as sketched by Moran & Yehudayoff, 2016). Shalev-Shwartz & Ben-David (2014, Corollary 30.3) state the cruder for a fixed . No VC dimension, norm or parameter count appears: only how few examples suffice to pin the output down.
A hard-margin SVM separates training points using support vectors. With , evaluate the compression bound .
Show the answer
0.151
and , so the bound is , whatever the dimension of the feature space, even for an RBF kernel. With 10 support vectors it would be about : fewer support vectors, better guarantee.
Compression implies PAC learnability, hence finite VC dimension, and Littlestone and Warmuth asked about the converse. Floyd & Warmuth (1995) asked whether every class of VC dimension has a scheme of size . Moran & Yehudayoff (2016) proved that every such class has one of size (counting a little side information), so for binary classification compressibility and learnability are equivalent; the question, they note, remains open.
PAC-Bayes: distance from a prior
Fix a prior over before seeing the data. After seeing it, choose any posterior , which may depend on the sample in any way, and predict with the Gibbs classifier: draw for each prediction. Its risk and training error are and , for a loss in . PAC-Bayes bounds charge for the KL divergence instead of for the size of .
For a fixed , is an average of independent mean-zero terms, each with range of length . Hoeffding's lemma gives
The prior does not depend on , so average over and swap the expectations. Markov's inequality then holds for the random variable : with probability at least ,
On that event, change measure with . Because the event does not involve , the inequality holds for every at once, including ones chosen after seeing the data. Divide by :
Minimizing the right side over is exactly the equality case of the change of measure: the Gibbs posterior , a Bayesian posterior with the likelihood replaced by an exponentiated training loss (for the log loss with it is formally Bayes' posterior). The best , about , depends on , and fixing it in advance is avoided with a union bound over a grid of values, at the cost of a logarithmic term (Alquier 2024, Theorem 2.4).
Finite classes are a special case. A point mass on has , so each hypothesis pays for its own prior weight, a weighted union bound; a uniform prior gives back . Putting prior mass on hypotheses you consider simple is Occam's razor with a price list. For Gaussians, in : the bound rewards solutions near the prior's center that tolerate a lot of noise, that is, flat ones.
For a fixed , which posterior minimizes ?
- The point mass on the empirical risk minimizer
- The prior itself
- The uniform distribution over
- The Gibbs posterior
Show the answer
D. The Gibbs posterior
Multiply by : minimizing is the change of measure with , whose equality case is . It interpolates between the prior () and the ERM point mass ().
Nonvacuous bounds for deep networks
Dziugaite & Roy (2017) took the kl bound literally. They trained fully connected networks with 0.3 to 2.4 million parameters by SGD on 55,000 MNIST images relabeled into two classes (digits 0–4 against 5–9). They then fit a Gaussian posterior with a learned diagonal covariance around the SGD solution, and a prior centered at the random initialization (not at zero), with its variance chosen from a grid under a union bound. Finally they minimized the bound directly by SGD, with a differentiable surrogate for the 0–1 loss. Because the posterior can be wide only where the training loss stays low, the bound rewards flat regions around the solution.
One of their networks had nats and stochastic training error , with and . Evaluate the Pinsker form .
Show the answer
0.244
, so the bound is . Inverting the kl form instead, solving , gives , the value they reported for this network: the kl form exploits the small training error and Pinsker throws that away.
| Setting | Result |
|---|---|
| Dziugaite & Roy (2017), true labels | bounds of 0.16 to 0.22 on the stochastic network's error, whose measured test error was about 0.03, where VC bounds for the same architectures are vacuous |
| Dziugaite & Roy (2017), random labels | vacuous, as it must be when the labels carry no signal: the bound's square-root complexity term alone came to 1.35 |
| Pérez-Ortiz, Rivasplata, Shawe-Taylor & Szepesvári (2021) | networks trained by minimizing PAC-Bayes bounds with data-dependent priors, with risk certificates near 0.03 on MNIST (as summarized by Alquier, 2024) |
| Route | What it measures | Strength | Weakness |
|---|---|---|---|
| Uniform convergence (VC, Rademacher) | the class, possibly on the sample | algorithm-free; tight for small classes | vacuous when the class can fit noise |
| Stability | sensitivity of the algorithm to one example | covers regularized ERM and SGD; learnability in general settings | label-independent; nonconvex bounds grow with training time |
| Compression | how few examples determine the output | dimension-free (support vectors) | needs an explicit reconstruction |
| PAC-Bayes | KL distance from a data-independent prior | nonvacuous numbers for some deep networks | bounds a randomized predictor; depends on the prior |
Key takeaways
- Uniform stability controls the expected gap exactly, through the replace-one identity; with high probability the gap is at most , sharpened to about .
- Regularized ERM is stable with , and SGD on convex losses with ; such bounds are label-independent, so they cannot separate true from random labels.
- A compression scheme of size gives with no reference to dimension; every VC class compresses to size , and whether suffices is open.
- PAC-Bayes: by change of measure, minimized by the Gibbs posterior; the kl form gives rates at zero training error.
- Optimizing a Gaussian posterior around SGD's solution gave the first nonvacuous bounds for deep networks (0.16 to 0.22 against a test error of about 0.03), and vacuous ones on random labels, as it should.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
An algorithm is -uniformly stable in the replace-one sense. Which conclusion is guaranteed?
- Its test error is at most
- With probability at least , its generalization gap is at most
- Its expected generalization gap, over random training sets, is at most in absolute value
- Its training error is at most
Show the answer
C. Its expected generalization gap, over random training sets, is at most in absolute value
The replace-one identity writes the expected gap as an average change in loss when one example is swapped, which uniform stability bounds by . High-probability statements need more (Bousquet–Elisseeff and its successors), and nothing bounds the training or test error themselves.
Hardt, Recht and Singer's bounds depend on the number of steps, the step sizes, the Lipschitz and smoothness constants and . Why can they not explain why a network that can fit random labels still generalizes on true labels?
- Because SGD is never uniformly stable
- Because nothing in the bound depends on the labels: with the same training run on random labels the same bound would hold, yet the true gap there is huge (about 90% with ten balanced classes)
- Because the bounds apply only to convex losses
- Because uniform stability implies uniform convergence, which fails for such networks
Show the answer
B. Because nothing in the bound depends on the labels: with the same training run on random labels the same bound would hold, yet the true gap there is huge (about 90% with ten balanced classes)
A label-independent bound must be at least as large as the gap in the worst labeling, including random ones, so it cannot certify the small gap on real labels (Zhang et al., 2017). Explanations must use properties of the data, such as how far the weights move or how flat the solution is.
An RBF-kernel SVM separates training points with 15 support vectors. With , what does the compression bound certify?
- Error at most about , although the RBF feature space is infinite-dimensional
- Nothing, because the feature space is infinite-dimensional
- Error exactly
- Error at most with probability at least
Show the answer
A. Error at most about , although the RBF feature space is infinite-dimensional
. The bound counts examples needed to rebuild the classifier, not dimensions. The ratio appears in Vapnik's leave-one-out bound, but only as a bound on the expected error.
In the PAC-Bayes bound, what happens if the learner simply reports the posterior , the prior?
- The bound becomes vacuous
- is infinite
- The bound does not apply, because must depend on the data
- , and the bound reduces to a Hoeffding-type bound for a randomized predictor fixed before seeing the data
Show the answer
D. , and the bound reduces to a Hoeffding-type bound for a randomized predictor fixed before seeing the data
With the complexity term vanishes and only or remains, exactly what a hypothesis chosen in advance would pay. Every nat of KL is the price of using the data to move away from the prior.
Further reading
- O. Bousquet & A. Elisseeff, "Stability and generalization," Journal of Machine Learning Research 2, 499–526 (2002).
- M. Hardt, B. Recht & Y. Singer, "Train faster, generalize better: stability of stochastic gradient descent," Proceedings of the 33rd International Conference on Machine Learning, PMLR 48, 1225–1234 (2016).
- S. Moran & A. Yehudayoff, "Sample compression schemes for VC classes," Journal of the ACM 63(3) (2016).
- G. K. Dziugaite & D. M. Roy, "Computing nonvacuous generalization bounds for deep (stochastic) neural networks with many more parameters than training data," Proceedings of the 33rd Conference on Uncertainty in Artificial Intelligence (2017).
- P. Alquier, "User-friendly introduction to PAC-Bayes bounds," Foundations and Trends in Machine Learning 17(2), 174–303 (2024).