Course contentsShow
← Machine Learning and Deep Learning
Lesson 2535 of 3,53855. Self-Supervised LearningFree lesson

Positive and Negative Pairs

Defining positive pairs (augmented views of same sample) and negative pairs (different samples) for contrastive objectives.

Positive and Negative Pairs

What you'll learn: How contrastive learning distinguishes between similar and dissimilar samples using positive and negative pairs.

The Core Concept

In contrastive learning, the model learns by comparing examples. To make these comparisons meaningful, we define two types of relationships:

  • Positive pairs: Two versions of the same sample that should be treated as similar
  • Negative pairs: Two versions of different samples that should be treated as dissimilar

The model's job is to pull positive pairs closer together in the representation space while pushing negative pairs farther apart.

How Positive Pairs Are Created

Positive pairs typically come from data augmentation. Take a single image and apply two different random transformations—maybe one is rotated and cropped, the other is color-jittered and flipped. These two augmented views are your positive pair. They look different visually, but semantically they represent the same underlying content.

Think of it like recognizing your friend: whether they're wearing sunglasses, standing in shadow, or viewed from the side, you still know it's them. Those are all "positive pairs" of the same person.

How Negative Pairs Are Created

Negative pairs are simpler: they're just augmented views of different samples from your dataset. If you have images of a cat and a dog, any augmentation of the cat paired with any augmentation of the dog forms a negative pair.

Why This Matters

This pairing strategy teaches the model to be invariant to augmentations (learning that different views of the same thing are fundamentally the same) while being sensitive to semantic content (learning that different things are actually different). The contrastive loss function uses these pairs to create a meaningful representation space without requiring labels.

Key Takeaway: Positive pairs are augmented views of the same sample that should have similar representations, while negative pairs are from different samples that should be distinguishable—this contrast drives self-supervised learning.