Generalization in Deep Learning
Dive into Deep Learning · §4.5
Generalization in Deep Learning
random-label memorization · double descent · minimum-norm & max-margin implicit bias · early stopping & grokking
The Overparameterization Paradox in Deep Learning
Classical vs. Modern Intuition
- Classical threshold (p / n = 1.0): A degree-19 polynomial (p = 20) interpolating n = 20 noisy points oscillates wildly (test MSE \geq 10^5, against 0.01 for the true cubic).
- Overparameterized MLPs (p \gg n): Our 256-unit MLP (p = 203{,}530) reaches \sim 87\% test accuracy on n = 60{,}000 images (p/n = 3.4) and \approx 80\% test accuracy on n = 1{,}000 images (p/n = 203.5) at 100\% training accuracy.
- The puzzle: Resolving why p/n = 203.5 generalizes requires testing capacity, conditioning at h = n, and SGD’s implicit bias.
Experiment 1: Memorizing Random Labels vs. True Labels
Memorization & Capacity
Following Zhang et al. (2017), we train our He-initialized 256-unit MLP (203{,}530 parameters) for 200 epochs on n = 1{,}000 Fashion-MNIST images, once with true labels and once with uniformly random labels:
- True labels (
fraction = 0): Reaches 100\% training accuracy within 60–90 epochs while test accuracy plateaus above 80\%.
- Random labels (
fraction = 1): The exact same network and SGD learning rate still hit 100\% training accuracy (in \sim 120–150 epochs), with test accuracy at 10\% random chance.
Why Distribution-Free Capacity Bounds Are Vacuous
Memorization & Capacity · Theory
\epsilon(f) \le \epsilon_{\mathcal{S}}(f) + B(\mathcal{F}, n, \delta)
- Naive parameter count fails: Approximating VC dimension v \approx p = 203{,}530 on n = 60{,}000 gives \sqrt{p/n} \approx 1.84 > 1.
- Random labels break every label-blind class bound: Because B(\mathcal{F}, n, \delta) depends only on the function class \mathcal{F} and sample size n, achieving \epsilon_{\mathcal{S}}(f) = 0 on random labels (\epsilon(f) = 0.90) forces B(\mathcal{F}, n, \delta) \ge 0.90 on true labels too.
No Free Lunch and the Role of Inductive Bias
Inductive Bias
- No Free Lunch (Wolpert, 1996): Averaged uniformly over all possible labelings of unseen inputs, every learning algorithm has the exact same expected test error.
- Interpolation \neq overfitting: 1-Nearest Neighbor achieves 100\% training accuracy yet has asymptotic test error \le 2\epsilon^\star via local Voronoi smoothness.
- Deep learning inductive bias: Overparameterized MLPs + SGD select minimum-norm / maximum-margin interpolators that fit coherent signal before noise.
Classical Bias-Variance U-Curve vs. Overparameterization
From Classical to Modern Regimes
In the classical underparameterized regime (h < n), increasing capacity lowers training error while test error traces a U-curve:
- Underfitting (left of U): Too few features to capture the true signal.
- Overfitting approaching h = n (right of U): Having just enough parameters to interpolate all n noisy points forces wild oscillations between training examples.
- The question beyond the chart: What happens when width h grows past n (h \gg n), where infinitely many zero-error interpolators exist and we select the minimum-norm one?
Double Descent in Random-Features Least Squares
Double Descent · Experiment
We freeze a He-initialized random ReLU layer \mathbf{H} = \mathrm{ReLU}((\mathbf{X} - \bar{\mathbf{x}})\mathbf{W}^{(1)}) \in \mathbb{R}^{n \times h} on n = 1{,}000 images and fit \mathbf{W}^{(2)} \in \mathbb{R}^{h \times 10} by minimum-norm least squares (np.linalg.lstsq) across widths h \in [50, 10{,}000]:
- Classical U-curve (h < 1{,}000): Test error drops to \sim 23\% at h = 200, then spikes to \sim 90\% right at the interpolation threshold h = n = 1{,}000.
- Second descent (h > 1{,}000): Past h = n, training error stays at 0, yet test error plunges to \sim 20\% at h = 10{,}000, beating the best h < n model.
Why Test Error Spikes at h = n: Singular Conditioning
Double Descent · Conditioning
Inspecting the smallest singular value s_{\min}(\mathbf{H}) and the weight norm \|\mathbf{W}^{(2)}\|_{\textrm{F}} explains both the spike at h = n and the healing at h \gg n:
h = 200: smallest singular value 1.7e+00, norm of W2 3.7
h = 900: smallest singular value 1.2e-01, norm of W2 20.4
h = 1000: smallest singular value 2.0e-04, norm of W2 1577.9
h = 1100: smallest singular value 2.3e-02, norm of W2 20.4
h = 10000: smallest singular value 2.1e-01, norm of W2 2.2
- At h = n = 1{,}000: \mathbf{H} is a square 1000 \times 1000 matrix with a single unique exact inverse \mathbf{W}^{(2)} = \mathbf{H}^{-1}\mathbf{Y}. Because random features have nearly collinear directions (s_{\min} \sim 10^{-4}\text{--}10^{-2}), inverting \mathbf{H} divides label noise by s_{\min} and blows up \|\mathbf{W}^{(2)}\|_{\textrm{F}}.
- At h = 10{,}000 \gg n: Extra features provide a 9{,}000-dimensional subspace of exact interpolators, allowing the minimum-norm fit to spread weights across well-conditioned directions (\|\mathbf{W}^{(2)}\|_{\textrm{F}} \approx 2.2\text{--}2.4).
When Adding More Training Data Hurts Test Accuracy
Double Descent · Sample-Wise
Because the ill-conditioned cliff sits along the diagonal h = n, increasing sample size n at a fixed model width h = 1{,}000 can push an overparameterized model onto the interpolation threshold:
500 training images: test error 0.28
1000 training images: test error 0.89
With width fixed at h = 1{,}000, training on n = 500 images sits safely in the overparameterized regime (h = 2n, test error \sim 28\text{--}30\%), whereas doubling the dataset to n = 1{,}000 lands squarely on h = n and degrades test error to 85\text{--}89\%. Regularization (\ell_2 ridge penalty) damps 1/s_{\min} and eliminates this spike.
Implicit Bias 1: Minimum-Norm Fit in Least Squares
Implicit Bias · Squared Loss
Why did lstsq’s minimum-norm preference generalize for h \gg n? Because gradient descent from \mathbf{w}_0 = \mathbf{0} finds the minimum-norm interpolator automatically, without any explicit regularizer:
\nabla_{\mathbf{w}} \tfrac{1}{2}\|\mathbf{H}\mathbf{w} - \mathbf{y}\|_2^2 = \mathbf{H}^\top(\mathbf{H}\mathbf{w} - \mathbf{y}) \in \mathrm{row}(\mathbf{H})
- Row-space invariance: Every gradient step is a linear combination of the rows of \mathbf{H}. Starting at \mathbf{w}_0 = \mathbf{0}, every iterate \mathbf{w}_t = \mathbf{H}^\top\mathbf{a}_t remains orthogonal to \mathrm{null}(\mathbf{H}).
- Pythagorean optimality: At convergence (\mathbf{H}\mathbf{w}^\star = \mathbf{y}), \mathbf{w}^\star = \mathbf{H}^\top(\mathbf{H}\mathbf{H}^\top)^{-1}\mathbf{y}. Any other interpolator \mathbf{w}^\star + \mathbf{v} (\mathbf{H}\mathbf{v} = \mathbf{0}) has strictly larger norm \|\mathbf{w}^\star\|_2^2 + \|\mathbf{v}\|_2^2.
Numerical Verification of Minimum-Norm Implicit Bias
Implicit Bias · Verification
Running 2{,}000 steps of unregularized gradient descent on an underdetermined 20 \times 100 system confirms the role of initialization \mathbf{w}_0:
start zero : residual 8e-17, norm 0.79, distance to w* 0.0
start random: residual 3e-15, norm 9.39, distance to w* 9.4
- Initialized at \mathbf{w}_0 = \mathbf{0}: Converges to the exact minimum-norm solution \mathbf{w}^\star (
distance to w* = 0.0, norm below 1).
- Initialized at random \mathbf{w}_0 \sim \mathcal{N}(\mathbf{0}, \mathbf{I}): Still interpolates the data (
residual at rounding error), but retains its initial null-space component \mathbf{v}_0 \in \mathrm{null}(\mathbf{H}), ending with a weight norm more than 10\times larger.
Implicit Bias 2: Max-Margin Direction in Classification
Implicit Bias · Classification
What is the implicit bias of gradient descent on linearly separable classification (y_i \in \{-1, +1\}) under logistic (cross-entropy) loss \sum_i \log(1 + e^{-y_i \mathbf{w}^\top\mathbf{x}_i})?
- Norm diverges, direction converges: Because \log(1 + e^{-m}) > 0 for all finite margins, \|\mathbf{w}_t\|_2 \to \infty, while \mathbf{w}_t / \|\mathbf{w}_t\|_2 rotates toward the hard-margin SVM maximum-margin separator (Soudry et al., 2018).
- Why margins keep improving after 100\% train accuracy: Boundary examples with the smallest margins dominate the gradient \propto e^{-y_i\mathbf{w}^\top\mathbf{x}_i}, driving test error down long after training error hits 0.
Temporal Bias: SGD Fits Clean Structure Before Noise
Early Stopping · Dynamics
On noisy datasets, gradient descent exhibits a striking temporal ordering (Arpit et al., 2017). Corrupting 20\% of our 1{,}000 Fashion-MNIST labels (\sim 18\% wrong), we track accuracy on clean training examples, mislabeled training examples, and clean validation images:
- Epochs 1–20 (clean-first window): Coherent gradients across clean images drive clean training accuracy above 80\% while fewer than 20\% of wrong labels are memorized; validation accuracy peaks here.
- Epochs 20–200 (memorization phase): As clean residuals shrink, SGD fits the conflicting wrong labels to \sim 100\%, pulling validation accuracy down by several points.
Early Stopping and Its Exception: Grokking
Early Stopping vs. Grokking
Halting training at the best validation checkpoint (early stopping) prevents late-epoch noise memorization, though algorithmic tasks with weight decay can exhibit the opposite phenomenon (grokking, Power et al., 2022):
best validation accuracy after epoch 16: test accuracy 0.775
after all 200 epochs: test accuracy 0.716
- Early stopping as implicit ridge: In linear least squares, stopping after t steps of rate \eta acts like \ell_2 weight decay with \lambda \approx 1/(\eta t).
- Grokking exception (right): On modular addition (a + b) \bmod 97 with weight decay, training accuracy hits 100\% by 10^3 steps while validation accuracy stays at chance until jumping to 100\% at 10^5 steps.
Concept Check: Capacity, Conditioning, and Implicit Bias
Check
Test your understanding of modern generalization phenomena:
- Corrupted-label arithmetic: When 20\% of 1{,}000 labels across 10 classes are redrawn uniformly at random and the network memorizes 100\% of the corrupted training set at epoch 200, what is its accuracy measured against the true uncorrupted training labels?
- Gradient descent from non-zero start: For the single linear equation w_1 + 2w_2 = 4 (\mathbf{h} = (1, 2)^\top), where does gradient descent converge when initialized at \mathbf{w}_0 = (0, 0) vs. \mathbf{w}_0 = (1, 1)?
- Eliminating the double-descent peak: Why does adding an \ell_2 ridge penalty \lambda\mathbf{I} eliminate the test-error spike at the interpolation threshold h = n?
Answers:
- 82\% true-label accuracy: A redrawn label accidentally matches the true class 1/10 of the time, so 0.20 \times (9/10) = 18\% of training labels are genuinely wrong and memorized.
- Projection onto w_1 + 2w_2 = 4: From (0, 0), it lands at the minimum-norm point \mathbf{w}^\star = \frac{4}{5}(1, 2) = (0.8, 1.6) (norm 1.79). From (1, 1), it steps along \mathbf{h} to (1, 1) + \frac{4 - 3}{5}(1, 2) = (1.2, 1.4) (norm 1.84).
- Damping s_{\min}: Ridge replaces singular value inversion 1/s_i with s_i / (s_i^2 + n\lambda), bounding the amplification of tiny singular values s_{\min} \approx 0 at h = n.
Summary: Generalization in Deep Learning
Key Takeaways
- Capacity & double descent: Random-label memorization makes label-blind VC bounds vacuous; test error spikes at h = n (s_{\min}(\mathbf{H}) \approx 0) and falls for h \gg n.
- Spatial implicit bias: Gradient descent from \mathbf{w}_0 = \mathbf{0} finds the minimum-\ell_2-norm interpolator under squared loss and rotates toward the maximum-margin SVM separator under logistic loss.
- Temporal implicit bias: SGD fits coherent clean labels in \sim 20 epochs before memorizing noise, making early stopping act like \lambda \approx 1/(\eta t) ridge regularization.