← Blog

What Is Grokking? A Formal Definition

Grokking refers to delayed generalization following overfitting: a model first memorizes its training data and only much later learns a rule that generalizes.

The term was introduced by Power et al. (2022) for neural networks trained on small algorithmic datasets. Our goal in this blog post is to provide a formal definition of grokking in line with the current state of the art on the subject. Let us begin with the standard example of addition modulo a prime, then make the definition precise.

Modular Addition

Let pp be a prime integer and Z/pZ\mathbb Z/p\mathbb Z is the set of residue classes modulo pp. We represent them by {0,,p1}\{0,\ldots,p-1\}, with addition wrapping around after p1p-1.. For xSx\in\mathcal S, the notation x{0,,p1}\langle x\rangle\in\{0,\ldots,p-1\} denotes its integer representative and therefore its token index. For x=(x1,x2)S2\mathbf x=(x_1,x_2)\in\mathcal S^2, define the label by y(x):=(x1+x2)modpy(\mathbf x) := \left\langle (x_1+x_2)\bmod p\right\rangle and the dataset by

D:={(x,y(x)):xS2}.\begin{equation} \begin{aligned} %y(\mathbf x) &:= \left\langle (x_1+x_2)\bmod p\right\rangle,\\ \mathcal D &:= \left\{ \bigl(\mathbf x,y(\mathbf x)\bigr) : \mathbf x\in\mathcal S^2 \right\}. \end{aligned} \end{equation}

We randomly split D\mathcal D into a training set Dtrain\mathcal D_{\mathrm{train}} and a test set Dtest\mathcal D_{\mathrm{test}} according to a ratio r:=Dtrain/D(0,1)r := |\mathcal{D}_{\text{train}}| / |\mathcal{D}| \in (0, 1).

Let ERp×d1\mathbf{E} \in \mathbb{R}^{p \times d_1} be the trainable embedding table for all the symbols in S\mathcal{S}, and let e(x):=Ex,:Rd1\mathbf e(x) := \mathbf E_{\langle x\rangle,:} \in \mathbb{R}^{d_1} be the embedding of token xSx \in \mathcal{S}. For x=(x1,x2)S2\mathbf x=(x_1,x_2)\in\mathcal S^2, the embeddings of x1x_1 and x2x_2 are added before being sent through the one-hidden-layer ReLU network. More specifically, the model is

zθ(x):=W(2)ReLU ⁣(W(1)[e(x1)+e(x2)]+b(1))+b(2)\begin{equation} \begin{aligned} \mathbf z_\theta(\mathbf x) &:= \mathbf W^{(2)} \operatorname{ReLU}\!\left( \mathbf W^{(1)}[\mathbf e(x_1)+\mathbf e(x_2)]+\mathbf b^{(1)} \right) +\mathbf b^{(2)} \end{aligned} \end{equation}

where the matrices W(1)Rd2×d1\mathbf W^{(1)}\in\mathbb R^{d_2\times d_1} and W(2)Rp×d2\mathbf W^{(2)}\in\mathbb R^{p\times d_2} are the hidden and output weights, while b(1)Rd2\mathbf b^{(1)}\in\mathbb R^{d_2} and b(2)Rp\mathbf b^{(2)}\in\mathbb R^p are their biases. Thus d1d_1 is the embedding dimension, d2d_2 is the hidden width, and zθ(x)Rp\mathbf z_\theta(\mathbf x)\in\mathbb R^p contains the class Logits are the model’s unnormalized class scores. Applying softmax turns them into probabilities; taking argmax\operatorname{argmax} selects the largest score directly.. Every array collected in θ:={E,W(1),b(1),W(2),b(2)}\theta := \{ \mathbf E,\mathbf W^{(1)},\mathbf b^{(1)},\mathbf W^{(2)},\mathbf b^{(2)} \} is optimized.

We train this model to minimize f(θ):=g(θ)+βθ22f(\theta):=g(\theta)+\beta\|\theta\|_2^2, where g(θ)g(\theta) is the average For a true class ii, cross-entropy is the negative log of the softmax probability assigned to ii. It strongly penalizes confident predictions of the wrong class. on Dtrain\mathcal{D}_{\text{train}}:

