Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Agree across views, and do not repeat yourself
Barlow Twins gives a network two jobs. First, each feature should come out the same for two altered views of the same image. Second, different features should not duplicate each other: if feature 3 already tells you something, feature 7 should tell you something else. Together these stop the network from collapsing, because a network that outputs the same thing in every feature fails the second job. The demo shows the cross-correlation matrix that Barlow Twins pushes toward the identity.
Decorrelated, non-redundant features are compact and efficient: valuable for embedded perception, compression and downstream models with little labelled data.
- 1. Barlow Twins pushes the cross-correlation matrix toward…
- 2. Off-diagonal terms near zero mean features are…
- 3. Barlow Twins needs negatives?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Cross-correlation: C_ij = Σ_b z^A_(b,i) z^B_(b,j) / B, with each feature standardised over the batch.
- Loss: L = Σ_i (1 − C_ii)² + λ Σ_(i≠j) C_ij².
- Diagonal (1, 1, 0.5) gives an invariance term of 0.25.
- Off-diagonal entries ±0.5 in a 2 × 2 matrix give a redundancy term of 0.5.
- Diagonal (0.9, 0.9), an off-diagonal sum of squares of 2 and λ = 0.05 give 0.02 + 0.1 = 0.12.
- Scale of λ: d dimensions have d(d − 1) off-diagonal terms, 67 million for d = 8192. The paper used λ = 0.005 with an 8192-D projector.
- Why standardise: batch standardisation fixes every feature’s variance at 1, so the trivial constant solution is impossible. Redundant solutions (all features equal) remain possible without the off-diagonal term.
- 1. Invariance term for diagonal (1, 1, 0.5):
- 2. Off-diagonal terms for d = 4:
- 3. Without the off-diagonal term, features can become…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Barlow Twins in code
Exercise 1.
- The cross-correlation of a batch with itself had a unit diagonal and zero loss.
- Nearly identical (redundant) features had near-zero loss at λ = 0, but a large loss once λ > 0.
Practice.
- Use a wide projector (8192-D in the paper) with batch norm, LARS, and λ ≈ 1/d.
- Barlow Twins works with batches of 256 or less.
- Watch the off-diagonal mass and the effective rank of the projector outputs during training.
za = (za - za.mean(0)) / za.std(0); zb = (zb - zb.mean(0)) / zb.std(0)
C = za.T @ zb / za.shape[0] # d x d cross-correlation
on = (torch.diagonal(C) - 1).pow(2).sum()
off = C.pow(2).sum() - torch.diagonal(C).pow(2).sum()
loss = on + lam * off- 1. Barlow Twins prefers projectors that are…
- 2. A typical λ is about…
- 3. Barlow Twins batch sizes:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Redundancy reduction.
- Horace Barlow (1961) proposed that sensory systems recode inputs into statistically independent components.
- Barlow Twins applies a second-order version: decorrelate features while keeping them invariant to augmentations.
- Combined with per-feature standardisation, this rules out complete collapse (variance is fixed at 1) and dimensional collapse (correlated features are penalised).
Information view. Under a Gaussian assumption, the loss relates to an information-bottleneck objective: maximise information shared between views (invariance) while spreading it across independent features.
Collapse modes.
- Complete collapse: all embeddings equal. Prevented by standardisation.
- Dimensional collapse: embeddings span few directions. Prevented by the off-diagonal term.
- With λ = 0, the invariance term alone is satisfied by making all features copies of one invariant feature: maximal redundancy, minimal information.
- 1. Barlow's 1961 principle:
- 2. Standardisation prevents…
- 3. The off-diagonal term prevents…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.What does the redundancy term buy?
History.
- H. Barlow, “Possible principles underlying the transformation of sensory messages” (1961).
- J. Zbontar, L. Jing, I. Misra, Y. LeCun and S. Deny, “Barlow Twins: self-supervised learning via redundancy reduction” (ICML 2021).
Exercise 2.
- Setup: the same style-dominated world as before, with encoder 32 → 64 → 16 and projector 16 → 32 → 16, 1000 steps.
- Training: the Barlow Twins loss on batch-standardised projections, with λ = 0, 0.005, 0.05 or 0.5.
- Measurements: probe accuracy and the effective rank of the standardised projector outputs (of 16).
| λ | probe accuracy | projector effective rank |
|---|---|---|
| raw observations | 0.522 | — |
| 0 (invariance only) | 0.462 | 1.77 |
| 0.005 | 0.586 | 4.49 |
| 0.05 | 0.752 | 8.53 |
| 0.5 | 0.748 | 13.57 |
- Without redundancy reduction, the features become copies: at λ = 0 the 16 projector features have an effective rank under 2, nearly perfectly correlated. The probe stays near raw (0.46; seeds 1 and 2 gave 0.61 and 0.53).
- The redundancy term spreads information: the rank rises steadily with λ, by 7.7-fold from λ = 0 to 0.5, and the probe reaches 0.75 for λ ≥ 0.05 (seeds 1 and 2: 0.70–0.77).
- λ needs to be large enough: 0.005 (the paper’s value for 8192 dimensions) is too small for 16 dimensions, consistent with the rule λ ≈ 1/d.
Barlow Twins in AI, robotics and aerospace
- Compact sensor features: decorrelated embeddings for efficient onboard storage and downstream learning.
- Multimodal fusion: cross-correlation objectives between sensors (camera and lidar views of the same scene).
- Design lesson: an objective should rule out both complete and dimensional collapse. Measure effective rank, not just loss.
References
- J. Zbontar, L. Jing, I. Misra, Y. LeCun and S. Deny (2021). “Barlow Twins: self-supervised learning via redundancy reduction.” Proc. ICML.
- H. B. Barlow (1961). “Possible principles underlying the transformation of sensory messages.” In Sensory Communication, MIT Press.
- L. Jing, P. Vincent, Y. LeCun and Y. Tian (2022). “Understanding dimensional collapse in contrastive self-supervised learning.” ICLR.