An Effective Gram Matrix Characterizes Generalization in Deep Networks

Rubing Yang, Pratik ChaudhariarXiv 2025 · DOI

One of the most enduring mysteries in machine learning is why deep neural networks (DNNs) generalize so effectively to unseen data, even when they possess the capacity to perfectly memorize the training set. Traditional theoretical frameworks often struggle to explain this, sometimes predicting generalization gaps orders of magnitude larger than those observed in practice. This paper offers a fresh perspective by shifting the focus from the "volume" of the weight space to the dynamics of the prediction space.

Shifting the Perspective: From Weights to Predictions

Most existing theories analyze the weight space (parameter movement) or the hypothesis space (the set of functions a network can represent). However, these views are often too coarse to capture the nuances of deep learning. This research argues that we must instead look at the prediction space—specifically, how the loss evolves as the network is trained on slightly different versions of the same dataset.

By treating the training process as a dynamical system governed by gradient flow, the authors derive a differential equation (ODE) that tracks the generalization gap throughout training. This evolution is controlled by two primary factors:

  1. Contraction Factor ($\bar{c}_n$): A force that pulls trajectories from different initializations or datasets together.
  2. Perturbation Factor ($\bar{\epsilon}_n$): A factor accounting for the "noise" introduced by training on different subsets of data.

The Effective Gram Matrix ($K_n$)

By solving the generalization ODE, the researchers identify a new mathematical tool: the Effective Gram Matrix ($K_n$). This matrix is essentially a weighted average of Gram matrices across the entire training trajectory, capturing how the network's sensitivity to data changes over time.

The eventual generalization gap is expressed as a quadratic form: $\vec{r}_n(0)^\top K_n \vec{r}_n(0)$, where $\vec{r}_n(0)$ is the initial "residual"—the part of the task that remains to be learned. This formulation allows for remarkably accurate predictions of test loss.

Empirical Validation

The authors validated their theory using standard benchmarks like MNIST and CIFAR-10 across various architectures, including Fully Connected networks and Wide Residual Networks. Unlike previous state-of-the-art methods that often had inaccuracies exceeding 100%, this approach achieved relative inaccuracies as low as 4-18%.

Figure 4: The theoretical estimates (purple triangles) closely track the actual generalization gap (blue line) for both MNIST and CIFAR datasets throughout the training process.

The Geometry of Generalization

A key insight of the paper is that generalization is "benign" (successful) when the initial task residual projects mostly onto the subspace of the Effective Gram Matrix associated with small eigenvalues.

During training, the network fits "easy," generalizable patterns first. These patterns correspond to the benign subspace where the generalization gap accumulates very slowly. In contrast, on "Random Label" tasks where generalization is impossible, the residual projects onto large-eigenvalue subspaces, leading to a massive generalization gap.

Figure 6: For MNIST (red), the task residual aligns with the low-eigenvalue part of the spectrum, explaining its benign generalization. For random tasks (orange), the residual is spread across larger eigenvalues, leading to poor generalization.

Conclusion and Future Directions

This research provides a rigorous mathematical bridge between training dynamics and generalization performance. It suggests that the "geometry of the task" relative to the "geometry of the network" is the true key to understanding why deep learning works.

While currently optimized for full-gradient descent and computationally intensive for large datasets, future work aims to extend this framework to stochastic optimizers like SGD and Adam, potentially providing a universal metric for model selection and architecture design.

Summary updated

BibTeX
@misc{yang2025effective,
  author = {Rubing Yang and Pratik Chaudhari},
  title = {{An Effective Gram Matrix Characterizes Generalization in Deep Networks}},
  year = {2025},
  eprint = {2504.16450},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.16450},
}
Figure