Topological Signatures of Grokking

Yifan Tang, Qiquan Wang, Inés García-Redondo, Anthea MonodarXiv 2026

TL;DR

This paper investigates "grokking"—the sudden transition from memorization to perfect generalization in neural networks—through the lens of Topological Data Analysis (TDA). By tracking persistent homology during training, the authors discover a distinct topological signature: a sharp rise in 1-dimensional loop structures ($H_1$ persistence) that perfectly tracks the onset of generalization. This approach provides a unified, multi-scale geometric framework to observe how networks internalize the latent structure of a task.

What Problem Does This Paper Address?

Deep neural networks occasionally exhibit a puzzling training dynamic called grokking. When training on certain structured tasks, a model will quickly overfit and memorize the training data (achieving 100% train accuracy but poor test accuracy). Then, after prolonged and seemingly redundant training steps, it abruptly "groks" the problem, and test accuracy shoots up to near-perfection.

While researchers have proposed various diagnostics to track this phase transition—such as Fourier analysis or tracking the intrinsic dimensionality of representations—we still lack a complete understanding of the global geometric structure that emerges when a network generalizes. This paper addresses that gap by using topology to visualize and quantify how a network reorganizes its internal representation space from an unstructured cloud into a coherent geometric shape.

Methods

The authors employ Persistent Homology (PH), a core tool from Topological Data Analysis. PH treats neural network representations (like token embedding matrices or hidden states) as point clouds in a high-dimensional space.

  1. Vietoris–Rips Filtration: The algorithm grows hyperspheres around each data point by increasing a distance threshold ($\epsilon$). When spheres overlap, edges and higher-dimensional shapes (simplices) are formed.
  2. Persistence Diagrams: The method tracks when topological features are born and when they die (fill in) as $\epsilon$ grows. The authors focus on:
  3. $H_0$ features: Connected components (clusters).
  4. $H_1$ features: 1-dimensional loops or cycles.
  5. Comparative Diagnostics: The authors compare PH against Local Intrinsic Dimension (LID) (using the TwoNN estimator to measure representation compression) and Fourier Analysis (to capture frequency-domain representations).
  6. Temporal Analysis: They use a cross-correlation function (CCF) to determine the exact timing and lag between changes in test accuracy and changes in topological structure.

Datasets

  • Modular Addition: The primary benchmark is the classic algorithmic task $(a + b) \pmod p$ for prime numbers $p \in \{113, 149, 197\}$. Models are trained on small fractions ($\alpha \in \{0.20, 0.25, 0.30\}$) of the total data.
  • Label-Permuted Controls: A control dataset where training labels are randomly shuffled (from 0% to 100% corruption) to force pure memorization and prevent grokking.
  • MNIST: Used as a counter-example representing real-world data with a highly heterogeneous, non-cyclic underlying geometry.

Key Insights and Ideas

  • The $H_1$ Topological Signature: When a model groks modular arithmetic, its embedding space undergoes a dramatic phase transition, forming a prominent, long-lived 1-dimensional loop ($H_1$). This perfectly mirrors the cyclic nature of clock arithmetic ($\mathbb{Z}/p\mathbb{Z}$).
  • Complementary to Intrinsic Dimension: While LID shows that the representation space compresses drastically during grokking, it cannot describe the shape of the compressed manifold. PH fills this gap, proving that the network compresses the data specifically into a global loop structure.
  • Two-Stage Learning in Transformers: Cross-correlation analysis revealed a ~1,000-step temporal lag in Transformers: the model first learns the correct algorithmic mapping (test accuracy spikes), and then cleans up its internal representation into a neat topological loop.
  • Architecture Agnosticism: The emergence of the $H_1$ loop occurs in both Transformers and Multilayer Perceptrons (MLPs), proving that grokking's geometric signature is driven by the task's latent structure rather than specific architectural mechanisms like self-attention.

Key Results

  • Persistence Spikes: At the exact moment of grokking, the maximum $H_1$ persistence jumps from a baseline of $\approx 0.08$ to $0.20\text{–}0.25$ for Transformers, and up to $0.35$ for MLPs. Total $H_1$ persistence similarly climbs from $\approx 20$ to a range of $30\text{–}70$.
  • Dimensionality Collapse: Simultaneously, the mean LID drops sharply from an unstructured $\approx 20\text{–}25$ down to a clean, low-dimensional manifold of $\approx 5$.
  • Generalization vs. Memorization: In label corruption experiments, when noise levels reached $\ge 20\%$, grokking failed entirely. Crucially, the $H_1$ topological signature completely vanished, proving that the loop structure is strictly tied to generalization, not just training duration.
  • MNIST Contrast: On MNIST, $H_1$ persistence increased slowly and noisily without any sharp phase transitions, confirming that the clean $H_1$ signature depends on the task possessing an inherent global cyclic geometry.

Limitations and Future Work

  • Task Geometry Dependence: The clarity of the topological signature relies heavily on the task having a clean, mathematically defined latent structure (like modular groups). For messy, real-world data like MNIST, the topological behavior is far more diffuse and less interpretable.
  • Descriptive, Not Causal: Persistent homology acts as an excellent diagnostic tool to describe what the representation looks like, but it does not provide a mechanistic explanation of why the optimization landscape (e.g., AdamW dynamics) coaxes the weights into this shape.
  • Future Directions: The authors suggest scaling this topological analysis to larger models, more complex non-cyclic latent geometries, and utilizing more expressive topological summaries beyond standard persistence diagrams.

Summary updated

BibTeX
@misc{tang2026topological,
  author = {Yifan Tang and Qiquan Wang and Inés García-Redondo and Anthea Monod},
  title = {{Topological Signatures of Grokking}},
  year = {2026},
  eprint = {2605.06352},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.06352},
}
Figure