Grokking in the Wild: Data Augmentation for Real-World Multi-Hop Reasoning with Transformers

Roman Abramov, Felix Steinbauer, Gjergji Kasneci

TL;DR

"Grokking"—the phenomenon where a neural network suddenly transitions from memorizing data to perfectly generalizing after prolonged training—has long been confined to toy, synthetic datasets. This paper demonstrates that by strategically augmenting real-world knowledge graphs to boost the ratio of inferred to atomic facts, we can induce grokking in a standard GPT-2 model, allowing it to match or outperform massive models like GPT-4o on multi-hop reasoning tasks.

What Problem Does This Paper Address?

Transformers excel at memorizing facts but notoriously struggle with multi-step (multi-hop) factual reasoning. Recent deep learning research identified a potential remedy called grokking, where overparameterized models suddenly discover underlying logical circuits long after overfitting.

However, grokking has historically only worked on highly controlled, toy datasets (like modular arithmetic). Real-world data is inherently sparse; in a typical knowledge graph, the ratio ($\phi$) of complex, inferred facts to simple, atomic facts is too low. Without a high enough density of these higher-order patterns, a Transformer defaults to lazy memorization rather than forming internal "generalizing circuits."

Methods

The authors propose a two-stage pipeline to bring grokking into real-world NLP:

  1. Targeted Data Synthesis: They mathematically formalize the relation-specific generalization ratio $\phi_r$ (inferred facts divided by atomic facts). To push $\phi_r$ past the empirical threshold required for grokking (typically between 3.6 and 18), they use an LLM-based data augmentation strategy (using GPT-4o and o1-mini) to inject new synthetic atomic edges and sample multi-hop paths.
  2. Prolonged Training: They train a modest 8-layer GPT-2 small model (124M parameters) from scratch for up to 300,000 steps, waiting for the characteristic delayed surge in out-of-distribution (OOD) accuracy that signals grokking.
Figure 3. Conceptual difference between ID and OOD: In- distribution (ID, orange) and Out-of-distribution (OOD, red) in- ferred facts are shown. All green components are seen during training, including all atomic facts (AF) and some inferred facts (IF).

Datasets

The approach is evaluated on 2WikiMultiHopQA, a benchmark featuring Wikipedia-based queries that require chaining multiple pieces of evidence. The authors split the dataset into two subsets:

  • Structured: Supporting facts are simplified into clean triplets (e.g., Paris -- country -- France).
  • Unstructured: Supporting facts are embedded within full, noisy Wikipedia paragraphs.

They focus specifically on Comparison tasks (e.g., "Are City A and City B located in the same country?") and Composition tasks (e.g., "Who directed the sequel of film X?").

Key Insights and Ideas

  • Grokking is Not Just an Algorithmic Artifact: With proper data distribution adjustments, real-world textual data can trigger the exact same sudden generalization circuits seen in toy mathematical datasets.
  • The Power of "Incorrect" Data: Surprisingly, the augmented synthetic data does not need to be factually true. Injecting factually incorrect relational data actually strengthens the emergent reasoning circuits because it forces the model to rely on abstract relational structure rather than memorizing specific real-world facts.
  • OOD is the True Litmus Test: Models easily achieve near-100% In-Distribution (ID) accuracy through memorization. True structural generalization is only proven when the model successfully reasons over entirely unseen combinations of atomic facts (OOD).

Key Results

  • Beating the Giants: On the structured comparison task, the Grokked GPT2-small achieved an incredible 96% OOD accuracy, soundly beating state-of-the-art models like GPT-4o (25%) and o1-mini (32%) which lack explicit grokking dynamics in this setup.
Figure 1. Average accuracy on 2WikiMultiHopQA for comparison task. Despite GPT2-small being a model with 124 million parame- ters, grokked version achieves almost 100% accuracy, beating the most recent gpt-4o and o1-mini models.
  • Composition Limits: While comparison tasks grokked beautifully, composition tasks proved much harder. GPT2-small reached near-perfect ID accuracy but flatlined at 7% OOD accuracy, showing that complex multi-hop chaining requires even more substantial or targeted data augmentation.
Figure 4. (a) Accuracy on the comparison task for original and grokked GPT2-small on OOD-test set. We can observe that the OOD accuracy remains almost the same when it reaches 100%, but the difference becomes evident afterward. The grokked transformer continues to improve in accuracy as training progresses, unlike the original version. (b) Training curves for the structured comparison task. IID and OOD behave similarly. (c) The structured compositional task. We see near-perfect ID accuracy but no late-phase jump in OOD test accuracy. (d) Training curves for the unstructured (full paragraph Wikipedia) comparison setting. Complexity slows convergence and limits OOD gains, although ID accuracy still improves significantly.

Limitations and Future Work

  • Complexity and Noise: Grokking was significantly hindered in unstructured text settings due to text distractors and a lower effective $\phi$ ratio, showing that text complexity delays circuit formation.
  • Factual Drift: Relying on hallucinated synthetic data introduces a risk of "factual fragility," where the model might overwrite or obscure genuine real-world knowledge.
  • High Compute Overhead: Training models for hundreds of thousands of steps to reach the grokking phase is computationally expensive. The authors suggest exploring accelerated convergence techniques (like Grokfast) or initializing with pre-trained models to mitigate this cost.

Summary updated

BibTeX
@inproceedings{abramov2025grokking,
  author = {Roman Abramov and Felix Steinbauer and Gjergji Kasneci},
  title = {{Grokking in the Wild: Data Augmentation for Real-World Multi-Hop Reasoning with Transformers}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=lyUJH51URt},
}
Figure