g(θ)=1Dtrain(x,y)Dtrain(zθ(x),y)\begin{equation} g(\theta) = \frac{1}{|\mathcal{D}_{\text{train}}|} \sum_{(\mathbf{x}, y) \in \mathcal{D}_{\text{train}}} \ell \left( \mathbf{z}_{\theta}(\mathbf{x}), y \right) \end{equation} (z,i):=logexp(zi)jexp(zj),zRp, i[p]\begin{equation} \ell \left( \mathbf{z}, i \right) := - \log \frac{ \exp\left( \mathbf{z}_i \right) }{ \sum_{j} \exp\left( \mathbf{z}_j \right)}, \qquad \forall \mathbf{z} \in \mathbb{R}^p, \ i \in [p] \end{equation}

For the following figure, we use (p,r)=(97,0.4)(p,r)=(97,0.4) and optimize f(θ)f(\theta) with Adam maintains moving averages of each parameter’s gradient and squared gradient, then uses them to adapt the update scale coordinate by coordinate., using a learning rate α=103\alpha=10^{-3} and penalty strength β=106\beta=10^{-6}. Source code: Tikquuss/grokking_algorithmic.

Training and test loss and accuracy during grokking on addition modulo 97
One run on addition modulo 97. The model reaches perfect training accuracy around t₁ ≈ 470, but test accuracy reaches the same level only around t₂ ≈ 9000.

The first transition is ordinary memorization. The striking part is the long interval during which training accuracy is perfect while test accuracy remains poor, followed by generalization without any new data.

A formal definition

Let θ(t)\theta^{(t)} denote the parameters after tNt\in\mathbb N optimization steps. The model optimization process can be divided into three consecutive phases when studying delayed generalization (see the figure above). The initial learning phase, t[0,t1/2]t \in [0,t_{1/2}], is called the confusion phase, during which both training and validation performance are poor. During the memorization phase, t[t1,t3/2]t \in [t_1,t_{3/2}], training performance is nearly perfect while validation performance remains low. During the comprehension phase, t[t3/2,)t \in [t_{3/2},\infty), validation performance improves and can eventually match training performance at step t2t_2. For a classification task such as the example above, t1/2t_{1/2} can be taken as the first step at which the training accuracy Atrain\mathcal{A}_{\text{train}} becomes strictly greater than 0%0\%; t1t_1 as the first step at which Atrain\mathcal{A}_{\text{train}} reaches 1\approx1; t3/2t_{3/2} as the first step at which the test accuracy Atest\mathcal{A}_{\text{test}} becomes strictly greater than 0%0\%; and t2t_2 as the first step at which Atest\mathcal{A}_{\text{test}} reaches 1\approx1.

The training of a deep-learning model by gradient descent generally, but not necessarily, goes through these phases. In the literature, training that ends in the confusion, memorization, or comprehension phase is referred to as underfitting, overfitting, or generalization, respectively.

More formally, define:

AB(t):=1B(x,y)B1 ⁣{argmaxj{0,,p1}[zθ(t)(x)]j=y}[0,1]\begin{equation} \mathcal A_{\mathcal B}(t) := \frac{1}{|\mathcal B|} \sum_{(\mathbf x,y)\in\mathcal B} \mathbf 1\!\left\{ \operatorname*{argmax}_{j\in\{0,\ldots,p-1\}} [\mathbf z_{\theta^{(t)}}(\mathbf x)]_j=y \right\} \in [0, 1] \end{equation}

for B{Dtrain,Dtest}\mathcal B\in\{\mathcal D_{\mathrm{train}},\mathcal D_{\mathrm{test}}\}. This is the accuracy after tt optimization steps. We write the two instances of Equation (3) as Atrain\mathcal A_{\mathrm{train}} and Atest\mathcal A_{\mathrm{test}}.

Fix a near-perfect accuracy threshold q(1/p,1]q\in(1/p,1]. The memorization and generalization times are

t1:=inf{tN0:Atrain(t)q},t2:=inf{tN0:Atest(t)q},\begin{equation} t_1:=\inf\{t\in\mathbb N_0:\mathcal A_{\mathrm{train}}(t)\geq q\}, \qquad t_2:=\inf\{t\in\mathbb N_0:\mathcal A_{\mathrm{test}}(t)\geq q\}, \end{equation}

where inf=\inf\varnothing=\infty. When both times are finite, the generalization delay is

