A bridge-builder who has only five measurements cannot trust a design with five hundred free numbers. The classical rule of thumb says the same for models: one with as many free numbers as data points can match every point exactly, and so it has probably learned the noise (P3.A3). Modern neural networks break the rule every day. A network with millions of weights is trained on thousands of examples, reaches zero training error, and still does well on new examples.
This lesson is about that mismatch. It has no final answer, because there is none yet. It shows the experiments that sharpened the puzzle, a demonstration you can run yourself, and an honest list of what is still open.
The classical picture, in two lines
P3.A3 fitted polynomials of growing degree to noisy points: training error falls all the way to at degree (10 weights for 10 points), and test error is U-shaped. P3.A5 explained the U: bias falls and variance rises as the model gets more flexible. A model that has just enough weights to pass through every training point, so that its number of weights equals , is at the right edge of the U, where variance is largest. The point where and the model can just fit the training data exactly is called the interpolation threshold.
The features here are cosines, not the polynomials of P3.A3, so the numbers differ from P3.A3’s degree-9 numbers. The rise is the same phenomenon. The P3.A3 widget stopped at degree . The questions here begin on the other side of that edge: what happens to a model with larger than ?
Puzzle 1: networks can memorize noise
If big networks generalize because their size is somehow “right”, then fitting anything should be hard. Zhang, Bengio, Hardt, Recht and Vinyals (ICLR 2017, posted 2016) tested it. They kept the images of standard benchmarks (CIFAR-10 and ImageNet) and replaced the labels with random ones, so that nothing in the images predicts the label. Standard convolutional networks trained with stochastic gradient methods still reached zero training error. Test accuracy, of course, could be no better than chance, because the test labels have no link to the images. The authors also report that this was qualitatively unaffected by explicit regularization, and that it also happens when the images are replaced by random noise. They add a construction showing that a simple two-layer ReLU network with parameters can express any labeling of any sample of points in dimensions.
You can reproduce the idea at small scale in the first code cell below. The network has one hidden layer of tanh units. The training set has points with inputs, and it is trained with plain gradient descent on the log loss. The same network and the same training run are used twice, once on labels given by a simple rule (the sign of a fixed linear score) and once on random labels:
- With the rule, training accuracy reaches and accuracy on new points is .
- With random labels, training accuracy also reaches (within steps), and accuracy on new points is .
Only the first run has learned something. So fitting the training data is not evidence of generalization, and a bound that depends only on how flexible the model class is cannot be the whole explanation. On real data the same networks do generalize, so something about the data, the architecture and the training procedure matters, not just the size.
Puzzle 2: double descent
If a model can fit pure noise, the classical rule suggests that nothing good happens past the interpolation threshold. Belkin, Hsu, Ma and Mandal (PNAS, 2019) reported the opposite. In a family of models whose size they could vary smoothly, test error rose to a peak at the threshold and then fell again as the model grew, sometimes below the lowest error of the classical U. They called the full curve double descent: the first descent is the classical one, then the rise to the peak at the threshold, then the second descent.
Their main experiments used random Fourier features, which are a two-layer network with a fixed random first layer, and a rule for choosing among many exact fits: take the one whose weights have the smallest norm. They report a similar shape for two-layer neural networks and for some decision-tree ensembles.
A model you can sweep: minimum-norm regression
You can see the whole curve on a toy that runs in your browser. The task is the one of P3.A3: training points with plus noise of size (so the best possible squared error on new noisy data is ). The model has weights on a list of fixed features of : a constant, then for . A model with features uses the first of them, so is a constant and a larger adds ever wigglier cosines. This is linear regression on made-up features (P3.A2, P3.A3).
- For the training points cannot all be matched, and least squares gives the best compromise.
- For there is exactly one weight vector that passes through every training point.
- For infinitely many weight vectors pass through every point. We choose the one with the smallest norm , called the minimum-norm solution. It is computed with the pseudo-inverse of the SVD lesson (P1.B13), and the code does it with
np.linalg.lstsq.
Things to try, with the numbers the widget shows for its default sample (noise 0.30, no penalty):
- Slide from up to . The fit improves and test error falls from at to its lowest value before the threshold, at (the floor is ). That is the classical descent.
- At test error is . At the curve passes through all ten points, its weights have norm , and test error is , hundreds of times the best. This is the peak.
- Keep going: gives , gives , gives and gives , with the weight norm falling to . The training error is throughout, and the test error is back near the classical best: the second descent.
- In the Noise row press none. The peak is gone: at test error is . The peak is made of noise in the training labels.
- Press small ridge in the Penalty row. A penalty of on the squared weights lowers the peak at from to , at the price of a nonzero training error (about there).
The first code cell below prints these numbers.
Why the peak is at
At the matrix of features has to be inverted to hit every point exactly, and it is nearly singular: its smallest singular value is , against at , at and at (P1.B13). The solution contains each noise component of divided by a singular value, so a tiny singular value blows the noise up: the weights are huge () and the curve swings wildly between the points. With more weights than points the system has slack, the matrix is less singular than at ( at , at ), and the minimum-norm choice keeps the weights small ( at , at ). In this toy the peak is a variance explosion at the one size where the model has no freedom left, and the second descent is the freedom coming back.
Two caveats about this demonstration, so you do not over-read it:
- The height of the peak depends a great deal on the draw of the training points. Over random draws of the ten positions, the test error at has a median of about , and the values are spread over many orders of magnitude (about one draw in five is milder than the widget’s ). The widget’s sample is therefore a mild one. At the median is and at it is (the second code cell). What is typical is the shape: a huge rise at and a fall after it.
- The second descent depends on what the minimum-norm choice prefers, and that depends on how the features are scaled. A feature multiplied by needs a weight times smaller, so it is cheap in norm. With the scaling above, low-frequency cosines are the cheap ones, so the minimum-norm fit leans on them. With all features at the same scale, the same sweep gives test error at , not . At the two give the same curve, since rescaling the columns of a square invertible matrix does not change the exact fit. Beyond , the scaling decides which exact fit is picked.
What the papers report for real networks
Nakkiran, Kaplun, Bansal, Yang, Barak and Sutskever (posted December 2019) looked for the same shape in deep learning. They report model-wise double descent for several datasets (CIFAR-10, CIFAR-100, IWSLT’14 translation), architectures (CNNs, ResNets, Transformers) and optimizers, with the peak occurring near the interpolation threshold, and that they see it most strongly when the training labels contain noise. They also report epoch-wise double descent (test error of a fixed large model falls, rises when training has just reached about zero training error, and falls again with longer training), and, in some settings, sample-wise non-monotonicity, where adding training data hurt (the threshold moves as the data grows). These are measured effects in the settings studied, not a rule that more data hurts. They define an “effective model complexity” (roughly, the largest number of training samples a training procedure can still fit) and conjecture that the peak appears when this complexity is about the number of training samples. For deep networks the threshold is therefore not simply “”: it depends on the data and on the training procedure too.
Implicit regularization: which exact fit does training pick?
A model with weights has many exact fits. In the toy we chose the one with the smallest norm. But you do not need to ask for it: gradient descent started at zero finds it by itself.
Take with equations and unknowns. Gradient descent on updates by (P1.F3). Every update is a combination of the rows of . Started at , never leaves the span of those rows. With a full-rank matrix and a small enough step size it converges to an exact solution, and among all exact solutions there is only one inside that span: the one with the smallest norm. The third code cell checks it on a example: from zero, gradient descent ends within about of the pseudo-inverse solution (norm ). From a random start it also fits exactly, but ends away (norm ), because the part of the start outside the span of the rows is never removed.
So the optimizer, its starting point and the parametrization make a choice that no line of the loss mentions. Such a built-in preference is called implicit regularization, as opposed to the explicit penalties of P3.A6 and P4.17. It is a theorem for this linear problem, and similar results exist for some other simple models. For the nonlinear networks used in practice it is an open research area, and no single preference such as “smallest norm” has been shown to explain what happens.
Noise in the updates is one proposed ingredient. P4.15 described the debate: Keskar and others (2016) reported that small batches reached flatter minima and better test accuracy, Goyal and others (2017) found that much of the gap closed with a scaled learning rate, and Shallue and others (2018) found no evidence that larger batches hurt when everything is tuned. In the grokking paper (below), noise helped generalization on small tasks, which the authors call consistent with flatter minima. Together this makes “SGD noise acts as a regularizer” a plausible hypothesis with mixed evidence, not an established rule.
Zhang and others (2017) conclude that explicit regularization may improve generalization but is, in their words, neither necessary nor by itself sufficient for controlling generalization error. Weight decay, dropout and early stopping (P4.17) remain standard tools, but they do not explain on their own why large networks generalize.
Puzzle 3: grokking
Power, Burda, Edwards, Babuschkin and Misra (posted January 2022) trained small transformers on tables of a binary operation, for example “”: part of the table is used for training, and the model has to fill in the rest. In their headline experiment (division modulo , half of the table used for training) training accuracy was close to perfect in under optimization steps, while it took close to steps for validation accuracy to reach that level, with little sign of generalization before steps. They called the late jump grokking. Weight decay (towards zero) had a very large effect: it more than halved the training data needed compared with most other interventions they tried. The model was a small decoder-only transformer (2 layers, width ), trained with AdamW at weight decay .
What does this show, and what does it not?
- It shows that a flat validation curve at a point where training error is already zero is not always the end of the story, at least on small algorithmic tasks.
- Follow-up work by Nanda, Chan, Lieberum, Smith and Steinhardt (2023) studied small transformers on modular addition. They report that the networks learn an algorithm based on trigonometry (discrete Fourier transforms), and that training splits into three phases: memorization, circuit formation, then cleanup of the memorizing parts. In that account grokking is gradual, not a sudden switch. One reading is that weight decay slowly favours the smaller, general solution, but that is an interpretation, not a settled explanation.
- It does not show that training any model for much longer will make it generalize. The effect was found on small algorithmic datasets, and whether it matters at the scale of everyday deep learning is not established.
Benign overfitting
Bartlett, Long, Lugosi and Tsigler (PNAS, 2020) gave a name and a theory to benign overfitting in linear regression: a fit that matches noisy training data exactly and still predicts well. They say when the minimum-norm interpolating predictor is nearly optimal. Roughly: the data must have many directions that matter little for the prediction (measured by two notions of effective rank of the covariance), many more than the number of training points, so that the interpolated noise is spread thinly over directions that do not affect the predictions much. The result is a theorem about linear regression with conditions on the data. The toy of this lesson is not a test of it. For deep networks, no comparable result covers the networks used in practice.
What this means in practice
- The classical picture still holds for models that are small compared with the data: the U-shaped curve and held-out validation (P3.A4) still decide how big they should be.
- “Zero training error” is not a failure on its own. The signal of overfitting is the gap between training and validation results, as in P3.A3. Many large networks reach zero training error and still do well with the usual tools (P4.17, P4.18).
- A bump in validation error as a model grows is not proof that larger models will be worse. If compute allows, look at a few sizes beyond it.
- Keep the safe defaults (P4.22, P4.23): hold out data and watch the validation curve. These results describe particular settings, and your data may differ.
Open questions
These are open as of this lesson:
- What makes the exact fit that a real network finds generalize, when other exact fits (such as the random-label ones) do not?
- Does SGD noise, flat minima, or something else act as the main implicit regularizer in deep networks?
- When does a double-descent peak appear, how high is it, and can it be predicted without training?
- Why does generalization sometimes arrive long after the training error is zero, and does that happen outside small algorithmic tasks?
Depth: three ways to see it
Intuition
Think of a rope threaded through posts. With fewer bends than posts it cannot touch every post. With exactly as many bends as posts there is one way to touch them all, and if the posts are a little off (noise), the rope has to loop and whip to get there. With many more bends you can choose the gentlest rope that touches every post, and gradient descent from zero is like pulling a straight rope: it bends only where it must. The analogy breaks because no tidy “gentle” measure is known to be what real networks prefer, and because more bends cost nothing here while real models cost memory and compute.
Math
Let be the matrix of features, the targets, and its SVD (P1.B13) with singular values . For and full row rank, the minimum-norm interpolator is
It lies in the row space of . Any other exact solution is with , so is orthogonal to the row space, and . That is why has the smallest norm.
The sum shows the peak. If contains noise, the term carries noise of size about along . When the smallest singular value is tiny, as at with on the toy, the noise is amplified and is large.
A ridge penalty (P3.A6) replaces by , which stays below whatever is and tends to as .
Gradient descent. If , the iterates from converge to , so from they reach , and the part of a nonzero start that is orthogonal to the row space survives.
Code
The same experiment as the first code cell below, in PyTorch (nn.Sequential(nn.Linear(10, 64), nn.Tanh(), nn.Linear(64, 1)), plain SGD with learning rate , steps, training and test points). Output from a local run with PyTorch 2.9.1:
true rule train 1.00, test 0.96
random labels train 1.00, test 0.52With random labels, test accuracy near is chance, as it has to be for labels that carry no pattern.
Try it in Python
The cells run the random-label experiment, print the widget’s numbers with the medians over many draws, and check that gradient descent from zero reaches the minimum-norm solution.
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
Running the cell gives, for the rule, training accuracy from step on and test accuracy . For random labels, training accuracy is at step and from step on, and test accuracy is .
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
The cell prints the table behind the widget (test error at , at ), the ridge column, the smallest singular values and the medians over draws (, about and ; the large value is not stable between machines and seeds). Change sigma to 0 to see the peak vanish, and a to 0.0 to see the second descent weaken.
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
The cell prints a fit error near for all three solutions, a distance of about between the gradient-descent result and the minimum-norm solution (norm ), and norm (distance ) for the run from a random start. The other exact solution has norm . The exact digits of the tiny errors depend on the machine.
Common mistakes
Quiz
Check your understanding
A network is trained on images whose labels were replaced by random ones, and reaches training accuracy. What does this show?
Random labels have no pattern, yet the network fits them, so a perfect fit to training data cannot by itself explain good performance on new data. Concluding that the same network must fail on real data does not follow: the same network trained on real labels generalizes. A hidden pattern is ruled out by how the labels were made, and the fitting is the ordinary algorithm working as designed.
In the toy task of this lesson, at which model size does the test error peak, and why?
At there is one exact fit, found by inverting a nearly singular matrix, so the noise in the labels is multiplied by large factors and the weights become large. The error at is , much lower than at . At the largest the test error is , near the classical best. Training error is highest at and falls with , so it does not mark the peak.
Gradient descent on an under-determined least-squares problem (more unknowns than equations) is started from and converges. Which solution does it reach?
Each update is a combination of the rows of the matrix, so from zero the weights stay in the row space, and the only exact solution there is the minimum-norm one. A random one would need something random in the procedure, and none is present. There is no largest-norm exact solution, since the norm can be made as large as you like. With more unknowns than equations, an exact fit exists, so the residual goes to zero.
Which statement about grokking is supported by the papers described in this lesson?
Power and others reported exactly this on small tasks such as modular arithmetic. They did not claim it for any network or dataset, so the statement about every network overreaches. Weight decay had a large effect, and a later study describes gradual phases, but a full explanation is not established. The memorization in the experiments took on the order of a thousand steps, not one, and the effect is not described as an artefact.
You sweep the width of a network and see validation error rise as width passes the point where training error first reaches zero. What does this lesson support doing?
Peaks near the interpolation threshold have been reported, and some curves fall again beyond them, so one bump is not proof. But the lesson does not claim a second descent always occurs, so checking is the sensible step. Dropping validation data removes the only way to see what is happening. The claim that bigger is never worse is not what the papers say: they report settings in which bigger models were worse.
Exercises
- A model has weights and is trained on points with a squared loss. Where is the interpolation threshold, and what does the model-wise double-descent picture say about , and (for a setting where it applies)?
Show answer
The threshold is at . At the model is in the classical regime (it cannot fit every point, and test error follows the U-shaped curve). At the model can just fit the data and test error is expected to be at or near its peak, especially with noisy labels. At it is far into the interpolating regime, where test error often falls again. That is an observation in some settings, not a guarantee, and held-out data is still needed to know. - One equation, two unknowns: . Find the minimum-norm solution and its norm, and compare it with the solution .
Show answer
The minimum-norm solution is with : , so . Check: . Its norm is . The solution also satisfies the equation but has norm . Gradient descent from moves along , so it ends at . - In the widget, keep noise 0.30 and no penalty and set and then . Then press none in the Noise row and set . What are the three test errors, and what does the comparison tell you?
Show answer
About at and at with noise 0.30, and at with no noise. Both models fit the ten training points exactly. The peak needs noise in the labels, so it is the noise being amplified by the nearly singular matrix that causes it, and with more weights than points the minimum-norm choice does not amplify it. - In the random-label code cell, why is the test accuracy and not, say, after training for much longer?
Show answer
The test labels were drawn independently of the test inputs, so no function of the inputs can predict them better than chance, whatever the network learned. The expected accuracy is for every model, and the observed is that value. The same network on labels given by a rule reached .
Next: This is the last lesson of Part 4. Part 5 starts with P5.1, Images as tensors: how a picture becomes numbers a network can read, as the first step towards convolutional networks.