Certifying Contrastive Features as Eigenfunctions with a Spectral Residual

A contrastive encoder learns by pulling two random augmentations of the same image together and pushing different images apart. Theory says that doing this well amounts to computing the top eigenfunctions of an "augmentation operator," the operator that averages any function of an image view over the other views that could come from the same source image (Provable Guarantees for Self-Supervised Deep Learning with Spectral Contrastive Loss, Contrastive Learning is Spectral Clustering on Similarity Graph). Numerical analysts who approximate operators like this with finite bases have learned something the contrastive community has not yet used. Finite approximations produce spectral pollution: spurious eigenvalues that belong to the finite matrix but not to the true operator. The standard defense is to check each computed eigenpair against the operator equation itself, using its spectral residual.

We propose to compute, for every direction in a trained contrastive representation, a residual that measures how far that direction is from being a true eigenfunction of the augmentation operator. We then use the residual to settle a live disagreement. One line of robustness work says the small-variance tail of a contrastive representation should be amplified, because it holds the minority-group features that shortcut learning suppresses. Operator-learning theory says small-variance directions under a misaligned basis are exactly where spurious modes live, so they should be cut. Our claim is that both are right about different directions. Tail directions with small residual are real low-eigenvalue structure and should be flattened. Tail directions with large residual are numerical artifacts and should be dropped. A residual-gated treatment should therefore beat both blanket flattening and blanket truncation on worst-group accuracy.

Why the transfer is clean, and why the obvious residual is vacuous

The augmentation operator $A$ has a symmetric kernel, because the two views of a positive pair play interchangeable roles. It is therefore self-adjoint and positive semi-definite. That is precisely the regime where the sharp spectral theory of Koopman Operator Learning: Sharp Spectral Rates and Spurious Eigenvalues holds. That paper proves operator-norm bounds for data-driven operator estimators and names "metric distortion," the mismatch between the empirical feature geometry and the true $L^2$ geometry. It also shows that spurious eigenvalues appear when estimator bias from a misaligned basis dominates sample error. Its open problem, non-normal operators, does not arise here. This makes contrastive learning an unusually well-posed place to import pollution theory.

The obvious import fails, though, and seeing why shapes the method. Take encoder features $f(x)\in\mathbb{R}^k$. From positive pairs $(x,x^+)$ we estimate the feature covariance $C=\mathbb{E}[f(x)f(x)^\top]$ and the symmetrized cross-covariance $T=\tfrac12\mathbb{E}[f(x)f(x^+)^\top+f(x^+)f(x)^\top]$. We then solve the generalized eigenproblem

$$T v_i = \lambda_i C v_i, \qquad \psi_i(x)=v_i^\top f(x),$$

which gives the eigenpairs $(\lambda_i,\psi_i)$ of $A$ restricted to the span of the encoder's features. This is the contrastive analogue of Extended Dynamic Mode Decomposition (EDMD, a least-squares projection of an operator onto a fixed set of basis functions).

Two naive residuals are uninformative. The residual measured inside the span of $f$ is exactly zero, a consequence of how the projection is built. The quantity $\mathbb{E}|\psi(x^+)-\lambda\psi(x)|^2$ always equals $1-\lambda^2$ for a normalized $\psi$ with its Rayleigh quotient, whether or not $\psi$ is an eigenfunction. The true residual $\|A\psi-\lambda\psi\|$ needs $\|A\psi\|^2$, a two-step quantity. That would require sampling a view, inferring its unknown source image, and resampling, which positive pairs cannot provide. This is the same obstacle that Beyond expectations: residual dynamic mode decomposition and variance for stochastic dynamical systems confronts for stochastic dynamics, where expectation-based residuals mix a variance term into the error. It is also why the residual-trained networks of ResKoopNet: Learning Koopman Representations for Complex Dynamics with Spectral Residuals cannot be copied directly. ResKoopNet trains neural dictionaries by minimizing $\|A\Psi-\lambda\Psi\|$ on deterministic trajectories, where the needed moments are observable.