Δtgen:=t2t1.\begin{equation} \Delta t_{\mathrm{gen}}:=t_2-t_1. \end{equation}

Definition Choose qq and a minimum relative delay κ>0\kappa>0 before looking at the trajectory. A run exhibits grokking when

0<t1<t2<,Δtgent1κ,Atrain(t)qfor every t1tt2.\begin{equation} \begin{gathered} 0<t_1<t_2<\infty, \qquad \frac{\Delta t_{\mathrm{gen}}}{t_1}\geq\kappa,\\ \mathcal A_{\mathrm{train}}(t)\geq q \quad\text{for every }t_1\leq t\leq t_2. \end{gathered} \end{equation}

The last condition distinguishes delayed generalization after memorization from two unrelated threshold crossings. The constant κ\kappa gives a precise meaning to a “long” delay; suddenness is common in grokking curves, but it is not part of the definition.

Remark For the sake of simplicity, many works studying grokking characterize all training experiments that eventually generalize as grokking, thereby avoiding a debate about what could be considered a trivial number of steps.

Remark The definition above is not fully general because it assumes an ideal context in which training progresses “smoothly.” It ignores The largest Hessian eigenvalue λmax(H(t))\lambda_{\max}(\mathcal H^{(t)}) increases during training, so the local loss landscape becomes progressively sharper. Cohen et al. (2021) observed it approaching the gradient-descent stability scale 2/αt2/\alpha_t., studied by Cohen et al. (2021), and the resulting When curvature is near or beyond the nominal stability threshold 2/αt2/\alpha_t, individual gradient-descent steps need not decrease the loss, even though the longer-run trajectory can continue to make progress.. It also ignores the The slingshot mechanism consists of cyclic transitions between relatively stable and unstable training regimes, often accompanied by spikes in loss or parameter norm. studied by Thilak et al. (2022). The phases must therefore be adapted to the context. Lyu et al. (2023) even observed In misgrokking, the model first generalizes and then, after a long training period, moves toward memorization and worse generalization—the temporal order is reversed..

From a run to a random regime

For a fixed choice HH of hyperparameters (e.g., learning rate, weight decay, and mini-batch size), the training split, initialization, minibatch order, and any stochastic optimizer choices make the trajectory random. Let ω\omega denote their joint outcome under a fixed experimental protocol, and write t1(ω)t_1(\omega), t2(ω)t_2(\omega), Δtgen(ω):=t2(ω)t1(ω)\Delta t_{\mathrm{gen}}(\omega):=t_2(\omega)-t_1(\omega), and Atrainω\mathcal A_{\mathrm{train}}^\omega for the corresponding quantities. The grokking event is

Gq,κ(H):={ω:0<t1(ω)<t2(ω)<,Δtgen(ω)/t1(ω)κ,Atrainω(t)q for every t1(ω)tt2(ω)}.\begin{equation} \mathsf G_{q,\kappa}(H) := \left\{ \omega: \begin{array}{l} 0<t_1(\omega)<t_2(\omega)<\infty,\\[2pt] \Delta t_{\mathrm{gen}}(\omega)/t_1(\omega)\geq\kappa,\\[2pt] \mathcal A_{\mathrm{train}}^\omega(t)\geq q \text{ for every }t_1(\omega)\leq t\leq t_2(\omega) \end{array} \right\}. \end{equation}

Grokking corresponds to Pgen ⁣[Gq,κ(H)]=1\mathbb P_{\mathrm{gen}}\!\left[\mathsf G_{q,\kappa}(H)\right]=1, where Pgen\mathbb P_{\mathrm{gen}} is the probability law of the random experiment. This is a statement about the full grokking event, not merely eventual test success. A finite collection of seeds can estimate its probability but cannot prove that it is one; a run stopped before t2t_2 is observed is We know only that the unobserved generalization time exceeds the stopping time. Treating such a run as if t2=t_2=\infty would confuse missing future observation with evidence of non-generalization., rather than evidence that t2=t_2=\infty.

