Search

Search papers and lessons

Representation Collapse

Level 3 · 11 min read

Representation collapse is when a self-supervised encoder maps different inputs to nearly the same vector, or to a few directions, so the loss drops while the features carry little information.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Linear algebra
  • Representation learning
  • Neural network basics
  • Learning basics
  • Sign in to see your progress

TL;DR

A self-supervised encoder is trained with a loss that only asks for useful features, so the easiest way to score well can be to make every input produce the same vector. This is representation collapse. The loss looks good, but the features carry almost no information about the input, and the damage often shows up only later, when a classifier is trained on top of them.

Collapse comes in two strengths: complete collapse, where all vectors are identical, and dimensional collapse, where the vectors vary but only along a few directions. Negatives, stop-gradient tricks and variance penalties are the standard defences.

Where you'll see it: when a SimCLR-, BYOL- or VICReg-style image encoder is pretrained without labels and its loss curve looks fine but its linear-probe accuracy stays low. It also matters for JEPA-style predictive models, which must avoid the same trivial solution.

Intuition

A student who copies the answer key

Imagine a training exercise where a student is graded only on whether two versions of the same photo get matching answers. The student could ignore the photos entirely and always write the number 7. Every pair matches, the score is perfect, and nothing was learned. Self-supervised learning has no human labels, so the objective is the only grader, and an objective that rewards agreement alone can be satisfied by ignoring the input.

That is collapse. The encoder finds a constant function, which trivially makes two views agree. The fix is always to make the constant answer score badly, so the model must keep information that tells one example from another.

Why the loss does not catch it

Contrastive methods add negatives: other images in the batch that must end up different from the anchor. If every embedding is the same, the negatives score just as well as the positive, and the loss does not drop. So contrastive loss already blocks complete collapse. Non-contrastive methods remove the negatives and need another mechanism, such as an asymmetric predictor with stop-gradient, or a penalty on the variance and correlation of the features.

Dimensional collapse is harder to see. The embeddings are not identical, but they stretch along only a handful of directions, as if a three-dimensional cloud had been flattened into a sheet or a line. The loss can still look healthy because the few directions it uses are enough to separate the training pairs. The downstream task is what suffers.

flowchart TD
  A["Objective rewards agreement"] --> B{"Anything stops the encoder?"}
  B -- "No" --> C["Complete collapse: all embeddings equal"]
  B -- "Partly" --> D["Dimensional collapse: spread in few directions"]
  B -- "Negatives, stop-gradient, variance penalty" --> E["Informative, spread-out features"]
  C --> F["Loss looks perfect, linear probe is poor"]
  D --> F

The math

Setup

Let an encoder fθf_\theta map an input xx to a feature, and a projection head gg map that feature to an embedding z=g(fθ(x))\mathbf{z} = g(f_\theta(x)). In many methods z\mathbf{z} is then scaled to unit length. Take a batch of NN embeddings z1,…,zN\mathbf{z}_1, \ldots, \mathbf{z}_N, each a vector in Rd\mathbb{R}^d, and stack them as the rows of a matrix Z∈RN×dZ \in \mathbb{R}^{N \times d}.

Subtract the batch mean zˉ\bar{\mathbf{z}} to get the centred matrix Z~\tilde{Z}, whose rows are zi−zˉ\mathbf{z}_i - \bar{\mathbf{z}}. The empirical covariance matrix of the batch is

C=1N Z~⊤Z~∈Rd×d.C = \frac{1}{N}\,\tilde{Z}^\top \tilde{Z} \in \mathbb{R}^{d \times d}.

This is the Covariance Matrix of the embeddings. Its diagonal holds the variance of each coordinate, and its off-diagonal entries hold how pairs of coordinates move together. Let its eigenvalues be λ1≥λ2≥⋯≥λd≥0\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_d \ge 0. Each eigenvalue measures how much the embeddings spread along one principal direction; the eigenvectors are those directions (see Eigenvalues and Eigenvectors).

