Understanding Contrastive Learning via Distributionally Robust Optimization

Junkang Wu, Jiawei Chen, Jiancan Wu, Wentao Shi, Xiang Wang, Xiangnan He

Abstract

Contrastive Learning (CL) has emerged as a powerful paradigm for self-supervised representation learning, yet its success despite significant sampling bias remains a theoretical puzzle. This paper provides a new perspective by establishing a formal equivalence between the InfoNCE loss and Distributionally Robust Optimization (DRO). We demonstrate that the temperature hyperparameter $\tau$ functions as a Lagrange multiplier that controls the robustness radius against distribution shifts in negative samples. To address the tendency of standard DRO to over-index on outliers, we propose ADNCE (Adjusted InfoNCE), which utilizes Gaussian-like weighting to focus on the most informative negative samples. Our framework is validated across computer vision, natural language processing, and graph learning tasks, showing improved performance and robustness.

Introduction

In standard Contrastive Learning, models are trained to pull "positive" pairs (e.g., different augmentations of the same image) together while pushing "negative" pairs (different images) apart. A persistent challenge in this setup is sampling bias: many negatives are semantically similar to the anchor (e.g., two different images of dogs), yet the model is forced to treat them as distinct. Theoretically, this should degrade performance, but CL remains highly effective.

Existing explanations often rely on Mutual Information (MI) maximization or "hard-mining" heuristics. However, these do not fully explain why CL is robust to false negatives or what specific role the temperature parameter $\tau$ plays beyond simple scaling. This work addresses these gaps by reframing CL as a form of DRO.

Contrastive Learning as Distributionally Robust Optimization

The core contribution of this paper is the mathematical proof that the InfoNCE loss is equivalent to performing DRO over the negative sampling distribution. DRO optimizes a model against the "worst-case" distribution within a defined uncertainty set, ensuring performance is stable even under distribution shifts.

Temperature as a Robustness Controller

Through this lens, the temperature parameter $\tau$ is revealed to be a Lagrange coefficient. It regulates the size of the potential distribution set, or the "robustness radius." A smaller $\tau$ makes the model more sensitive to hard negatives, effectively narrowing the focus to the worst-case scenarios. This theoretical grounding explains why $\tau$ is critical for balancing the trade-off between learning from hard samples and maintaining robustness to noise.

Robustness of relative accuracy to the temperature parameter τ under varying noise ratios. The optimal τ shifts as the noise level changes, supporting its role as a robustness controller.

ADNCE: Refining the Informative Region

While standard DRO provides robustness, it can be overly conservative by focusing excessively on the absolute hardest negatives. In many datasets, these "hardest" samples are actually outliers or noisy labels that provide poor learning signals.

To mitigate this, we introduce ADNCE (Adjusted InfoNCE). Instead of the exponential weighting used in standard InfoNCE—which puts maximum weight on the highest similarity scores—ADNCE employs Gaussian-like weights. This reshapes the "worst-case" distribution to focus on a specific "informative region" of high-similarity negatives while discounting extreme outliers.

Comparison of weight scales for InfoNCE and the proposed ADNCE (w) across similarity scores. ADNCE shifts focus from extreme outliers to a more informative region of similarity.

Key Insights and Results

  • Inherent Robustness: CL is mathematically structured to handle sampling bias by optimizing for the worst-case negative distribution, naturally mitigating the impact of false negatives.
  • Mean-Variance Trade-off: The authors derive a mean-variance approximation showing that CL implicitly introduces a variance regularizer on negative samples, contributing to its empirical success.
  • Empirical Performance: ADNCE consistently outperforms standard InfoNCE baselines. On the STL-10 image dataset, ADNCE achieved 88.00% top-1 accuracy, a significant jump from the 81.67% baseline. Similar gains were observed in NLP (improving average Spearman’s correlation to 77.10% on STS tasks) and graph representation learning.
  • Faster Convergence: By avoiding the "outlier trap," ADNCE demonstrates more stable training and faster convergence in early epochs compared to standard contrastive methods.

Conclusion

By viewing Contrastive Learning through the lens of Distributionally Robust Optimization, we provide a rigorous theoretical foundation for its empirical success and the critical role of the temperature parameter. The proposed ADNCE method offers a practical way to leverage this theory, focusing the model on informative samples rather than noisy outliers. Future work will explore making the Gaussian weighting parameters ($\mu$ and $\sigma$) adaptive to further automate the optimization process.

Summary updated

BibTeX
@inproceedings{wu2023understanding,
  author = {Junkang Wu and Jiawei Chen and Jiancan Wu and Wentao Shi and Xiang Wang and Xiangnan He},
  title = {{Understanding Contrastive Learning via Distributionally Robust Optimization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=5XshcizH9w},
}
Figure