Although it is easy to identify grokking, it is very difficult to give a formal definition of its opposite since, in practice, we cannot optimize a model for an infinite number of steps. In many cases, we do not even have access to the true data distribution Pdata\mathbb P_{\mathrm{data}} needed to properly define Pgen\mathbb P_{\mathrm{gen}}. Even if this distribution is available, exactly or approximately, computing Pgen ⁣[Gq,κ(H)]\mathbb P_{\mathrm{gen}}\!\left[\mathsf G_{q,\kappa}(H)\right] for a fixed choice of hyperparameters remains intractable given the complexity of the stochastic process defined by the optimization procedure, a complexity inherited in part from that of the model whose parameters are being optimized.

Faced with this challenge, we proceeded empirically in Notsawo et al. (2023). For models of the same family—that is, with the same architecture—and a given quantity of training data rr, we train several models with different hyperparameters and initializations. When all possible input-output pairs form a finite, tractable dataset, as in addition modulo a small prime integer, r[0,1]r\in[0,1] can instead denote the training-data fraction. We fit a function that predicts t2t_2, the generalization step, for each rr. Then, if for a given choice of hyperparameters, initialization, and rr, we train a model for more than the predicted t2(r)t_2(r) steps without generalization, we can stop training and report the outcome as confusion or memorization—that is, non-grokking—according to the observed training and validation performance. This corresponds to an empirical definition in which we use the Pgen\mathbb P_{\mathrm{gen}} is the ideal distribution over all runs allowed by the protocol. P^gen\widehat{\mathbb P}_{\mathrm{gen}} places equal mass on the finite runs actually observed and therefore only estimates that population law. instead of Pgen\mathbb P_{\mathrm{gen}}.

In general, more data leads to faster grokking: t2(r)t_2(r) is a decreasing function of rr, as reported by Power et al. (2022), Liu et al. (2023), Žunkovič and Ilievski (2022), and Gromov (2023). Some authors report a t2(r)=Θ(rγ)t_2(r)=\Theta(r^{-\gamma}) means that, up to constant factors, the generalization time scales like rγr^{-\gamma}. On logarithmic axes, this relationship appears approximately linear with slope γ-\gamma. (Žunkovič and Ilievski, 2022; Notsawo et al., 2023):

t2(r)=Θ ⁣(rγ),γ>0.t_2(r)=\Theta\!\left(r^{-\gamma}\right),\qquad \gamma>0.

This law generally breaks at a Below rcr_c, the available data do not identify the target well enough for the scaling law to continue. In inverse problems, this can coincide with an information-theoretic recovery threshold.: it is valid only for rrcr\geq r_c. In the toy model of Liu et al. (2023), rcr_c can be estimated using the quality of the representations learned by the model. For sparse recovery and matrix factorization problems, for which we recently proved the existence of grokking in Notsawo et al. (2025), this limit is the minimum number of measurements below which no recovery is possible by any method whatsoever; see, for example, Rauhut (2010) for sparse recovery and Candès and Recht (2012) for matrix completion.

The three phases

This definition separates a grokking trajectory into three phases:

PhaseOptimization stepsBehaviour
Confusiont<t1t<t_1The model has not yet fit the training data.
Memorizationt1t<t2t_1\leq t<t_2Training accuracy is high, but test accuracy is still low.
Comprehensionat t2t_2Training and test accuracy both meet the threshold qq; in a typical grokking trajectory, they remain high afterwards.

Taking q=1q=1 for the curve above gives Δtgen8530\Delta t_{\mathrm{gen}}\approx8530: the memorization phase lasts much longer than the initial fitting phase.

Liu et al. (2023) used the terms confusion, memorization, and comprehension in a phase diagram based on different hyperparameters. In this post, we also use them to refer to phases along a single training trajectory, as defined above.

It is common in the deep-learning literature to divide neural-network optimization into The usual picture has an initial fitting phase with a small generalization gap, followed by overfitting as test error rises. Grokking requires a different temporal pattern: a prolonged memorization interval followed by improved generalization. (Shwartz-Ziv and Tishby, 2017; Nakkiran et al., 2020; Feng and Tu, 2021). However, Nakkiran et al. (2020) show that in some regimes the test error decreases again and can reach a lower value at the end of training than at the first minimum, suggesting potential training phases to exploit. Feng and Tu (2021) distinguish an initial fast-learning phase, in which the loss decreases quickly and sometimes abruptly, followed by an exploration phase, in which the training error has reached its minimum and the overall loss continues to decrease, but much more slowly and gradually. The defining ingredient of grokking lies in the memorization phase and in the transition from memorization to generalization.

