Representation geometry
表示空间的几何
Compare rotations, stretches and sample-space saturation without confusing preserved information with preserved geometry.
representation-geometryWhy two maps disagree
Suppose two models place the same six objects on two maps. One map is rotated by ninety degrees. Another has been stretched horizontally and squeezed vertically. Neither transformation deletes coordinates: both have an inverse. Yet a nearest-neighbor search can behave differently on the stretched map. Preserved information and preserved geometry are different requirements.
Representation geometry studies relationships among examples: distances, angles, neighborhoods and the directions along which activations vary. A comparison only makes sense after choosing which changes to ignore. Kornblith and colleagues make this choice explicit when comparing neural activations: orthogonal transformations and uniform scaling are useful invariances, whereas invariance to every invertible linear transform can erase meaningful distinctions. Similarity of Neural Network Representations Revisited
Our experiment uses supplied coordinates, not a trained language model. It isolates the behavior of a measurement so that the measurement does not get mistaken for an account of semantic understanding.
Define the comparison
Let X and Y have n corresponding rows, with possibly different numbers of feature columns. Subtract each column’s mean. With H the centering matrix, form sample Gram matrices K and L:
Linear centered kernel alignment compares these two sample relationship matrices by a normalized Frobenius inner product. Expanding the trace gives an equivalent feature-space calculation:
The denominator must be nonzero. A constant representation has zero centered Gram matrix; returning a perfect similarity for it would hide an undefined comparison. For nonzero positive-semidefinite K and L, the result lies between zero and one by positivity of the trace product and Cauchy–Schwarz. This is a property of the statistic, not a probability that two models are equivalent.
If Q is orthogonal, replacing X by XQ leaves K unchanged. Translating every row disappears during centering. Multiplying X by a nonzero scalar rescales K and cancels in the normalization. In contrast, an arbitrary invertible A produces , which need not be a scalar multiple of K. This derivation follows the linear CKA identity and invariance discussion in Sections 2–3. Similarity of Neural Network Representations Revisited
One route to CCA uses orthonormal bases U and V for the centered sample-space column spans:
If both spans fill the n−1 dimensional centered sample space, all these canonical correlations are one. This can happen even for independently generated wide matrices. SVCCA first discards low-variance directions by SVD and then applies CCA; the paper uses a 99% variance criterion. Our full-space counterexample deliberately omits that truncation and is not a reproduction of SVCCA. SVCCA: Singular Vector Canonical Correlation Analysis for Deep Understanding and Improvement — arXiv v1
Run the calculation
Run with CPython 3.12.4 and NumPy 1.26.4. The first four comparisons share exactly six row identities. The fifth constructs two independent wide matrices with a fixed seed. gradient is an analytic derivative of our CKA formula used in the accompanying finite-difference check; it is not a training recommendation.
import numpy as np
def center(x):
x = np.asarray(x, dtype=float)
if x.ndim != 2 or len(x) < 2 or not np.isfinite(x).all():
raise ValueError("Expected a finite matrix with at least two samples")
return x - x.mean(axis=0, keepdims=True)
def cka(x, y):
x, y = center(x), center(y)
if len(x) != len(y):
raise ValueError("Rows must refer to the same samples")
a, b = np.linalg.norm(x.T @ x), np.linalg.norm(y.T @ y)
if a == 0 or b == 0:
raise ValueError("CKA is undefined for a zero centered Gram matrix")
return np.linalg.norm(x.T @ y)**2 / (a * b)
def distances(x):
return ((x[:, None, :] - x[None, :, :])**2).sum(axis=2)
def basis(x):
x = center(x)
u, s, _ = np.linalg.svd(x, full_matrices=False)
tol = np.finfo(float).eps * max(x.shape) * s[0]
return u[:, s > tol]
def gradient(x, y):
x, y = center(x), center(y)
a, b = np.linalg.norm(x.T @ x), np.linalg.norm(y.T @ y)
n = np.linalg.norm(x.T @ y)**2
if a == 0 or b == 0:
raise ValueError("Undefined gradient")
g = 2 * y @ (y.T @ x) / (a*b) - 2*n*x @ (x.T @ x)/(a**3*b)
return g - g.mean(axis=0)
X = np.array([[-2.,0.],[-1.,1.],[0.,-1.],[0.,1.],[1.,-1.],[2.,0.]])
Q = np.array([[0.,-1.],[1.,0.]])
STRETCH = np.diag([5.,.2])
def main():
for name, y in [("rotation", X@Q), ("translation", X+np.array([7.,-3.])),
("stretch", X@STRETCH), ("row permutation", X[[1,0,2,3,4,5]])]:
print(name, "CKA", round(cka(X,y),9),
"max squared-distance change", round(np.abs(distances(X)-distances(y)).max(),6))
rng = np.random.default_rng(4)
x, y = rng.normal(size=(6,8)), rng.normal(size=(6,9))
u, v = basis(x), basis(y)
print("centered ranks", u.shape[1], v.shape[1])
print("full-space CCA", np.round(np.linalg.svd(u.T@v,compute_uv=False),9))
print("wide independent CKA", round(cka(x,y),9))
if __name__ == '__main__':
main()
rotation CKA 1.0 max squared-distance change 0.0
translation CKA 1.0 max squared-distance change 0.0
stretch CKA 0.934174962 max squared-distance change 384.0
row permutation CKA 0.870967742 max squared-distance change 6.0
centered ranks 5 5
full-space CCA [1. 1. 1. 1. 1.]
wide independent CKA 0.664716981
Feature-space CKA forms three cross-products, costing with intermediate storage. Sample-space Gram calculations instead cost and storage. Choose the smaller route for the actual dimensions. This compact program does not add overflow-safe scaling for extreme magnitudes; use bounded inputs as supplied.
Interpret the result carefully
A similarity score inherits the distribution of the samples used to compute it. Shared backgrounds can dominate a visual representation, while a rare but important category barely affects the global Gram matrix. Repeat comparisons on meaningful subsets and held-out data; do not select a layer on the test set and then present that selection as independent evaluation.
Row correspondence matters. A neuron permutation changes columns and is a desirable invariance; shuffling only one model’s sample rows changes the question. Our exchange of the first two rows preserves the point cloud as an unordered set but changes which objects are paired. A different score is therefore expected.
CKA is also not a universal detector of useful geometry. Uniform scaling leaves it unchanged while changing raw distances; strongly varying nuisance directions can dominate it. High CKA neither establishes identical predictions nor proves a shared causal mechanism. Combine it with a stated distance metric, local-neighborhood checks, task evaluation and targeted interventions.
Exercises with answers
1. Why is a ninety-degree rotation invisible to linear CKA?
Its orthogonal matrix satisfies QQᵀ=I, so the sample Gram matrix is unchanged.
2. Does an invertible stretch lose information?
No in exact arithmetic: multiply by its inverse to recover the coordinates. It can still change Euclidean distances and nearest neighbors.
3. Why do two independent wide matrices have five canonical correlations equal to one here?
Their centered columns span the same five-dimensional subspace of six-dimensional sample space. This is a finite-sample rank effect, not learned agreement.
4. Should constant representations receive CKA zero?
The normalized expression is undefined because its denominator is zero. Report that failure explicitly rather than inventing a similarity.
Sources and next steps
Read Kornblith et al., Sections 2–3 and Theorem 1, to see why choosing invariances is a modeling decision. Then compare the full-space counterexample with the actual SVD truncation in Raghu et al., Section 2. The results in their neural-network experiments remain conditional on their architectures and datasets. Our six-point construction is an independent teaching example, not evidence about current frontier models.
Continue with linear probes for label accessibility and embedding evaluation for task-specific tests. Similarity of Neural Network Representations Revisited; SVCCA: Singular Vector Canonical Correlation Analysis for Deep Understanding and Improvement — arXiv v1
Make a prediction, then check
Why can two independent wide representations have all full-space canonical correlations equal to one?
Learning objectives
- Choose and derive the invariances of a representation comparison.
- Recognize finite-sample saturation in high-dimensional CCA.
Prerequisites & connections
Explore related knowledge →References
- Similarity of Neural Network Representations Revisited
Simon Kornblith; Mohammad Norouzi; Honglak Lee; Geoffrey Hinton · 2019 - SVCCA: Singular Vector Canonical Correlation Analysis for Deep Understanding and Improvement — arXiv v1
Maithra Raghu; Justin Gilmer; Jason Yosinski; Jascha Sohl-Dickstein · 2017
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author check: bounded primary passages, attribution, stated assumptions, original examples, bilingual structure and exercises; computational tests only for the algorithm chapter. Not independent human or second-agent review.
- Single-agent authored technical review; runnable example, exact or literal reference checks, explicit assumptions and matching bilingual equations/exercises. Automated execution and rendering results recorded separately.
- Four executed CPython 3.12.4/NumPy 1.26.4 checks: independent Gram identity and invariances, full coordinate finite differences, centered-rank/projector saturation and bilingual structure. Row exchange uses a non-isometric permutation; symmetric reversal is not used as a misleading negative control.
- Complete bilingual prose and corresponding exercises promoted with formal status and SHA binding. Algorithm tests read formal MDX; historical essays claim no executable program or computational tests.
- Original Matplotlib 3.9.1 illustration generated from frozen executable coordinates; both locales and numerical JSON hash-bound. Equal axis units within panels, varying limits explicitly labeled.
- Browser check found the new unstyled 420px image overflowing mobile width. Added the existing responsive-image convention (zero side margins, max-width 100%, automatic height) to this new figure only; computation and frozen drafts unchanged.
- Visual inspection of the mobile SVG found overlapping labels for the squeezed central pair. Placed one label below its point; coordinates and computed data are unchanged, and SVG dependency hashes refreshed.
Source locations checked:
- Similarity of Neural Network Representations Revisited · Physical pages 2–4, Sections 2–3, Theorem 1, Gram identity and normalized linear CKA; finite centered-space example derived independently.
- SVCCA: Singular Vector Canonical Correlation Analysis for Deep Understanding and Improvement — arXiv v1 · Version 1 physical pages 1–3, title and authors, Section 2 SVD 99% variance selection followed by CCA; full-rank example does not implement this truncation.
Related topics