Rank-N-Contrast: Learning Continuous Representations for Regression

Kaiwen Zha, Peng Cao, Jeany Son, Yuzhe Yang, Dina Katabi

Overview

Rank-N-Contrast (RNC) is a novel representation learning framework designed to ensure that the internal features learned by a neural network reflect the continuous nature of regression targets. By contrasting samples based on their relative rankings in the target space, RNC creates a smooth, ordered embedding manifold. This approach significantly improves accuracy, data efficiency, and robustness across a variety of computer vision and healthcare tasks.

The Problem: Fragmented Representations in Regression

In deep learning, regression is typically treated as an end-to-end distance-minimization problem. Models are trained to make their final predictions as close to the ground truth (e.g., age or temperature) as possible using standard loss functions like $L_1$ or Mean Squared Error (MSE).

However, this standard approach ignores a fundamental property of regression: continuity. While the final output is a continuous number, the internal representations (embeddings) learned by the model often become fragmented. For instance, in a weather-prediction task, a standard model might group images by spurious features—like which camera took the photo—rather than the actual temperature. This lack of a "regression-aware" representation leads to brittle models that are inefficient and struggle to generalize to unseen values.

Comparison of learned feature representations. Standard methods like L1 and SupCon result in fragmented clusters, while RNC learns a continuous, ordered manifold.

The Solution: Rank-N-Contrast (RNC)

To address this, the authors introduce the Rank-N-Contrast (RNC) loss. Unlike standard contrastive learning methods (such as SimCLR or SupCon) that treat samples in a binary "same" or "different" manner, RNC leverages the continuous rank of the targets.

RNC constructs pairs by ranking samples based on their target distance from the anchor. Closer targets form positive pairs, while distant targets form negative pairs.

The RNC framework operates through a structured process:

  1. Ranking: For any given "anchor" image in a batch, RNC evaluates all other images and ranks them based on how far their target values are from the anchor's target.
  2. Contrasting: The loss function forces the model to pull the anchor’s embedding closer to samples with similar targets (positive pairs) and push it farther from samples with distant targets (negative pairs), proportional to their rank distance.
  3. Two-Stage Training: First, the model learns these ordered representations using the RNC loss. Second, the encoder is frozen, and a simple linear regressor is trained on top of these features to produce the final numerical prediction.

The authors provide theoretical guarantees that optimizing this loss results in strictly ordered features, meaning the distances in the model's latent space directly correspond to the distances between real-world labels.

Key Insights and Results

The researchers evaluated RNC across five diverse, real-world datasets spanning computer vision, human-computer interaction, and healthcare (including AgeDB, IMDB-WIKI, TUAB Brain-Age, MPIIFaceGaze, and SkyFinder).

  • Representation over Prediction: RNC shifts the focus from merely outputting the right number to learning the right underlying structure. A well-structured, continuous internal representation makes the final prediction task trivial.
  • State-of-the-Art Performance: RNC consistently outperformed existing regression baselines, reducing prediction error by an average of 5.8% to 11.7% across the tested datasets. Furthermore, it can be used as a pre-training step for existing regression architectures, consistently boosting their performance.
  • Fighting Spurious Correlations: RNC helps models ignore "easy" but irrelevant features. In the SkyFinder dataset, standard models clustered images by camera ID. RNC forced the model to ignore the camera and focus entirely on the temperature manifold.
  • Zero-Shot Generalization & Data Efficiency: Because RNC learns a continuous curve of representations, it excels at interpolation. It can accurately predict values it hasn't explicitly seen during training. Additionally, RNC is highly data-efficient; models trained with RNC on just 4,000 samples outperformed standard models trained on 16,000 samples.
  • Robustness: When tested on corrupted data (images with blur, noise, or weather artifacts), RNC maintained significantly higher accuracy than standard models, proving its learned features are more fundamental and resilient.

Limitations and Future Work

While RNC excels at ignoring irrelevant features, it cannot distinguish between a "real" target and a "spurious" one if they are perfectly correlated in the training data. Additionally, RNC currently requires labeled data to perform its ranking. Future work may explore adapting this continuous ranking logic to unlabeled data in self-supervised settings, as well as investigating how these continuous representations impact fairness across different demographic subgroups.

Summary updated

BibTeX
@inproceedings{zha2023rank,
  author = {Kaiwen Zha and Peng Cao and Jeany Son and Yuzhe Yang and Dina Katabi},
  title = {{Rank-N-Contrast: Learning Continuous Representations for Regression}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=WHedsAeatp},
}
Figure