Core Claim

The fix is to test the equation against a richer probe space than the one used to solve it. The probe space is a set of functions $g(x)\in\mathbb{R}^m$ with $m\gg k$ that contains $f$. Examples are the backbone's penultimate features concatenated with features from an independently seeded encoder and random Fourier features of both. Inner products $\langle g_j, A\psi\rangle=\mathbb{E}[g_j(x)\psi(x^+)]$ are single-step and computable from positive pairs. The projected residual of eigenpair $i$ is

$$r_i^2=\frac{c_i^\top (C_{gg}+\epsilon I)^{-1} c_i}{v_i^\top C v_i},\qquad c_i=\tfrac12\mathbb{E}\big[g(x)\psi_i(x^+)+g(x^+)\psi_i(x)\big]-\lambda_i\,\mathbb{E}[g(x)\psi_i(x)].$$

Here $C_{gg}$ is the probe covariance and $\epsilon$ is a small ridge. The quantity $r_i$ lower-bounds the true residual and increases toward it as the probe space grows. A large $r_i$ is therefore proof that direction $i$ is not an eigenfunction. We will report how $r_i$ changes as the probe space grows, so that a small $r_i$ can be read with appropriate caution.

The central empirical claim follows. In contrastive encoders trained under shortcut features, the low-variance tail splits into low-residual and high-residual directions. The worst-group gains from spectrum flattening come from the low-residual part. Flattening the high-residual part adds noise that residual gating removes.

Research Program

The first stage validates the residual where the truth is known. We build a synthetic augmentation graph on a circle. Each source is a point at an angle, and augmentation adds Gaussian angular noise of width $\sigma$. The true operator is then a convolution whose eigenfunctions are Fourier modes with eigenvalues $e^{-q^2\sigma^2}$ for frequency $q$, because the two-hop view-source-view walk composes two noise steps. We add a "shortcut" coordinate that is correlated with a coarse label and easy to learn. We then train small encoders with the spectral contrastive loss at varying batch sizes and widths. We measure whether $r_i$ ranks computed eigenvalues by their true error $|\lambda_i-\lambda_{\text{true}}|$, and whether directions with no true counterpart, the polluted ones, have large $r_i$. We will also check whether the gap between our lower bound and the true residual closes as the probe space grows.

The second stage applies the diagnostic to real encoders. We train SimCLR and the spectral contrastive loss on CIFAR-10 and on SpurCIFAR-10, compute $(\lambda_i,r_i)$ for all directions, and study the joint distribution of eigenvalue and residual. InfoNCE is argued to be spectral clustering on a kernel similarity graph (Contrastive Learning is Spectral Clustering on Similarity Graph). That graph is not identical to the augmentation graph, so for SimCLR we treat the residual as a test against $A$ specifically and report the two losses separately.

The third stage turns the diagnostic into interventions. The post-hoc intervention trains the linear probe on the residual-certified subspace, directions with $r_i$ below a threshold chosen on a held-out split. The training-time intervention applies the eigenvalue-flattening penalty of Spectral Dynamics of Contrastive Learning with Spurious Features only to low-residual directions and adds a penalty on the variance carried by high-residual ones. Residuals are recomputed every few epochs from accumulated $m\times m$ statistics. This costs one probe forward pass per recomputation and is far cheaper than the alternating eigen-solves of ResKoopNet.

Baselines

The naive reference point is the unregularized encoder with a linear probe on all features: SimCLR, and the spectral contrastive loss. The file reports SimCLR worst-group accuracy of 36.5% on SpurCIFAR-10 and 81.7% on C-MNIST (Mitigating Spurious Features in Contrastive Learning with Spectral Regularization). It also reports 92.07% CIFAR-10 linear-probe accuracy for the spectral contrastive loss (Provable Guarantees for Self-Supervised Deep Learning with Spectral Contrastive Loss). We reproduce these in our own pipeline rather than comparing against quoted numbers.