Two kinds of collapse

Complete collapse. Every embedding is the same vector, so Z~=0\tilde{Z} = 0, C=0C = 0, and all eigenvalues are zero. The Matrix Rank of CC is 0.

Dimensional collapse. The embeddings vary, but rank⁡(C)<d\operatorname{rank}(C) \lt d, or most of the eigenvalue mass sits in a few directions. Because the spread is uneven, a single rank number can hide the problem, so practitioners use an effective rank. With pk=λk/∑jλjp_k = \lambda_k / \sum_j \lambda_j, define

erank⁡(C)=exp⁡ ⁣(−∑k=1dpkln⁡pk),\operatorname{erank}(C) = \exp\!\left(-\sum_{k=1}^{d} p_k \ln p_k\right),

with 0ln⁡0=00 \ln 0 = 0. This is the exponential of the entropy of the normalised spread. If all dd directions carry equal variance, erank⁡=d\operatorname{erank} = d. If one direction carries everything, erank⁡=1\operatorname{erank} = 1. A healthy encoder has an effective rank close to dd; a collapsing one has it close to 1.

Why the losses allow it

A positive-only objective, such as L=−E[cos⁡(za,zb)]L = -\mathbb{E}[\cos(\mathbf{z}_a, \mathbf{z}_b)] for two views aa and bb of the same input, is minimised at −1-1, which holds exactly when all embeddings point the same way. Nothing in that loss penalises the constant solution.

The InfoNCE loss used in Contrastive Learning has the form

Li=−log⁡exp⁡(sii/τ)∑k≠iexp⁡(sik/τ),L_i = -\log \frac{\exp(s_{ii}/\tau)}{\sum_{k \neq i} \exp(s_{ik}/\tau)},

where sik=cos⁡(zi,zk)s_{ik} = \cos(\mathbf{z}_i, \mathbf{z}_k) is the Cosine Similarity between embeddings, τ>0\tau \gt 0 is a temperature, and the positive is the other view of the same image. If every embedding is identical, every sik=1s_{ik} = 1, so each term in the fraction equals 1/(2N−1)1/(2N-1) and the loss is log⁡(2N−1)\log(2N-1). That is the loss of a model that guesses uniformly among the 2N−12N-1 candidates. Collapse is not a zero-loss solution here, which is why negatives matter.

Non-contrastive methods use a predictor qq on one branch and a stop-gradient operator sg⁡(⋅)\operatorname{sg}(\cdot) on the target, with a loss such as ∥q(za)−sg⁡(zb)∥2\lVert q(\mathbf{z}_a) - \operatorname{sg}(\mathbf{z}_b) \rVert^2 on normalised vectors. Stop-gradient means the target is treated as a constant during backpropagation. Methods of this kind work in practice, but the full reason they avoid collapse is still debated, so treat any single explanation with caution.

Variance and covariance regularisers attack the problem directly. A VICReg-style term penalises any feature dimension whose standard deviation falls below a threshold, and a second term penalises off-diagonal entries of CC. Both keep the spread across directions high and the correlations between directions low.

Worked examples

Example
Detecting dimensional collapse in four points

Take four unnormalised embeddings in R2\mathbb{R}^2 to keep the arithmetic simple. Ignore normalisation for this example.

Case A, a line: (1,0.1)(1, 0.1), (−1,−0.1)(-1, -0.1), (2,0.2)(2, 0.2), (−2,−0.2)(-2, -0.2).

  1. The mean is (0,0)(0, 0), so no centring is needed.
  2. Sum of x2x^2 is 1+1+4+4=101 + 1 + 4 + 4 = 10. Sum of y2y^2 is 0.01+0.01+0.04+0.04=0.10.01 + 0.01 + 0.04 + 0.04 = 0.1. Sum of xyxy is 0.1+0.1+0.4+0.4=1.00.1 + 0.1 + 0.4 + 0.4 = 1.0.
  3. Divide by N=4N = 4: C=(2.50.250.250.025)C = \begin{pmatrix} 2.5 & 0.25 \\ 0.25 & 0.025 \end{pmatrix}.
  4. The determinant is 2.5⋅0.025−0.252=0.0625−0.0625=02.5 \cdot 0.025 - 0.25^2 = 0.0625 - 0.0625 = 0, so one eigenvalue is 0. The trace is 2.5252.525, so the eigenvalues are 2.5252.525 and 00.
  5. p=(1,0)p = (1, 0), so erank⁡=exp⁡(0)=1\operatorname{erank} = \exp(0) = 1.

