Learning Paradigms

contrastive learning

/ kun-TRAS-tiv LER-ning /

Suppose you learn what a "dog" looks like not from labels, but by sorting a heap of photos: two snapshots of the same dog belong together; a dog and a bicycle belong apart. Do that millions of times and you build a strong sense of visual similarity without anyone naming a thing. Contrastive learning teaches a machine this way — by pulling similar things close together and pushing different things apart in its internal representation.

Mechanically, you take an example and make a "positive" pair — usually two altered versions of the same item, like a photo cropped and color-shifted two different ways — which should map to nearby points. Other items in the batch are "negatives," which should map far away. The model trains to minimize distance within positive pairs and maximize it to negatives. The labels here are free and automatic (you made the pairs yourself), which makes contrastive learning a leading form of self-supervised learning and a workhorse for learning good representations from unlabeled data.

Its payoff is representations that cluster meaningfully, so that a tiny labeled set — or even none — suffices for the downstream task. It powers modern image and image-text models. The honest engineering: it is sensitive to how you create the pairs (bad augmentations teach the wrong invariances), it usually needs many negatives to work well (large batches, hungry for memory), and it can collapse into a useless shortcut where everything maps to the same point unless the method is designed to prevent that.

Take one photo of a cat. Make two versions — one cropped and brightened, one flipped and recolored. Train the model to map these two close together (they're the same cat) and far from a photo of a car in the same batch. After millions of such comparisons, the model's representations cluster cats near cats and cars near cars, with no labels ever supplied.

Pull two views of the same thing together; push different things apart.

Contrastive learning lives or dies on its pairs: the augmentations you choose decide what the model treats as "the same." It also needs safeguards against collapse, where everything maps to one point and the representation becomes useless.

Also called
对比学习對比學習contrastive representation learning