Grokking is a training phenomenon in which a neural network first memorizes its training data, reaching near-perfect training accuracy while test accuracy stays low, and then, after many more optimization steps, suddenly generalizes to unseen examples. In artificial intelligence research on Training, it is also called delayed generalization, because the gap between fitting the data and understanding the underlying rule can span thousands or even millions of steps.
The effect was first described in 2022 by researchers who trained small transformers on algorithmic tasks such as modular arithmetic. The word comes from the novel Stranger in a Strange Land, where to grok means to understand something completely. Grokking matters because it shows that training loss alone can hide a model’s progress toward a general solution.
How grokking unfolds during training
Grokking follows a recognizable sequence of phases that appear clearly in plots of training and validation accuracy against optimization steps. The training curve saturates early, the validation curve stays near chance for a long plateau and then rises sharply to near-perfect accuracy.
The table below summarizes the phases that interpretability studies of modular addition have identified.
| Phase | Training accuracy | Validation accuracy | What happens inside |
|---|---|---|---|
| Memorization | Rises to about 100% | Near chance | Network stores input-output pairs |
| Circuit formation | Stays near 100% | Still low | A general algorithm grows in the weights |
| Cleanup | Stays near 100% | Jumps to near 100% | Memorizing weights decay away |
| Stable generalization | About 100% | About 100% | Compact solution dominates |
Mechanistic analyses showed that a transformer learning addition modulo a prime builds a Fourier-based algorithm, representing numbers as rotations and combining them with trigonometric identities. The jump in test accuracy happens when this general circuit outweighs the memorized lookup table, not when it first appears.
Why delayed generalization happens
The leading explanation treats grokking as a competition between two solutions that both fit the training data. Memorization is found quickly but needs large weights, while the general solution is harder to find but more efficient in parameter norm. Regularization slowly tilts the balance toward the efficient solution.
- Weight decay penalizes large weights and is the most reliable trigger of grokking in published experiments.
- Small training fractions make memorization easy and lengthen the plateau before generalization.
- Initialization scale matters: large initial weights push models toward memorization first.
- Optimizer dynamics, including late loss spikes sometimes called the slingshot effect, can coincide with the transition.
Later work extended the effect beyond toy arithmetic to image classification, sentiment analysis and molecular data when initialization and regularization were adjusted. Whether large language models grok specific skills during pretraining remains an open research question with suggestive but incomplete evidence.
Grokking compared with related training phenomena
Grokking is often confused with other effects that also involve non-monotonic generalization. The distinguishing feature is the axis: grokking unfolds over training time on a fixed dataset, while the others usually vary model size or data size.
| Phenomenon | Varied quantity | Characteristic pattern |
|---|---|---|
| Grokking | Optimization steps | Late, sudden jump in test accuracy |
| Double descent | Model size or epochs | Test error rises, then falls again |
| Overfitting | Optimization steps | Test error rises and stays high |
| Emergent abilities | Model scale | Skill appears abruptly at larger scale |
| Neural scaling laws | Compute, data, parameters | Smooth power-law loss decrease |
The comparison with overfitting is the most practical one. A classic training run that shows a widening gap between training and validation loss is usually stopped early, yet grokking demonstrates that a widening gap is not always permanent when strong regularization is present.
Practical implications for training runs
Grokking has direct consequences for training decisions, especially for small models trained on structured or synthetic data. The following decision table shows how practitioners typically respond.
| Situation | Recommended choice | Reason |
|---|---|---|
| Training accuracy saturated, validation flat | Continue training with weight decay | Generalization may still arrive |
| Strict compute budget | Use early stopping | Grokking time is unpredictable |
| Small algorithmic dataset | Increase weight decay or data fraction | Shortens the memorization plateau |
| Need to detect progress early | Track weight norm and probes | Internal circuits form before test gains |
Researchers monitor progress measures such as the total weight norm, the restricted loss of the general circuit or linear probes on hidden activations. These signals often change smoothly long before validation accuracy moves, which shows that the apparent suddenness partly reflects the choice of metric.
Limitations and common misconceptions
Grokking is a well-documented but narrow phenomenon, and several popular claims about it go beyond the evidence. It appears most clearly on small, clean datasets with a precise underlying rule and strong explicit regularization.
- Not a guarantee: training longer does not make every overfitted model generalize.
- Not purely sudden: internal progress is gradual even when accuracy jumps.
- Not proof of understanding: a generalizing circuit implements a rule, not human-like comprehension.
- Not free: the extra steps can cost ten to a hundred times the compute needed to memorize.
A further caution concerns reproducibility across settings. The length of the plateau depends strongly on the random seed, the learning rate, the optimizer and the exact data split, so a single run says little about another configuration. Published results also rely on datasets with a known ground-truth rule, which makes it possible to verify that the model generalizes. In messy real-world data, the boundary between memorized patterns and a learned rule is far less clear, and claims that a production model grokked a capability should be treated with skepticism unless they are supported by controlled experiments and interpretability evidence.
The idea in brief
Grokking is when a model learns by rote first and understands later. At the start, it remembers every practice answer. It still fails on new questions.
Training continues, and the model is pushed to keep its settings small. Slowly, it finds the real rule behind the answers. Then, almost at once, it starts solving new questions correctly. A student who memorizes a times table and later sees the pattern behind it goes through a similar change.
A practical scenario
A research team trains a two-layer transformer to compute addition modulo 97, using 30% of all possible number pairs for training and the rest for validation. They use the AdamW optimizer with a weight decay of 1.0. After about 1,000 steps, training accuracy reaches 100%, while validation accuracy stays below 5%.
Instead of stopping, the team keeps training and logs the total weight norm. The norm declines steadily for tens of thousands of steps, and then validation accuracy climbs from near zero to above 99% within a short window. Inspection of the embeddings reveals periodic Fourier features, confirming that the model replaced its lookup table with a general algorithm. A repeat run without weight decay never generalizes within the same budget.