learn-deep-learning-with-phoebe / Session 5 of 6
Learn Deep Learning with Phoebe · Session 5 of 6

Taming the net

The loop works. Architectures promise. And yet a network with more parameters than data points WILL memorize the training set if you let it - next session's showdown contains a live specimen, a 2x16 MLP scoring 100 on train and 60 on holdout from 200 rows. Tonight is the taming: the one diagnosis that matters, a shocking 2017 result about what nets can memorize, the medicine cabinet in its correct order, and a plot twist where making the net even bigger sometimes - sometimes - makes things better again.

🟠 Hands-on Builders - you own the loop from session 3 45 min
0-3 · Welcome 3-20 · Memorization and its medicine 20-40 · Build-along: the taming checklist 40-45 · Q&A
Part 0

The net that knows too much

Quick recap of where you stand: sessions 1-2 built the unit and the blame assignment, session 3 gave you the live loop, session 4 gave you architectures that spend parameters wisely. Tonight's problem is the opposite of session 4's: not too little capacity in the wrong shape, but too much capacity with nothing to stop it. Every number tonight points at session 6, where the 2x16 memorizer meets its holdout score in public.

🎫 Clear all three quiz questions to stamp your passport Live = presented in the 45 minutes Self-study = the full depth, after class

★ What you walk out with tonight. The one-look overfitting diagnosis. The Zhang et al. random-labels result, with its exact scope. A medicine cabinet you can recite in order. And one honest sentence about double descent that will survive contact with a skeptical meeting.

LiveThe diagnosis before the medicine4 min▶

You already saw the shape in session 3's stuck-shapes gallery: training accuracy keeps climbing while validation goes flat, then drifts down. Train-up-test-flat. That gap is overfitting, and it is the only diagnosis tonight - everything else is treatment.

Every item in tonight's cabinet attacks that same gap from a different side: more data makes the training set harder to memorize; early stopping quits before the memorizing starts; dropout makes memorizing unreliable; weight decay makes it expensive; a smaller net makes it impossible. The order matters - and Part 2 gives you the order with sources attached.

Real world

The live specimen, from next session's showdown canon: on 200 training rows of Mango Lane churn data, the 2x16 MLP reaches train 100, holdout 60 - the worst holdout of every net tested, precisely because it fit best. Memorization is not a theoretical risk. It is the default behavior of an untamed net on small data.

Self-studyTonight's vocabulary2 min▶
  • Generalization gap - train score minus test score. The number every treatment tries to shrink.
  • Regularization - anything that trades training fit for holdout performance, from extra data to weight penalties.
  • Interpolation threshold - the capacity at which a model can fit the training data exactly. Part 3's landmark.
  • Label noise - wrong labels in the training set. Where double descent shows itself most clearly.
Part 1 · covers the memorization result

The shocking baseline: nets memorize random labels

6 min live

Before trusting any medicine, measure the disease. In 2017, Zhang, Bengio, Hardt, Recht and Vinyals ran the cleanest possible experiment: take state-of-the-art convolutional networks and train them on image labels that are completely random. If nets learn patterns, this should fail. It did not.

LiveThe experiment, in the paper's words4 min▶
The paper's wordsState-of-the-art convolutional networks "easily fit a random labeling of the training data" - and the result is essentially unchanged by explicit regularization, and holds even when the true images are replaced by completely random pixels.
  • Random labels: the nets reach perfect training accuracy. There is no pattern to learn - this is pure memorization, and the architecture does it without complaint.
  • With regularizers on: essentially the same. The standard toolkit does not remove the memorization capacity.
  • Random pixels: still fits. The result is not about image structure at all.

The punchline is a negative result about theory: if the same architecture can memorize noise perfectly, then classical complexity measures - counting capacity - cannot explain why that architecture generalizes on real labels. The capacity to memorize was always there. Something else decides whether it gets used.

Cite it as ICLR 2017 (or the 2021 CACM republication) - never 2016, whatever a slide deck tells you.