The strongest existing method is covariance-spectrum flattening. Spectral Dynamics of Contrastive Learning with Spurious Features penalizes the sum of squared normalized eigenvalues on top of SimCLR and reports 59.7 ± 1.0% SpurCIFAR-10 worst-group accuracy. Mitigating Spurious Features in Contrastive Learning with Spectral Regularization reports 64.6% on SpurCIFAR-10 and 95.1% on C-MNIST with a related effective-rank regularizer. It is the strongest competitor because it targets the same tail directions we do and reports large gains there. We run both regularizers ourselves with the same backbone, augmentations, epochs, and seeds (five), and give each a hyperparameter sweep of equal size to ours. Beating it means a worst-group improvement on SpurCIFAR-10 exceeding the seed spread, without losing average accuracy.

The truncation baseline follows the logic of Koopman Operator Learning: Sharp Spectral Rates and Spurious Eigenvalues. That paper shows reduced-rank regression, which fits the operator under an explicit rank constraint, cut empirical spectral bias on triple-well Langevin dynamics from 0.164 (plain projection) to 0.002. We fit reduced-rank regression of $g(x^+)$ on $g(x)$ in the probe space and use its top eigenfunctions as the representation. We also run eigenvalue-ordered truncation of the encoder's own spectrum, matching the number of retained dimensions to our certified subspace.

The key ablation replaces residual ordering with eigenvalue ordering while holding the number of kept or flattened directions fixed. If eigenvalue ordering matches residual ordering, the residual adds nothing.

Why not just…?

Why not just flatten the whole spectrum, as the spurious-feature papers do? Flattening cannot tell a genuine low-eigenvalue feature from a polluted direction; both look like small eigenvalues. The reported flattening gains, 36.5% to 59.7% or 64.6% on SpurCIFAR-10, are real and are our main target. Our claim fails if flattening only the high-residual directions recovers as much worst-group accuracy as flattening only the low-residual ones. The stage-two split probe tests exactly this.

Why not just truncate, or run reduced-rank regression on backbone features? This is a real threat, because reduced-rank regression carries guarantees of the form $O(\sigma_{r+1}+1/\sqrt{n})$ in the Koopman setting. However, "Spectral Dynamics of Contrastive Learning with Spurious Features" reports that flattening helped where truncation did not in its controlled synthetic setting, raising worst-group accuracy from 30% to 40%. That suggests truncation discards useful tail structure. If reduced-rank regression on probe features matches residual gating, we will report that the simpler operator-theoretic estimator suffices. The contribution would then shrink to the diagnostic itself.

Why not just measure eigenvalue stability across bootstrap resamples? Pollution from finite samples should show up as instability, and bootstrap stability is cheap. But pollution caused by a misaligned basis, as opposed to noisy samples, is stable across resamples. It is exactly the bias-dominated case identified in the Koopman sharp-rates paper. We include bootstrap stability as a competing ranking in every ablation. On the circle testbed we build one condition where the encoder architecture is deliberately misaligned with Fourier modes, where we predict stability fails and the residual succeeds.

Proposed Experiments

The decisive checks come in order. On the circle testbed, the residual must rank computed eigenvalues by true error with high Spearman correlation, and must flag injected spurious directions; if it cannot, the program stops. On SpurCIFAR-10 and C-MNIST, five seeds per method, we compare worst-group and average accuracy for the naive encoders, both flattening regularizers, eigenvalue truncation, probe-space reduced-rank regression, bootstrap-gated flattening, and residual-gated flattening. On CelebA and Waterbirds we run the same comparison; no reported result was found on Lacuna for exact worst-group numbers there, so all values will be our own reproductions. On standard CIFAR-10, CIFAR-100, and Tiny-ImageNet linear probes we check that certification costs no average accuracy relative to the 92.07% CIFAR-10 reference. Finally, we report residual profiles as a function of probe-space size and training batch size. The prediction, from the sample-error term of the Koopman bounds, is that the fraction of high-residual tail directions shrinks as the batch grows.