NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Understanding and Generalizing Contrastive Learning from the Inverse Optimal Transport Perspective

Liangliang Shi, Gu Zhang, Haoyu Zhen, Jintao Fan, Junchi YanICML 2023

Overview

This paper reimagines Contrastive Learning (CL) not as a series of isolated pairwise comparisons, but as a collective set-matching problem. By framing CL through the lens of Inverse Optimal Transport (IOT), the authors demonstrate that the standard InfoNCE loss is just one specific case of a much broader family of transport-based losses. This novel perspective leads to improved representation learning and provides a more principled way to handle feature uniformity.

The Limitation of Pairwise Views

In standard Contrastive Learning frameworks like SimCLR or MoCo, the model learns by taking an "anchor" image and trying to pull its "positive" version (an augmentation) closer while pushing "negative" versions (other images in the batch) further away.

Pairwise contrasting vs. collective matching

The authors argue this pairwise view is fundamentally limited. It treats every pair in isolation, ignoring the global, geometric relationships between all samples in a mini-batch. Furthermore, the common theoretical justification for these losses—maximizing the lower bound of Mutual Information—has been criticized for being inconsistent in practice. This paper seeks a more robust framework to understand why contrastive learning works and how to optimize it collectively.

Methods: IOT-CL Framework

To address these limitations, the researchers propose IOT-CL, a framework that treats a mini-batch as two sets of points that need to be matched. They formulate this as a bilevel optimization approach:

The IOT-CL framework
  1. The Inner Problem (Optimal Transport): Given a "cost matrix" representing how different the features are, the model finds the optimal way to match the two sets of images. This results in a "coupling matrix" $P$, which represents the probability that image $i$ matches image $j$.
  2. The Outer Problem (Representation Learning): The neural network parameters are adjusted so that the "predicted" matching from the inner problem aligns with the "ground truth" matching (where an image only matches its own augmentation).

The flexibility of this framework lies in how the matching constraints are relaxed. By varying the "relaxation" of the constraints, the authors derive three distinct losses:

  • Loose ($U(1)$): Only requires the total probability to sum to 1.
  • Medium ($U(a)$): Requires each anchor to match something. Mathematically, this is equivalent to the famous InfoNCE loss.
  • Tight ($U(a, b)$): Requires a balanced one-to-one matching across the whole batch, which is solved using the Sinkhorn Algorithm.

Key Insights

  • InfoNCE is Optimal Transport: A major theoretical contribution of this work is the proof that the standard InfoNCE loss is a special case of IOT where constraints are only enforced on one side of the matching.
  • Temperature as Regularization: In traditional CL, a "temperature" hyperparameter ($\tau$) scales similarities. This paper proves that $ au$ is mathematically equivalent to the entropic regularization coefficient ($\epsilon$) used in Optimal Transport to turn "hard" assignments into "soft" probabilities.
  • The Uniformity Penalty: The IOT perspective naturally suggests a new penalty term. By encouraging the matching probabilities of negative pairs to be low and uniform, the model learns a more even distribution of features on the hypersphere, effectively preventing "feature collapse."

Empirical Results

The authors evaluated their framework on standard computer vision benchmarks, including CIFAR-10, CIFAR-100, SVHN, and ImageNet-100. The IOT-based losses consistently outperformed standard contrastive methods across various architectures:

  • Linear Evaluation: On CIFAR-10, IOT-CL achieved 91.06% accuracy compared to InfoNCE's 90.61%.
  • ImageNet-100: The proposed method with the uniformity penalty reached 68.32% top-1 accuracy, outperforming InfoNCE (67.35%) and other specialized methods like HNSampling.
  • Robustness: The new uniformity term significantly improved k-Nearest Neighbor (k-NN) classification performance, suggesting the underlying feature space is much better organized.

Limitations and Future Work

The authors note that their method is slightly less "natural" for memory-bank-based frameworks like the original MoCo. Because MoCo matches a small mini-batch against a massive queue of previous samples, the matching problem becomes skewed (few-vs-many). While they still demonstrated improvements in this setting, they suggest that newer "bank-less" versions (like MoCo v3) are a more natural fit for IOT-CL.

Future directions include applying this IOT perspective to other domains like long-tailed recognition, adversarial training, and graph matching, where the collective relationship between samples is even more critical than in standard image classification.

Summary updated

BibTeX
@inproceedings{shi2023understanding,
  author = {Liangliang Shi and Gu Zhang and Haoyu Zhen and Jintao Fan and Junchi Yan},
  title = {{Understanding and Generalizing Contrastive Learning from the Inverse Optimal Transport Perspective}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=DBlWCsOy94},
}
Figure