Interpretation: the points look like two dimensions, but they carry only one. This is dimensional collapse, and the loss would not necessarily notice.

Case B, spread out: (1,0)(1, 0), (0,1)(0, 1), (−1,0)(-1, 0), (0,−1)(0, -1).

  1. Sum of x2x^2 is 2, sum of y2y^2 is 2, sum of xyxy is 0. So C=14⋅2I=0.5 IC = \tfrac{1}{4}\cdot 2I = 0.5\,I.
  2. Both eigenvalues are 0.50.5, so p=(0.5,0.5)p = (0.5, 0.5).
  3. erank⁡=exp⁡(−2⋅0.5ln⁡0.5)=exp⁡(ln⁡2)=2\operatorname{erank} = \exp(-2 \cdot 0.5 \ln 0.5) = \exp(\ln 2) = 2.

Interpretation: the effective rank reaches the full dimension d=2d = 2. Case A had effective rank 1 with the same number of points, so the two cases differ only in spread.

Example
The contrastive loss at collapse and at a healthy state

Use a batch of N=4N = 4 images, so there are 2N=82N = 8 embeddings. Each anchor has one positive and 2N−2=62N - 2 = 6 negatives. Set the temperature τ=0.5\tau = 0.5.

Collapsed state. All eight embeddings are identical, so every similarity is 11.

  1. Each term in the denominator is exp⁡(1/0.5)=e2\exp(1/0.5) = e^2. There are 2N−1=72N - 1 = 7 terms, including the positive.
  2. The fraction is e2/(7e2)=1/7e^2 / (7 e^2) = 1/7.
  3. The loss is −ln⁡(1/7)=ln⁡7≈1.946-\ln(1/7) = \ln 7 \approx 1.946 for every anchor.

Healthy state. The positive similarity is 0.90.9 and the six negatives sit at similarity 00.

  1. The positive score is 0.9/0.5=1.80.9 / 0.5 = 1.8, and each negative score is 00.
  2. The loss is ln⁡ ⁣(1+6e−1.8)\ln\!\left(1 + 6 e^{-1.8}\right). Here e−1.8≈0.1653e^{-1.8} \approx 0.1653, so 6e−1.8≈0.99186 e^{-1.8} \approx 0.9918.
  3. The loss is ln⁡(1.9918)≈0.689\ln(1.9918) \approx 0.689.

Interpretation: the collapsed state scores about 1.95 and the healthy state about 0.69, so the loss does punish collapse here. A positive-only loss would not, since both states would score equally well, or the collapsed one would score better.

Tradeoffs and failure modes

Collapse is easy to cause and easy to miss, so the first step is to measure the representation, not only the loss.

SituationProblemBetter choice
Positive-only loss with no predictor or stop-gradientComplete collapse is a global minimumAdd a predictor with stop-gradient, or a variance and covariance penalty
Contrastive loss with very few negativesWeak push-apart signal, so features stay less discriminativeLarger batch, or a memory queue of past embeddings
Loss falls but linear-probe accuracy stays lowProbably dimensional collapseCheck effective rank and per-dimension standard deviation on held-out data
Strong variance or decorrelation penaltyFeatures become noisy and lose class structureTune the penalty weights against a downstream check
Stop-gradient without an asymmetric predictorTarget and online branch can drift togetherKeep the predictor, or follow a published recipe

