Skip to content
AI360Xpert
Beta

Barlow Twins Identity Target

Line up two views of one photo feature by feature, keep matching slots near one, and push different slots toward zero. Redundancy falls and useful factors stay.

Barlow Twins drives the cross-correlation of two views toward identity
Barlow Twins drives the cross-correlation of two views toward identity

Why Does This Exist?

Contrast can keep redundant features because any correlated pair still matches. Barlow Twins asks for more: each feature slot should match itself across views and ignore other slots. That cuts redundancy directly. Readers who know siamese networks get the twin shape; the new part is the matrix target, not a pair list.

This page covers the correlation loss only. Pair losses live in contrastive loss.

The one idea you need first.

Cross-correlation CC is a d×dd \times d matrix over a batch: CijC_{ij} is the correlation of slot ii in view A with slot jj in view B. Identity means ones on the diagonal and zeros elsewhere.

Think of It Like This

Two choirs singing the same score in tune

Two choirs sing one score in separate rooms. Matching voice parts should agree note for note, while soprano should not copy bass. A judge scores tuning within parts and leakage across parts.

Diagonal ones are in-tune parts, off-diagonal zeros are no leakage, and weight 0.0050.005 sets how harshly leakage counts. Where it stops: choirs hear each other, while the two views train from separate crops.

How It Actually Works

Normalize projector outputs zAz^A and zBz^B over the batch to zero mean and unit variance per slot. Form C=(ZA)TZB/NC = (Z^A)^T Z^B / N for batch size NN. Loss is L=∑i(1−Cii)2+λ∑i≠jCij2L = \sum_i (1-C_{ii})^2 + \lambda \sum_{i \ne j} C_{ij}^2 with λ=0.005\lambda = 0.005 and width d=8192d = 8192.

In plain words: NN averages over the batch, dd is the wide projector, and λ\lambda trades invariance against decorrelation.

Worked example

Say d=2d = 2 and measured C=[[0.9,0.2],[0.1,0.85]]C = [[0.9, 0.2],[0.1, 0.85]]. Diagonal terms give (0.1)2+(0.15)2=0.01+0.0225=0.0325(0.1)^2 + (0.15)^2 = 0.01 + 0.0225 = 0.0325. Off-diagonal give 0.04+0.01=0.050.04 + 0.01 = 0.05, times 0.0050.005 is 0.000250.00025. Total 0.032750.03275. Training pushes diagonals to 11 and wipes the 0.20.2 leak, which is exactly redundancy leaving the code.

Watch Out For

Small projector that hides the gain

A 256-dim head cannot hold 8192 decorrelated slots, so off-diagonal pressure does little. The symptom is weak transfer despite low loss. Use a wide projector near 8192 and batch-norm on its output beforeStats.

The Quick Version

  • Barlow Twins matches two views by driving cross-correlation toward identity.
  • Diagonal ones demand view invariance per slot.
  • Off-diagonal zeros with weight 0.005 cut redundancy.
  • Wide projectors near 8192 dims matter.
  • No negatives, queues, or cluster passes are used.