Same net, REAL labels train: high test: high Looks like learning: patterns found, patterns transfer to unseen data. Same net, SHUFFLED labels train: 100 test: chance No pattern exists - yet the net fits perfectly. Pure memorization. Identical architecture, identical training - only the labels changed. The memorization capacity was always there, and explicit regularizers barely dent it. So capacity counting alone cannot explain why the left panel generalizes. That open question is what Part 3's double descent lives inside.
🔍 Click to zoom - the same net, real vs shuffled labels: the capacity was always there
Self-studyWhat the result does NOT say3 min▶

The paper shows classical tools are insufficient - it does not show generalization is unexplainable. The working answers under active research: the implicit bias of SGD (gradient descent prefers certain solutions among the many that fit), margin-based measures, and Part 3's double descent. The honest summary for a meeting: "we can measure that these nets generalize, and we can rule out the textbook explanation; the replacement theory is still being written."

Practical consequence, and the bridge to Part 2: since the architecture will not protect you from memorization, you have to - with data, stopping rules, and the rest of the cabinet.

Part 2 · covers the treatments, in order

The medicine cabinet

7 min live

Five treatments, ordered by preference, each with its source and its fine print. The order is not taste - it is the difference between fixing the disease and suppressing the symptom.

Reach left first 1 2 3 4 5 More data the by far best Early stopping quit before the cram Dropout break co-adaptation Weight decay (AdamW) make weights cheap Smaller model remove the capacity always first, when you can get it free - your s3 validation habit FC heads and transformers decoupled, via torch.optim.AdamW when data is small and fixed Order matters: data fixes the disease, the rest manage the symptom. Karpathy calls more data the by far best and preferred regularizer. Every shelf item attacks the same diagnosis: train climbing, validation flat.
🔍 Click to zoom - the cabinet, ordered: reach left before reaching right
LiveMedicines 1 and 2: data, then the clock3 min▶

(a) More data. Karpathy's recipe puts it beyond argument:

Karpathy's recipe"...get more data - the by far best and preferred way to regularize a model in any practical setting."

Every other treatment trades something away. Data does not - it directly makes the training set unmemorizable and the patterns unmistakable. It is only ever skipped because it is inconvenient, which is not a statistical argument.

(b) Early stopping. You already do this: session 3's habit of watching the validation curve. Stop when validation stops improving - the net was learning patterns first and noise second, so quitting early keeps the patterns and skips the cram. The ensemble course's early-stopping law on boosted trees is the same medicine administered to a different species.

LiveMedicines 3 and 4: dropout and decay, with fine print4 min▶

(c) Dropout (Srivastava et al., JMLR 2014), mechanism verbatim:

The paper's words"The key idea is to randomly drop units (along with their connections) from the neural network during training. This prevents units from co-adapting too much."
  • The theory: training with random deletions approximates averaging exponentially many thinned networks. Note the verb - it is an approximation argument, not a literal ensemble like the tree course's forests.
  • Modern usage: mostly fully-connected heads and transformers; less in conv layers, where normalization layers took over the job.

(d) Weight decay, done right. For years people wrote "L2 regularization" and "weight decay" interchangeably. Loshchilov and Hutter's AdamW paper (ICLR 2019) showed the equivalence has a boundary:

The paper's wordsL2 regularization and weight decay "are equivalent for standard stochastic gradient descent... but as we demonstrate this is not the case for adaptive gradient algorithms, such as Adam". Decoupling them "substantially improves Adam's generalization performance".

With Adam, the L2 penalty gets rescaled by the adaptive step sizes - exactly the weights with large gradients get under-regularized. The fix is decoupling the decay from the gradient update, which is why torch.optim.AdamW is today's default and plain Adam plus L2 is the quiet bug in a thousand training scripts.

Self-studyMedicine 5, and how the cabinet maps to your loop3 min▶
TreatmentOne line in PyTorchWhat it costs
More dataNothing to type - collect, or augmentTime and money, never accuracy
Early stoppingTrack val loss, keep the best checkpointA validation split
Dropoutnn.Dropout(p) in the FC headSlower convergence, a p to tune
Weight decaytorch.optim.AdamW(..., weight_decay=...)A coefficient to tune
Smaller modelFewer layers, narrower widthsCapacity you might have needed

