Contrastive Attraction and Contrastive Repulsion for Representation Learning

Huangjie Zheng, Xu Chen, Jiangchao Yao, Hongxia Yang, Chunyuan Li, Ya Zhang, Hao Zhang, Ivor Tsang, Jingren Zhou, Mingyuan Zhou

Abstract

Contrastive learning (CL) methods effectively learn data representations in a self-supervision manner, where the encoder contrasts each positive sample over multiple negative samples via a one-vs-many softmax cross-entropy loss. However, most existing methods rely on a binary partition that insufficiently considers the nuanced relations between samples, often leading to suboptimal performance on uncurated, real-world datasets. We propose a doubly CL strategy, Contrastive Attraction and Contrastive Repulsion (CACR), which adaptively weights samples based on their difficulty. CACR exerts a greater force to attract distant positive samples and repel closer negative samples. Theoretical analysis shows that CACR generalizes standard CL and narrows the gap between sampled and true distributions. Extensive experiments demonstrate that CACR consistently outperforms existing CL methods on standard benchmarks and shows significantly better robustness on imbalanced datasets.

Introduction

Self-supervised representation learning has been revolutionized by Contrastive Learning (CL) frameworks such as SimCLR and MoCo. These methods typically employ a "one-vs-many" binary approach: augmented views of a single image are treated as positive pairs to be pulled together (attraction), while views from all other images in a batch are treated as negative pairs to be pushed apart (repulsion).

Despite its success, this binary partition is often too simplistic for "in the wild" data. It suffers from two primary limitations:

  1. Informational Blindness: Standard CL treats all negative pairs equally, failing to distinguish between "easy" negatives and "hard" negatives that are semantically similar but distinct.
  2. The Uniformity Trap: These losses implicitly assume a uniform data distribution. In uncurated or imbalanced datasets, this assumption fails, leading to poor generalization and collapsed class boundaries.

Methodology: The Doubly Contrastive Strategy

To address these issues, we propose Contrastive Attraction and Contrastive Repulsion (CACR). This "doubly contrastive" strategy moves beyond simple push-pull mechanisms by adaptively weighting samples based on their relative difficulty in the representation space.

Comparison between conventional contrastive learning and the proposed CACR strategy.

Contrastive Attraction (CA)

Instead of a uniform pull, CACR utilizes a distribution to determine the strength of attraction. Positive views that are distant in the representation space are identified as "hard" and assigned higher weights. This forces the encoder to learn features that are truly invariant even under heavy augmentation.

Contrastive Repulsion (CR)

Similarly, for negative samples, CACR identifies "hard negatives"—those currently too close to the query. The model exerts a stronger repulsive force on these samples while effectively ignoring "easy" negatives that are already well-separated.

Theoretical Foundation

Theoretical analysis demonstrates that CACR generalizes standard contrastive loss. The Repulsion mechanism acts as a bound on mutual information that does not strictly require a perfectly uniform representation space, making it inherently more robust to skewed or long-tailed data distributions.

Experimental Evaluation

We evaluated CACR across a diverse set of benchmarks, including standard datasets (CIFAR-10/100, ImageNet-1K), large-scale noisy data (Webvision v1), and custom imbalanced scenarios.

Key Results

  • State-of-the-Art Performance: On ImageNet-1K with a ResNet-50 backbone, CACR achieved 74.7% Top-1 accuracy, significantly outperforming MoCov2 (72.2%) and SimCLR (71.7%).
  • Robustness to Imbalance: In exponentially imbalanced CIFAR-100 tests, CACR maintained superior performance, with a drop of only 9.24% compared to the 12.57% drop seen in standard CL.
  • Superior Transferability: CACR outperformed MoCov3 on 15 out of 20 datasets in the ELEVATER benchmark, demonstrating more versatile learned representations.
  • Downstream Gains: CACR established new baselines for object detection and instance segmentation on MS COCO, surpassing non-contrastive methods like BYOL and SwAV.

Discussion and Conclusion

The success of CACR highlights that hard-sample awareness and intra-group relations are critical for robust representation learning. By focusing the "gradient budget" on distant positives and close negatives, the model more effectively refines class boundaries. This makes CACR particularly well-suited for real-world datasets that are often noisy or imbalanced.

While CACR shows significant improvements, future work could address the potential for "false negatives"—where samples of the same class are accidentally repelled. Despite a minor increase in per-iteration computational complexity, the gains in robustness and accuracy make CACR a powerful evolution of the contrastive learning paradigm.

For more details, see the full paper at https://openreview.net/forum?id=f39UIDkwwc.

Summary updated

BibTeX
@article{zheng2023contrastive,
  author = {Huangjie Zheng and Xu Chen and Jiangchao Yao and Hongxia Yang and Chunyuan Li and Ya Zhang and Hao Zhang and Ivor Tsang and Jingren Zhou and Mingyuan Zhou},
  title = {{Contrastive Attraction and Contrastive Repulsion for Representation Learning}},
  journal = {Accepted by TMLR},
  year = {2023},
  url = {https://openreview.net/forum?id=f39UIDkwwc},
}
Figure