TL;DR
Power and colleagues trained small transformers on tables of arithmetic-like facts, such as "a dot b equals c", where every symbol is an unlabelled token with no visible structure. The networks memorised the training entries within a few thousand updates, then stayed at chance on unseen entries for a very long time. In some settings, validation accuracy rose from chance to perfect long after overfitting, a pattern they named grokking. The lesson is that memorisation and generalisation can happen on separate clocks, and that weight decay can speed up the second.
Builds on: Transformer, Group (Abstract Algebra), AdamW Optimizer · Leads to: none in the graph yet
Why it mattered
Grokking changed how researchers think about overfitting. The usual rule is that once a model fits its training set and its validation score stops improving, more training only makes things worse. The paper showed a clear counterexample on a dataset small enough to run on one GPU. Its datasets became a standard testbed for studying generalisation: the question of why an overparameterised network generalises at all, when it has enough capacity to memorise. Follow-up work on the phenomenon used these tasks, and the paper's central tools (weight decay as a driver of generalisation, and a focus on the optimisation clock instead of only the data size) have been reused in later studies of how networks find simple, structured solutions.
The problem
Classical learning theory says that a model with many more parameters than data points should overfit, and that test error should rise as capacity grows. Practitioners know a milder version: after the validation loss stops falling, it usually stays flat or rises. A double descent in test error, where error rises, falls and rises again as the model grows, was already documented, but it was seen as unusual.
The difficulty is that natural datasets mix memorisation and pattern learning, so it is hard to say what the network has learned. The paper's idea is to remove that mess. Build a dataset from a rule that is fully known, make the symbols meaningless, and then check whether the network has found the rule. Once the rule is known, you can tell memorising from generalising exactly, because the unseen entries are either predictable from the rule or they are not.
How it works
The setup has four parts: the data, the model, the training, and the measurement.
- Pick a rule. Take a binary operation, for example division modulo the prime 97, written as . A table with every pair of the 97 residues has at most 97 times 97, or 9409, entries.
- Hide the structure. Give each residue its own abstract symbol and never show the network the number it stands for. The network sees a token for "a", a token for the operator, a token for "b", a token for "=", and a token for the answer "c". It has to learn what the symbols do from the equations alone.
- Hold out part of the table. Train on a random 50 percent of the 9409 equations and test on the rest. Each entry is a small "fill in the blank" problem, like one cell in a Sudoku grid.
- Train a tiny transformer and watch two curves. The model is a decoder-only transformer with 2 layers, width 128 and 4 attention heads, about non-embedding parameters. Loss and accuracy are measured only on the answer token. Training accuracy hits nearly 100 percent within about updates. Validation accuracy stays at chance for a long time, then climbs toward 100 percent, after roughly updates.
A toy version with the same shape makes the logic concrete. Take addition modulo 3, a table with 9 cells, and show the network 5 of them. The 5 training cells can be memorised outright. The 4 unseen cells can only be answered by finding that the table follows a rule. A network that has only memorised will guess on those 4 cells, which for a 3-symbol answer is about one chance in three. A network that has found the rule gets all 4 right.
flowchart LR A["Binary operation table"] --> B["Split: 50 percent train, 50 percent validation"] B --> C["Train tiny transformer on train equations"] C --> D["Train accuracy reaches near 100 percent quickly"] C --> E["Validation accuracy stays at chance"] E --> F["Long plateau of optimisation steps"] F --> G["Sudden rise to near 100 percent validation accuracy"]
The paper also measures how much optimisation a given dataset needs. On the group of permutations of five objects, , the number of steps to reach 99 percent validation accuracy rises steeply as the training fraction falls, so there is a fraction below which the time becomes very long.
The math
Definition (the task). Let be a finite set of symbols and a binary operation on . The full dataset is the set of all triples . A training set is a random subset of these triples, and the validation set is the complement. Accuracy on a split is the fraction of its triples for which the network's most likely answer is the correct .
Step 1 in symbols (the table). For modular division with prime , is the residues , and the number of triples is at most . Half of them are training triples and half are validation triples, so a random guess scores about , roughly 1 percent.
Step 2 in symbols (the model). The input is the token sequence and the model must produce . A causal transformer outputs a distribution over the answer symbols. The training loss is the usual Cross-Entropy Loss on the answer position:
The loss approaches zero only when each training answer has probability near 1, and the network can reach that with an arbitrary lookup table. That is why training loss can fall to zero without any generalisation.
Step 3 in symbols (weight decay). The paper's default optimiser is AdamW Optimizer with learning rate and weight decay . Each update is
where is the usual adaptive gradient step. The middle term shrinks every weight toward zero, a pull that the gradient does not cancel. As a number: with , the decay part alone multiplies each weight by per update. Over 1000 updates that is , so a weight that the gradient does not refresh shrinks to about a third of its size. The ablations in the Results section treat this decay as the key regulariser, and it pushes the network toward small-weight solutions.
Step 4 in symbols (the clock). The paper measures the number of updates needed to reach 99 percent validation accuracy, as a function of the training fraction . The reported finding is that rises sharply as falls near the minimum fraction that generalises at all, and that the converged accuracy stays at 100 percent over a range of . In other words the limit is on time, not on final accuracy.
Interpretation of the symmetry result. For a prime , every nonzero residue is a power of a primitive root , so multiplication modulo becomes addition of exponents modulo . This is why and are the same task up to renaming. A network that sees only abstract symbols cannot tell the two apart, so the symmetry argument predicts similar data needs for both.
Results
The main experimental results, using the paper's numbers:
- Delayed generalisation. On modular division, training accuracy is near perfect before updates, and validation accuracy shows little sign of generalisation before . It reaches near-perfect accuracy close to updates, about 1000 times later than training accuracy.
- Data efficiency. Across binary operations, most generalise once a sufficient fraction of the table is seen. Some operations did not generalise within the training budget at the fractions tried, and their models only memorised the training set.
- Regularisation. On , weight decay had the largest effect on data efficiency among the interventions compared. Other tested interventions helped less, and the learning rate had to be tuned within a narrow window.
- Embeddings. t-SNE projections of the output layer show structure in networks that generalise. For modular addition the points form a circle, which is the cyclic-group picture of the problem. For the points cluster into cosets of a subgroup. The structure is clearer in networks trained with weight decay.
The limits are important. The datasets are tiny and the models are two-layer transformers. Some configurations did not reach perfect generalisation within the budget. The paper states the phenomenon and its drivers, and it does not explain the mechanism fully. The embedding visualisations are suggestive, and the authors do not claim they prove a particular solution has been found.
Reading guide
Read the paper in this order, with the lessons each section needs:
- Introduction. Needs Overfitting and Double Descent. The main figure, showing the training and validation curves, is the central picture.
- Method and task definitions. Needs Group (Abstract Algebra) for the group-based tasks and Modular Arithmetic for the division and addition tables.
- Model and optimisation details. Needs Transformer, AdamW Optimizer and L2 Regularization. Use the hyperparameters here to check the weight decay story in the Math section.
- Generalisation beyond overfitting. Needs Train, Validation and Test Sets for the held-out evaluation.
- Learning time curves. Needs Cyclic Group for the task.
- Other problems. Needs Word Embedding for the symbol vectors. The symmetry argument uses the fact that multiplication modulo a prime is addition of exponents.
- Ablations. Needs Dropout (residual dropout), Stochastic Gradient Descent (minibatch and full-batch) and L2 Regularization. The weight decay result is the main practical lesson.
- Discussion. Read with the Cross-Entropy Loss lesson for the loss, and with Understanding deep learning requires rethinking generalization for the wider context on generalisation in deep networks.
Check yourself
QuestionIn the grokking setup, why can the training loss reach zero without the network having learned the rule?Show answer
The network can store each training equation as a separate lookup. Cross-entropy is zero only when each training answer gets probability near 1, and a lookup table does that without any pattern. Generalisation requires the unseen equations to be correct, and that is a separate test.
QuestionA table of addition modulo 3 has 9 cells, and 5 are used for training. How many unseen cells must the network answer correctly to be said to have generalised on all of them, and what accuracy would a pure guesser reach on those cells?Show answer
There are 9 minus 5 = 4 unseen cells. Generalising means answering all 4 correctly, which is 100 percent validation accuracy on this split. A guesser over the 3 answer symbols has about 1 chance in 3, so its expected accuracy is about one third.
QuestionWith learning rate 0.001 and weight decay 1, the decay term alone multiplies each weight by 0.999 per update. Roughly how much is a weight that gets no gradient reduced after 2000 updates?Show answer
The factor is 0.999 raised to the 2000th power, which is about e to the minus 2, or roughly 0.135. The weight shrinks to about one seventh of its original size. This ignores the Adam step, which is the setting where weight decay acts alone.
QuestionWhy does the paper say that multiplication modulo a prime p and addition modulo p minus 1 look the same to the network?Show answer
For a prime p, every nonzero residue is a power of a primitive root g. Multiplying residues then adds their exponents, so the exponents add modulo p minus 1. Because the network sees only abstract symbols, the two tasks differ only by renaming the symbols, so the symmetry argument predicts similar data needs.
Sources
- Power et al., Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets, arXiv:2201.02177. arxiv.org/abs/2201.02177
- DOI for the same paper: doi.org/10.48550/arXiv.2201.02177