Smaller model is last on the shelf for a reason Part 3 makes vivid: capacity you remove is gone, and the relationship between capacity and generalization is stranger than the textbook says.

Part 3 · covers the plot twist

Double descent: when bigger recovers

4 min live

The textbook says capacity has a sweet spot: too little underfits, too much overfits, tune to the valley of the U. Belkin and colleagues showed the U is not the whole curve.

test error model capacity (parameters) interpolation threshold the classical U the second descent 2x16 here: holdout 60 3x32 here: holdout 68 Most visible with label noise near the threshold. Not a law that bigger always wins, and not a regularization amnesty. Session 6 shows the shape measured: the 401-param net at 60, the 2,369-param net at 68, same 200 rows.
🔍 Click to zoom - the U was only the first half of the curve
LiveThe claim, its scope, and where the full story lives4 min▶
Belkin et al., PNAS 2019"This 'double descent' curve subsumes the textbook U-shaped bias-variance trade-off curve by showing how increasing model capacity beyond the point of interpolation results in improved performance."

Nakkiran et al. then showed the effect in modern deep nets, both model-wise (grow the network) and epoch-wise (train longer) - and found regimes where, strangely, more data hurts. The scope, which is content and not a disclaimer: the effect is most visible with label noise near the interpolation threshold, and it does NOT mean bigger is always better or that regularization is obsolete.

You will see the shape with your own eyes next session: the 3x32 overparameterized net (holdout 68) beats the 2x16 memorizer (holdout 60) on the exact same 200 rows - a measured dip-and-recovery, live. And note who still wins that showdown: the booster at 73. Recovery is not victory.

One card, on purpose. Why nets in the second descent generalize - implicit bias, interpolation theory, the whole epistemology fight - is a parked course of its own on this hub. Tonight you get the curve, the caveat, and the live evidence. The debate gets its own room.

Build-along

The taming checklist

★ 20 min · everyone builds

The scenario is next session's exact setup: a churn MLP on 6 features and 200 training rows. You will price the nets, predict their fates, and prescribe - before session 6 reveals the measured answers.

Compute the parameter counts. 1x8: (6x8 + 8) + (8x1 + 1) = 56 + 9 = 65. 2x16: (6x16 + 16) + (16x16 + 16) + (16x1 + 1) = 112 + 272 + 17 = 401. 3x32: (6x32 + 32) + (32x32 + 32) + (32x32 + 32) + (32x1 + 1) = 224 + 1,056 + 1,056 + 33 = 2,369. Verify each sum yourself - the habit from session 1, now with stakes.

Write the params-per-row ratios. On 200 rows: 65/200 is about 0.3, 401/200 is about 2, 2,369/200 is about 12. One net cannot afford to memorize, one can memorize comfortably, one could memorize the dataset several times over. Circle the middle one - it is tonight's patient.

Predict each config's fate - train and holdout, in writing, before session 6 shows the measured numbers. Use tonight's two lessons: the 2x16 has the capacity and no medicine, and the biggest net is past the threshold. Sealed predictions get compared against the live showdown next week.

Order the medicine for the 2x16. More data is unavailable in the lab (the dataset is fixed at 200 rows), so: early stopping first - it is free and you already track validation - then smaller model or weight decay. Write the order and one reason per line.

Two sentences, your own words. First, the Zhang sentence - something like: "our nets can memorize anything, so the fact that they generalize is not explained by their size". Second, the double-descent meeting sentence: "bigger sometimes recovers - and it is not a license to skip regularization".

What to bring to session 6. Your sealed predictions from step 3. The showdown runs all three nets plus the tree course's booster on byte-identical data, and the most instructive number will be whichever one you got wrong.

Homework

Before session 6

