Deep neural networks are often treated as "black boxes." To better understand their internal mechanics, researchers frequently attempt to compare the activations (representations) of different layers or entirely different models. For instance, does a ResNet-50 trained with one random seed learn the same internal features as one trained with another? Can we map a layer in a VGG network to a corresponding layer in a Transformer?
This paper introduces Centered Kernel Alignment (CKA) as a robust method to measure whether two neural networks have learned similar internal representations, overcoming significant flaws in previously used methods.
The Problem with Previous Methods
Historically, researchers have used Canonical Correlation Analysis (CCA) to compare network representations. CCA is invariant to any invertible linear transformation. While this sounds mathematically advantageous, the authors argue it is actually a critical flaw for analyzing neural networks.
In neural networks, the scale and variance of specific directions in activation space matter deeply because gradient descent prioritizes directions with larger eigenvalues. CCA treats all directions as equally important, making it "blind" to the actual dynamics of neural network training. Furthermore, CCA fails completely when a layer has more neurons than there are data points in the evaluation set—a very common scenario in modern deep learning.
The Solution: Centered Kernel Alignment (CKA)
To address these issues, the authors propose CKA. Instead of comparing individual neurons, CKA compares Representational Similarity Matrices (RSMs).
- Representational Similarity Matrices: For a set of $n$ examples, an $n \times n$ matrix is calculated where each entry represents the similarity (e.g., dot product) between the model's activations for example $i$ and example $j$.
- Comparing Matrices: CKA then measures the similarity between the RSM of Model A and the RSM of Model B.
Crucially, CKA is invariant to orthogonal transformations (like permutations of neurons) and isotropic scaling, but not to all invertible linear transformations. This "weaker" invariance allows CKA to capture the meaningful, variance-weighted structure that gradient descent actually creates. Mathematically, linear CKA is closely related to the Hilbert-Schmidt Independence Criterion (HSIC) and acts like a version of CCA where correlation coefficients are weighted by the variance they explain.
Key Insights and Results
The researchers evaluated CKA on CNN architectures (using CIFAR-10 and CIFAR-100) and Transformer models (using linguistic data), yielding several major insights:
The Sanity Check Success
The authors proposed a simple "sanity check" for any similarity metric: if you have two identical networks trained with different random seeds, Layer $L$ in Network 1 should be most similar to Layer $L$ in Network 2.
CKA passes this test with flying colors. In identifying corresponding layers across 10 different random initializations, Linear CKA achieved 99.3% accuracy, whereas standard CCA achieved only 10.6% and SVCCA (a popular variant) reached 15.1%.
Revealing "Pathological Depth"
CKA can act as a diagnostic tool to reveal when a network is "too deep."
When evaluating an 8x-depth CNN, CKA showed that the representations in the second half of the network were virtually identical to the final layer. This suggests the extra layers were not actually refining the representation, a phenomenon CKA makes easily visible.
Architecture Mapping and Network Width
CKA successfully identified relationships between layers of different architectures. For example, when mapping layers between a Plain CNN and a ResNet, CKA showed that ResNets effectively "insert" new layers between the representations learned by shallower networks. Additionally, the authors found that wider networks learn more similar representations to one another than narrower networks do.
Limitations and Future Work
While CKA is a powerful diagnostic tool, it provides a scalar summary of similarity. It tells you that two layers are similar, but it doesn't explicitly explain what specific features they are sharing in a way that is easily interpretable by humans.
The authors note that while they focused on Linear and RBF kernels, other kernels might be better suited for specific data types or architectures. Future work could leverage CKA to guide "student-teacher" training (knowledge distillation) or to improve deep network initialization by copying representations from successful models.
Summary updated