Temperature Schedules for Self-Supervised Contrastive Methods on Long-Tail Data

Anna Kukleva, Moritz Böhle, Bernt Schiele, Hilde Kuehne, Christian Rupprecht · DOI

Abstract

Self-supervised learning (SSL) has achieved remarkable success on balanced datasets, yet its performance often falters on real-world data characterized by long-tailed distributions. In contrastive learning, the temperature hyperparameter ($\tau$) plays a pivotal role in balancing the focus between global semantic clustering and local instance discrimination. This paper explores the fundamental trade-off imposed by a fixed temperature and proposes a simple, computationally efficient solution: a cosine temperature schedule. By oscillating $\tau$ during training, the model effectively switches between learning broad category structures and fine-grained details, leading to significant performance gains on long-tailed benchmarks like CIFAR-LT and ImageNet-LT.

Introduction

Most self-supervised learning algorithms are developed and tuned using perfectly balanced datasets such as ImageNet. However, real-world data is rarely uniform; it typically follows a "long-tail" distribution where a few categories (the "head") contain the majority of samples, while many categories (the "tail") are represented by only a few instances.

In contrastive learning (CL), models learn representations by pulling positive pairs (different views of the same image) together and pushing negative pairs (different images) apart. A critical component of this loss function is the temperature parameter ($\tau$), which scales the similarity scores. While $\tau$ is traditionally kept constant, this paper demonstrates that a fixed value forces a sub-optimal compromise between the needs of head and tail classes.

The Temperature Trade-off

The authors identify a fundamental tension in how temperature affects the learning process:

  1. Large $\tau$ (Group-wise Discrimination): A higher temperature encourages the model to form dense semantic clusters. This is beneficial for common "head" classes, as it helps the model capture broad semantic similarities across many samples.
  2. Small $\tau$ (Instance Discrimination): A lower temperature forces the model to distinguish sharply between individual images. This is crucial for rare "tail" classes, preventing them from being "swallowed" or collapsed into larger, more dominant clusters.

On long-tailed data, a single fixed temperature cannot satisfy both requirements. High temperatures neglect the distinctiveness of rare samples, while low temperatures may prevent the formation of useful semantic groupings for common classes.

Methodology: Cosine Temperature Scheduling

To break this trade-off, the researchers introduce the Temperature Schedule (TS). Instead of a static value, the temperature oscillates between an upper bound ($\tau_+$) and a lower bound ($\tau_-$) following a cosine wave over the course of training.

The schedule is defined as: $$\tau_{cos}(t) = \frac{(\tau_+ - \tau_-) \times (1 + \cos(2\pi t/T))}{2} + \tau_-$$

Where $t$ is the current epoch and $T$ is the period of oscillation. This creates a "task-switching" effect: during high-temperature phases, the model focuses on global structure; during low-temperature phases, it refines its focus on instance-level details.

Crucially, this is a "drop-in" modification. It requires no changes to the neural network architecture, adds zero computational overhead, and does not increase memory usage, making it highly accessible for practical applications.

Experimental Results

The method was evaluated on long-tailed versions of standard benchmarks (CIFAR10-LT, CIFAR100-LT, and ImageNet100-LT) using popular frameworks like MoCo-v2 and SimCLR.

Performance Gains

The implementation of a temperature schedule yielded consistent improvements across the board:

  • CIFAR10-LT: Using MoCo-v2 with an imbalance ratio of 100, the temperature schedule improved kNN accuracy from 63.54% to 64.99%.
  • Tail Class Accuracy: The most significant gains were observed in the rare classes. In CIFAR100-LT, SimCLR with TS improved tail-class kNN accuracy by nearly 15% relative to the baseline.
  • Efficiency vs. Complexity: The proposed method outperformed SDCLR, a more complex state-of-the-art method that requires model pruning and additional memory. This highlights that optimizing the training dynamics of existing losses can be more effective than adding architectural complexity.

Theoretical Insights

The authors provide a novel theoretical lens by viewing contrastive loss as "average distance maximization." They demonstrate that as $\tau \to \infty$, the loss is dominated by the cumulative contribution of many distant negatives, which naturally facilitates clustering. Conversely, as $\tau$ decreases, the loss becomes more sensitive to the nearest neighbors.

Furthermore, the study found that smooth oscillation (the cosine schedule) performs better than random temperature sampling. This suggests that the rhythmic alternation between broad and fine-grained learning is beneficial to the optimization process, allowing the model to progressively refine its representation space.

Conclusion and Future Work

Temperature scheduling offers a simple yet powerful tool for improving self-supervised learning on imbalanced data. By recognizing that different classes and training stages require different levels of discriminative granularity, the cosine schedule provides a robust mechanism to handle the challenges of long-tailed distributions.

While this study focused on contrastive methods using Info-NCE loss, future research could investigate whether similar dynamics benefit non-contrastive methods like BYOL or Barlow Twins. Additionally, the development of adaptive schedules—where the temperature changes based on the model's internal state rather than a fixed clock—remains a promising avenue for further optimization.

Summary updated

BibTeX
@inproceedings{kukleva2023temperature,
  author = {Anna Kukleva and Moritz Böhle and Bernt Schiele and Hilde Kuehne and Christian Rupprecht},
  title = {{Temperature Schedules for Self-Supervised Contrastive Methods on Long-Tail Data}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=ejHUr4nfHhD},
}
Figure