Abstract
Robust generalization is a major challenge in deep learning, particularly when the number of trainable parameters is very large. In general, it is very difficult to know if the network has memorized a particular set of examples or understood the underlying rule (or both). Motivated by this challenge, we study an interpretable model where generalizing representations are understood analytically, and are easily distinguishable from the memorizing ones. Namely, we consider multi-layer perceptron (MLP) and Transformer architectures trained on modular arithmetic tasks, where ($\xi \cdot 100\%$) of labels are corrupted (i.e. some results of the modular operations in the training set are incorrect). We show that (i) it is possible for the network to memorize the corrupted labels and achieve 100% generalization at the same time; (ii) the memorizing neurons can be identified and pruned, lowering the accuracy on corrupted data and improving the accuracy on uncorrupted data; (iii) regularization methods such as weight decay, dropout and BatchNorm force the network to ignore the corrupted data during optimization, and achieve 100% accuracy on the uncorrupted dataset; and (iv) the effect of these regularization methods is mechanistically interpretable: weight decay and dropout force all the neurons to learn generalizing representations, while BatchNorm de-amplifies the output of memorizing neurons and amplifies the output of the generalizing ones. Finally, we show that in the presence of regularization, the training dynamics involves two consecutive stages: first, the network undergoes grokking dynamics reaching high train and test accuracy; second, it unlearns the memorizing representations, where the train accuracy suddenly jumps from 100% to $100 (1-\xi)\%$.
Introduction
A fundamental tension in deep learning exists between generalization—learning the underlying logic of a dataset—and memorization—brute-forcing specific training examples. This tension is most prominent in the phenomenon of grokking, where a model achieves perfect test accuracy long after it has seemingly "solved" the training set via memorization. Disentangling these two modes is difficult in complex models. This study utilizes algorithmic datasets, specifically modular arithmetic, to provide a "microscope" into the internal representations of neural networks.
Methods
The researchers trained Multi-Layer Perceptrons (MLPs) and Transformers on modular addition tasks: $(m + n) \pmod p$, with a fraction ($\xi$) of the training labels corrupted by random noise. To analyze the internal state, they employed the Inverse Participation Ratio (IPR), a physics-inspired metric. High IPR values indicate structured, periodic weights corresponding to mathematical generalization, while low IPR values indicate unstructured weights used for memorizing specific noise.
The Three Phases of Learning with Noise
The interaction between memorization and generalization manifests in three distinct phases depending on the training conditions and regularization:
- Coexistence: The network achieves 100% test accuracy while maintaining high training accuracy on corrupted labels. The model effectively runs a generalizing algorithm and a memorizing algorithm in parallel.
- Partial Inversion: The model begins to prioritize the underlying rule, causing training accuracy on corrupted labels to dip as it "corrects" them internally.
- Full Inversion: The model achieves higher accuracy on the test set than on the training set. It ignores the corrupted labels entirely in favor of the mathematical rule.
Mechanistic Interpretability and Pruning
By calculating the IPR for every neuron, the authors discovered a bimodal distribution during the coexistence phase. One group of neurons exhibited high IPR (generalizers), while another exhibited low IPR (memorizers). This functional separation was confirmed through pruning: removing low-IPR neurons eliminated accuracy on corrupted training data while leaving test accuracy at 100%.
Regularization techniques were found to act as mechanistic filters. Weight decay and dropout physically eliminate memorizing neurons or force them to convert into generalizing ones. Conversely, BatchNorm "mutes" the signal of memorizing neurons while amplifying the generalizing ones. This process leads to a final "forgetting" phase where the model unlearns noise to focus entirely on the mathematical rule.
Conclusion
This work demonstrates that neural networks can simultaneously maintain distinct sub-networks for memorization and generalization. Through the lens of modular arithmetic and the IPR metric, these behaviors become mechanistically interpretable. While these findings are based on algorithmic datasets, they provide a foundational framework for understanding how regularization shapes the internal logic of deep learning models, moving us closer to disentangling these behaviors in large-scale real-world applications.
Summary updated