Remark The definition of grokking evolved between 2024 and 2025. Initially, grokking, as observed by Power et al. (2022), corresponded to a sudden transition from a long phase of perfect memorization to generalization. Over time, however, the term has evolved to the point where, when a model generalizes late—whether abruptly or gradually—some authors refer to it as grokking. This is the case in Wang et al. (2024) and Abramov et al. (2025), who show that grokking enables Transformers to develop reasoning abilities that emerge only after extended training, whether on synthetic comparison or composition tasks or on real-world multi-hop reasoning augmented with inferred facts.

In general, this type of “reasoning” task exhibits a typical progression during training: training and test performance improve similarly from the beginning of training until the model reaches a more or less acceptable level of generalization. Then, when the model is trained for longer, a gradual increase in generalization performance is observed. We will return to this type of grokking in a future post. This seems to be the best kind of grokking we can have on “real,” non-synthetic tasks.

Accuracy is not always the right observable

Accuracy is natural for modular arithmetic, but it is only one possible observable. A smooth change in the logits can look abrupt after taking an argmax\operatorname{argmax}, so loss curves should be shown as well. In regression, signal recovery, or matrix completion, the same definition can use predeclared error tolerances instead of accuracy thresholds.

In contexts where accuracy is not directly available, such as regression, one can use the value L\mathcal L of the loss function directly, so that “A1.0\mathcal A\approx1.0” becomes “L0\mathcal L\approx0.” Alternatively, following Liu et al. (2023), one can define accuracy as the empirical fraction of points whose prediction error is smaller than a chosen tolerance ϵ0\epsilon\geq0:

A(data):=E^zdata1 ⁣{(z)ϵ}=P^zdata[(z)ϵ],\mathcal A(\mathrm{data}) := \widehat{\mathbb E}_{z\sim\mathrm{data}} \mathbf 1\!\left\{\ell(z)\leq\epsilon\right\} = \widehat{\mathbb P}_{z\sim\mathrm{data}} [\ell(z)\leq\epsilon],

where (z)\ell(z) is the value of the loss function on the sample zz. Here E^\widehat{\mathbb E} and P^\widehat{\mathbb P} average over the finite dataset, while 1{(z)ϵ}\mathbf 1\{\ell(z)\le\epsilon\} equals 11 when the tolerance is met and 00 otherwise. Their average is therefore the fraction of successful samples. turn a continuous error into an empirical accuracy.

It should be noted that the transition in L(t)\mathcal L(t) is generally not as sharp as the transition in A(t)\mathcal A(t), and it is possible to observe a transition in A(t)\mathcal A(t) without observing one in L(t)\mathcal L(t), as shown by Kumar et al. (2023). It is preferable to study grokking using loss rather than accuracy: loss reflects the training dynamics, whereas accuracy is discontinuous and can exhibit apparent transitions without any internal change in the model. As Kumar et al. (2023) point out in the context of grokking, hard-threshold measures of performance such as accuracy can be extremely misleading; continuously optimized measures such as loss should be studied instead (Schaeffer et al., 2024).

The observable must match the scientific question. In sparse recovery, A small residual means the estimate matches the observed measurements. A small recovery error means it is close to the unknown latent signal. With insufficient or ambiguous measurements, the former can be tiny while the latter remains large.. Confusing the two can produce what we call grokking without understanding in the next post.

What to report

A grokking experiment should report:

  • the task, split, model, optimizer, and regularization;
  • the observable and the chosen values of qq and κ\kappa;
  • the training and test curves, together with t1t_1, t2t_2, and Δtgen\Delta t_{\mathrm{gen}} across seeds.

With these choices fixed, grokking is no longer just the shape of one attractive curve. It is a measurable event: rapid memorization, a non-trivial delay, and eventual generalization.

References

Cite this post

If you would like to cite this post, you can use the following BibTeX entry:

@misc{tikengnotsawo2025whatisgrokking,
  author = {Tikeng Notsawo, Pascal Jr.},
  title = {{What Is Grokking? A Formal Definition}},
  year = {2025},
  month = may,
  url = {https://tikquuss.github.io/blog/what-is-grokking/},
  note = {Blog post}
}