Similarity and Matching of Neural Network Representations

Adrián Csiszárik, Péter Kőrösi-Szabó, Ákos K. Matszangosz, Gergely Papp, Dániel Varga

Introduction

Deep neural networks are often criticized as "black boxes." While their empirical success is undeniable, understanding their internal representations—the specific "features" they learn—remains a major challenge. A fundamental question in the field of interpretability is: When are two representations similar?

Traditionally, researchers use statistical measures like Canonical Correlation Analysis (CCA) or Centered Kernel Alignment (CKA) to compare the activations of two networks. However, these measures are purely mathematical; they do not inherently reveal if the features are functionally equivalent. This paper addresses the critical gap between representational similarity (do the activation distributions look the same?) and functional similarity (can one network actually use the features learned by another to solve a specific task?).

To explore whether neural networks trained from different random starting points learn compatible features, the authors introduce a "Dr. Frankenstein" toolset. By "stitching" the first half of one network to the second half of another using a simple linear layer, they demonstrate that these models are remarkably compatible, even when popular similarity metrics like CKA fail to predict their functional performance.

Methodology: Model Stitching

The authors introduce a methodology called Model Stitching to evaluate functional similarity.

  1. The Setup: Two networks (Model A and Model B) with the identical architecture but different random initializations are pre-trained on a target task.
  2. The Stitch: Model A is severed at layer $L$, and Model B is severed at the corresponding layer $L$. The bottom half of Model A is then connected to the top half of Model B using a "stitching layer"—a simple affine transformation (e.g., a $1 \times 1$ convolution).
  3. Matching Strategies: The authors compare two distinct ways to optimize this stitching layer:
  4. Direct Matching: Using linear least squares to force the activations of Model A to statistically match those of Model B. This is an unsupervised, purely statistical alignment.
  5. Task Loss Matching: Training the stitching layer using the actual task objective (e.g., image classification cross-entropy) via gradient descent, while keeping the rest of the "Frankenstein" network frozen. This directly measures functional compatibility.
Diagram illustrating the Model Stitching methodology. Left: Direct matching using least squares. Right: Task loss matching using gradient descent.

Experimental Setup

The experiments were conducted on standard computer vision benchmarks to ensure broad applicability:

  • CIFAR-10: Used to train a simple 10-layer convolutional network (Tiny-10) and ResNet-20.
  • CelebA: Used to train the Inception V1 architecture on a 40-label attribute classification task.
  • ImageNet: Utilized for cross-dataset stitching experiments to test robustness.

Key Insights

  • The "Matchability" Property: The most striking finding is the incredible functional robustness of these networks. You can swap the "brains" of two differently initialized ResNets mid-stream, and with just a single linear layer to align them, the hybrid model performs almost as well as the original, unstitched models.
  • The CKA Warning: Centered Kernel Alignment (CKA) is currently a "gold standard" for comparing representations. However, the authors show that CKA can be highly misleading. They successfully trained a stitching layer that maintained high task accuracy while explicitly minimizing CKA. This suggests that high functional performance does not strictly require high representational similarity as defined by current statistical metrics.
  • Variance $\neq$ Importance: Methods like SVCCA rely on Singular Value Decomposition (SVD) to find the most "important" directions in data based on variance. The authors found that the directions with the most variance aren't necessarily the ones most useful for the task. Task loss matching consistently outperformed SVD-based matching, especially when the stitching layer was constrained to be low-rank (acting as a bottleneck).
  • Sparsity and Distributed Features: The authors demonstrated that you can zero out 80-90% of the connections in a stitching layer and still maintain high accuracy if trained with task loss. This suggests that while representations are somewhat "distributed," there is a core functional alignment that can be captured very efficiently.

Key Results

  • Near-Perfect Recovery: On architectures like ResNet-20 and Inception V1, task loss matching achieved nearly 100% of the original model's accuracy across almost all layers.
  • Direct Matching Success: Even without utilizing task labels, simple least-squares matching performed surprisingly well on middle layers, often reaching over 90% relative accuracy.
  • Width Matters: As networks become wider, they become even easier to stitch together. This suggests that over-parameterization leads to more "universal" or easily alignable feature spaces.
Relative accuracy and cross-entropy across different layers for ResNet-20, Tiny10, and Inception V1, comparing task loss matching and linear least squares.

Limitations and Future Work

  • Architecture Scope: The study focused primarily on well-established convolutional neural networks (CNNs). While the authors note that others have successfully stitched Transformers, those architectures were not the primary focus of this specific analysis.
  • Lower Bounds: The performance of a stitched model is technically a "lower bound" on functional similarity. If a stitch fails to recover performance, it might simply be because the optimization process got stuck in a local minimum, not necessarily because the underlying representations are inherently incompatible.
  • Task Specificity: The "functional similarity" defined here is intrinsically tied to a specific target task. Future work could explore how these insights change when models are trained on multi-task or self-supervised objectives.

Ultimately, this paper serves as a vital reality check for the interpretability community, reminding us that how a network uses information to solve a task is just as important as the raw statistical properties of the information itself.

Summary updated

BibTeX
@inproceedings{csiszarik2021similarity,
  author = {Adrián Csiszárik and Péter Kőrösi-Szabó and Ákos K. Matszangosz and Gergely Papp and Dániel Varga},
  title = {{Similarity and Matching of Neural Network Representations}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=aedFIIRRfXr},
}
Figure