...

/

Contrastive Learning: The SimCLR Algorithm

Contrastive Learning: The SimCLR Algorithm

Get an overview of a widely used contrastive learning algorithm: SimCLR.

What is contrastive learning?

The objective of contrastive learning is to learn neural network embeddings such that embeddings from related images should be closer than embeddings from unrelated or dissimilar images. So, given an image XaX_a, we can call it an “anchor image” and define two terms:

  • Positives: Images that are closely related to the anchor image, XaX_a. Let’s represent them by XpX_p

  • Negatives: Images that are unrelated or dissimilar to XaX_a. Let’s call them XnX_n.

The contrastive learning objective thus learns a neural network f(.)f(.) such that:

Here, sim(. , .)\text{sim}(. \ ,\ .) is any similarity measure (e.g., cosine similarity). Therefore, we need to maximize the similarity between positive pairs and minimize the similarity between negative pairs. This is illustrated in the figure below.

Press + to interact
Contrastive learning
Contrastive learning

Contrastive loss

To enforce the contrastive property, we can define a contrastive loss function as follows:

Here, fa=f(Xa)f_a = f(X_a), fp=f(Xp) ...