Practical checks. Track the mean per-dimension standard deviation of the embeddings and the effective rank of CC on a fixed held-out batch, every few hundred steps. A sharp drop in either is an early warning. Also check that augmentations are strong enough: weak augmentations make the two views nearly identical, so the task can be solved without learning much.

Edge case. A low but nonzero effective rank can be correct for a dataset with few real factors of variation. Compare against a supervised or randomly initialised baseline before concluding that the encoder is broken.

History

Siamese networks, with two weight-sharing branches compared by a distance, were used for signature verification in the early 1990s. In 2006, Hadsell, Chopra and LeCun wrote down a contrastive loss that pulls matched pairs together and pushes others apart, which is the ancestor of the losses above.

Modern self-supervised vision methods began to use this structure at scale around 2020. SimCLR, published in 2020, uses large batches of augmented views and an InfoNCE-style loss, so its negatives block complete collapse directly. BYOL, also from 2020, showed that negatives were not strictly required, which made the question of what prevents collapse sharper. Later in 2020 and in 2021, SimSiam, Barlow Twins and VICReg each proposed a different non-contrastive route: a predictor with stop-gradient, a cross-correlation objective, and an explicit variance and covariance regulariser.

Dimensional collapse is the name given to the subtler failure, where the embeddings span only a few directions. The exact dates of its naming are uncertain, so this lesson does not give one. Joint-embedding predictive models such as Joint-Embedding Predictive Architecture face the same trivial-solution risk, and their lesson covers the exponentially averaged target encoder that they use against it, described in Exponential Moving Average.

Check yourself

QuestionIn one sentence, what is the difference between complete collapse and dimensional collapse?Show answer

Complete collapse means every embedding is the same vector, so the covariance matrix is zero and its rank is 0. Dimensional collapse means the embeddings vary but spread along only a few directions, so the covariance has rank below the feature dimension dd or a small effective rank.

QuestionThree embeddings in R2\mathbb{R}^2 are (1,1)(1, 1), (2,2)(2, 2) and (3,3)(3, 3). Find the covariance matrix, its eigenvalues, and the effective rank.Show answer

The mean is (2,2)(2, 2), so the centred points are (−1,−1)(-1, -1), (0,0)(0, 0) and (1,1)(1, 1). Every entry of ∑z~iz~i⊤\sum \tilde{\mathbf{z}}_i \tilde{\mathbf{z}}_i^\top is 2, so C=13(2222)C = \tfrac{1}{3}\begin{pmatrix} 2 & 2 \\ 2 & 2 \end{pmatrix}. The trace is 43\tfrac{4}{3} and the determinant is 49−49=0\tfrac{4}{9} - \tfrac{4}{9} = 0, so the eigenvalues are 43\tfrac{4}{3} and 00. Then p=(1,0)p = (1, 0) and erank⁡=1\operatorname{erank} = 1. The points lie on a line, so the representation is dimensionally collapsed.

QuestionWhy does a positive-only objective allow collapse, while InfoNCE with negatives does not reach zero loss at collapse?Show answer

A positive-only objective such as negative cosine similarity between two views is minimised when all embeddings point the same way, and nothing in it penalises that. InfoNCE includes the other items in the batch in its denominator. When every embedding is identical, each anchor's loss equals log⁡(2N−1)\log(2N-1), the loss of a uniform guess among the candidates, which is above zero and above the loss of any state that separates the examples. The negatives therefore make collapse a poor solution.

QuestionA self-supervised encoder's training loss drops steadily, but a linear classifier on its features is only slightly better than chance. Which check would you run first, and what would you do if it showed a problem?Show answer

Measure the per-dimension standard deviation and the effective rank of the covariance matrix on a held-out batch. If both are low, the encoder has collapsed or nearly collapsed, despite the loss. Fixes include adding negatives or a larger batch, using a predictor with stop-gradient, adding a variance and covariance penalty, or strengthening the augmentations so the two views differ more.

Sources