A Tale of Two Classes: Adapting Supervised Contrastive Learning to Binary Imbalanced Datasets

David Mildenberger, Paul Hager, Daniel Rueckert, M. Menten
2/10/2026

No official code found. Best implementation: aiforvision/TTC (11 stars, MIT, last commit 2025-05-22).

Abstract

Supervised contrastive learning (SupCon) has proven to be a powerful alternative to the standard cross-entropy loss for classification of multi-class balanced datasets. However, it struggles to learn well-conditioned representations of datasets with long-tailed class distributions. This problem is potentially exacerbated for binary imbalanced distributions, which are commonly encountered during many real-world problems such as medical diagnosis. In experiments on seven binary datasets of natural and medical images, we show that the performance of SupCon decreases with increasing class imbalance. To substantiate these findings, we introduce two novel metrics that evaluate the quality of the learned representation space. By measuring the class distribution in local neighborhoods, we are able to uncover structural deficiencies of the representation space that classical metrics cannot detect. Informed by these insights, we propose two new supervised contrastive learning strategies tailored to binary imbalanced datasets that improve the structure of the representation space and increase downstream classification accuracy over standard SupCon by up to 35%. We make our code available.1

View on arXivView PDF

Code Implementations(1)

aiforvision/TTCCommunity58%
MIT

Official PyTorch implementation for the paper: A Tale of Two Classes - Adapting Supervised Contrastive Learning to Binary Imbalanced Datasets

112PythonMar 27, 20251 years agoMIT

Similar Papers

Cite this paper

@article{mildenberger2026tale,
  title  = {A Tale of Two Classes: Adapting Supervised Contrastive Learning to Binary Imbalanced Datasets},
  author = {David Mildenberger and Paul Hager and Daniel Rueckert and M. Menten},
  year   = {2026},
  eprint = {2503.17024},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2503.17024},
  journal = {CVPR 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.17024.svg)](https://codeofpaper.com/paper/2503.17024)

Discussion