30 min
  1. Recompute the three parameter counts from scratch without looking, then check against tonight. If any layer's count surprises you, draw it as neurons and count the arrows.
  2. Run the diagnosis on something real: find one train/validation curve pair at work (any model, any tool). Is the gap growing? Which shelf item would you reach for first, and why is it not the third one?
  3. Audit one training script (yours or a colleague's) for the Adam + L2 bug: if it uses Adam with an L2 penalty instead of AdamW with decoupled decay, you have found a real instance of tonight's Part 2(d).
  4. Write your prediction table for session 6: logistic baseline, 1x8, 2x16, 3x32, booster - five holdout guesses, committed on paper.
  5. Optional: read the first page of Zhang et al. (arXiv:1611.03530). The experiments are exactly as simple as tonight claimed - that simplicity is the paper's power.
Check yourself

Three questions

Clear all three and session 5 gets stamped in your passport.

1 · Zhang et al. showed state-of-the-art nets "easily fit a random labeling of the training data", barely changed by regularization. What does this prove - and not prove?

The same architecture that generalizes on real labels memorizes pure noise perfectly - so counting its capacity cannot be what separates the two outcomes. That is a negative result about the textbook theory, not about the nets: they demonstrably generalize on real data. The replacement explanation is active research, which is why this course hands the full debate to its own parked course.

2 · Why does AdamW exist, when Adam plus an L2 penalty was already standard?

Loshchilov and Hutter's exact framing: the two "are equivalent for standard stochastic gradient descent... but as we demonstrate this is not the case for adaptive gradient algorithms, such as Adam". Under Adam, weights with large gradient history get their L2 penalty shrunk by the adaptive scaling - the decay stops decaying where it matters most. Decoupled decay fixes it, which is why torch.optim.AdamW is today's default.

3 · A colleague says double descent "disproves the bias-variance trade-off". What did Belkin et al. actually claim?

The paper's word is "subsumes": the classical curve is the first half of a longer one, not a mistake. And the scope travels with the claim - the effect shows most clearly with label noise near the interpolation threshold, and it licenses neither "bigger is always better" nor skipping regularization. Session 6's measured version: 2x16 at holdout 60, 3x32 at 68, booster still at 73.

Sources covered

What this session teaches, and where it came from

✓Zhang et al., ICLR 2017 (CACM 2021)Nets "easily fit a random labeling"; unchanged by regularization; random pixels too - classical complexity measures shown insufficient, not generalization unexplainable
✓Srivastava et al. 2014, dropoutRandom unit dropping prevents co-adaptation; approximates averaging exponentially many thinned nets (approximation, not literal ensemble); modern home is FC heads + transformers
✓Loshchilov & Hutter, ICLR 2019, AdamWL2 = weight decay under SGD but not under Adam; decoupled decay substantially improves generalization; torch.optim.AdamW is the default
✓Belkin et al. 2019 + Nakkiran et al. 2019, double descentThe curve that subsumes the U; model-wise and epoch-wise; label-noise scope - teaser card only, the parked epistemology course owns the full debate
✓Karpathy, A Recipe for Training Neural Networks"Get more data - the by far best and preferred way to regularize a model in any practical setting" - the top of the cabinet

Every fact on this page, and its verification tier, is recorded in the course's source map.

Session 5 cheat sheet · pin this

The diagnosisTrain up, validation flat then drifting down. One look at the two curves; everything else is treatment.
The Zhang resultNets easily fit random labels, regularizers barely matter - so capacity counting cannot explain generalization.
The cabinet orderMore data, early stopping, dropout, weight decay, smaller model. Data fixes the disease; the rest manage it.
The AdamW ruleL2 = decay under SGD, NOT under Adam. Use torch.optim.AdamW; Adam + L2 is the quiet bug.
Double descent, scopedSubsumes the U; clearest with label noise near the interpolation threshold. Not a regularization amnesty.
The specimen's numbersOn 200 rows: 65 / 401 / 2,369 params = 0.3 / 2 / 12 per row. The middle one memorizes: train 100, holdout 60.