A Worked Example of Why Models Memorise Before They Generalise
Grokking is not magic: it is a slow trade between fitting the training set exactly and finding a rule that actually compresses it. Here is the mechanism, with numbers.
The puzzle worth taking seriously
Train a small network on a lookup table and something strange keeps happening. Training accuracy hits 100% almost immediately. Validation accuracy stays near chance for a long time, sometimes thousands of epochs, then suddenly climbs to near 100% too. Nothing dramatic changes in the loss curve before that jump; the training loss has been flat near zero the whole time. This phenomenon has been called grokking, and it is a clean illustration of a general truth: memorisation is easy and fast, generalisation is hard and slow, and a network will happily do the easy thing first unless something pushes it towards the hard thing.
This matters for anyone building and evaluating models, not just for people studying toy arithmetic tasks. If you stop training the moment your training metric looks perfect, or if you judge a model's quality from training curves alone, you can be fooled into thinking you have a working rule when you actually have an elaborate lookup table. The worked example below is deliberately small so the mechanism is visible, but the lesson generalises to anything from tabular classifiers to language models fine-tuned on narrow datasets.
A concrete task: modular addition
Suppose the task is to learn addition modulo 97. Inputs are pairs of integers from 0 to 96, the output is their sum mod 97, and we train on, say, 60% of the roughly 9,409 possible pairs, holding out the rest for validation. A small transformer or MLP with an embedding layer has more than enough parameters to simply memorise the 5,645 or so training pairs outright. It can build an internal lookup table: embedding for input A, embedding for input B, a dense mapping to the correct output, with no shared structure between different values of A.
Early in training, this is exactly what happens. The loss drops fast because fitting 5,645 arbitrary associations is a well-posed optimisation problem for a network with tens of thousands of parameters. Training accuracy reaches 100% within a few hundred steps. But the held-out pairs, the roughly 3,764 combinations the network never saw, remain wrong at a rate consistent with random guessing, because a memorised lookup table has no reason to interpolate correctly to unseen pairs. The network has fit the data perfectly without learning that addition is commutative, or that there is a consistent cyclic structure underneath, because neither property was ever rewarded during the first phase of training.
The network keeps training, usually with weight decay or some other regularisation pressure. This is the part that is easy to miss. The training loss is already near zero, so the gradient signal from the data term is small and noisy. But weight decay is still pulling every weight towards zero, continuously, every step. The lookup-table solution, built from many large, idiosyncratic weights, is expensive under that penalty. A solution that represents the numbers using something like sinusoidal or circular embeddings and computes the sum via a small number of shared, reusable operations is cheaper: fewer effective parameters doing more work. Over thousands of further steps, the optimiser slowly reshapes the memorised solution into the structured one, because the structured one sits in a flatter, lower-norm region of the loss landscape that still achieves zero training loss.

Why the mechanism matters beyond arithmetic
The general principle is that for a fixed training loss of zero, there are many solutions, and they are not equally good. Memorised solutions typically require a large number of specific, high-magnitude weights because every example is handled as a special case. Generalising solutions require fewer, more reusable weights because they exploit structure shared across examples. If your objective only measures training loss, both solutions look identical. The moment you add a term that prices in weight magnitude, sparsity, or some other notion of simplicity, you create a slope that favours the generalising solution, but descending that slope can take far longer than reaching zero training loss in the first place.
Consider a more mundane analogue: a classifier trained on a dataset of 2,000 labelled product reviews with heavy class imbalance, fine-tuned for 40 epochs. By epoch 5 the training accuracy is at 99%. If validation accuracy is also high at epoch 5, that is reassuring, but it is not proof the model has learned sentiment rather than a handful of superficial correlations, like particular brand names appearing more often in one class. If training continues and validation accuracy keeps inching upward through epoch 30 while training loss stays flat, that slow climb is the same phenomenon: regularisation and the implicit bias of stochastic gradient descent are gradually favouring representations that transfer, over representations that merely fit.
This is also why early stopping on a validation set, chosen purely by watching training loss plateau, can be a mistake in either direction. Stop too early and you might cut off the slow climb towards a genuinely useful representation. Keep training blindly without a validation check and you might never notice that the apparent improvement on held-out data has stalled or reversed, because memorisation of noise in a larger dataset can also continue to improve training metrics without helping generalisation at all.
What to actually do about it
First, never trust a training curve alone to tell you whether a model generalises. Hold out data properly, with a split that respects whatever leakage risk exists in your domain, whether that is time, users, or near-duplicate examples, and watch that held-out metric through the full training run, not just at the point where training loss flattens.
Second, if you suspect your task has learnable structure, be patient with regularisation rather than removing it the moment training loss looks stuck. Weight decay, dropout, or data augmentation are often doing their most important work after the training loss has already converged, not before. Cutting a training run short because the training loss curve looks boring can mean stopping during exactly the slow, unglamorous phase where a lookup table is being reshaped into a rule.
Third, treat suspiciously fast convergence as a prompt for scepticism rather than celebration, especially on small or narrow datasets. If a model reaches near-perfect training accuracy in a handful of steps, ask what it would take for that to be a real pattern versus an easily memorised shortcut, and check behaviour on inputs designed to break shortcuts specifically, not just on a random held-out split drawn from the same distribution. Memorisation and generalisation can look identical on the training set by construction; the only way to tell them apart is to look somewhere the model was never allowed to peek.
