Conditional Contrastive Learning with Kernel

Yao-Hung Hubert Tsai, Tianqin Li, Martin Q. Ma, Han Zhao, Kun Zhang, Louis-Philippe Morency, Ruslan Salakhutdinov

Abstract

Conditional Contrastive Learning with Kernel (CCL-K) solves a major bottleneck in contrastive learning: the "insufficient data" problem that occurs when trying to sample data pairs conditioned on specific variables (like attributes or sensitive features). By replacing discrete sampling with a continuous kernel-based weighting scheme, CCL-K allows models to leverage the entire dataset for conditioning, even when the conditioning variables are continuous or high-dimensional.

The Challenge of Conditional Sampling

Contrastive learning has become a cornerstone of modern AI, teaching models to recognize similarities by comparing "positive" pairs (e.g., two views of the same object) and "negative" pairs (e.g., two different objects). Conditional Contrastive Learning (CCL) takes this a step further by choosing these pairs based on specific variables ($Z$). Common applications include:

  • Fairness: To remove bias, negative pairs might be sampled from the same demographic group so the model learns to ignore group-specific features.
  • Weak Supervision: Positive pairs might be sampled based on shared metadata (e.g., "blue sky") to bake that information into the representation.

The primary gap in traditional CCL is its reliance on a conditional sampling procedure. If an algorithm needs to sample a pair of images that both share a rare attribute, the lack of exact matches causes the process to break down. This problem is exacerbated for continuous variables (like exact RGB values or coordinates), where the probability of finding two data points with the exact same value is effectively zero. Historically, researchers have resorted to "binning" or clustering these values, which discards precision and degrades performance.

Comparison of Traditional Conditional Sampling vs. CCL-K

CCL-K: A Kernel-Based Solution

To overcome the limitations of hard sampling, the authors introduce CCL-K, which transitions to a "soft" kernel-based estimation approach.

Instead of searching for a data point that exactly matches a specific condition $z$, CCL-K utilizes the Kernel Conditional Embedding Operator (KCEO). This mathematical framework allows the model to:

  1. Leverage All Available Data: Every point in a mini-batch contributes to the contrastive loss, eliminating the data sparsity issue.
  2. Assign Continuous Weights: Each point is assigned a weight based on its kernel similarity to the target condition. For instance, if conditioning on "age 80," an image of a 79-year-old receives a high weight, while a 20-year-old receives a near-zero weight.
  3. Kernelize the Objective: The authors reformulate standard contrastive objectives (like InfoNCE) into kernel expressions. This involves calculating a Gram matrix for the data ($K_{XY}$) and a Gram matrix for the conditioning variables ($K_Z$).

Essentially, CCL-K transforms the problem from finding an exact match to weighting the entire dataset based on conditional similarity.

Experimental Setup and Key Insights

The authors evaluated CCL-K across diverse tasks, including Weakly Supervised learning (UT-Zappos, CUB-200-2011), Fairness (ColorMNIST), and Hard Negative mining (CIFAR-10).

Several key insights emerged from the framework:

  • Smoothing as a Solution: The kernel approach acts as a "smoother." By allowing data points with similar conditions to support the learning process, the model becomes much more stable in data-sparse regimes.
  • Elimination of Binning: Because the method handles continuous variables naturally via kernels (like RBF or Cosine kernels), researchers no longer need to manually discretize their data into arbitrary clusters.
  • Plug-and-Play Versatility: The kernel approach can be applied to three distinct goals—incorporating extra info (Weak Supervision), removing unwanted info (Fairness), and finding difficult examples (Hard Negatives)—using the same underlying logic.
  • Computational Efficiency: While matrix inversion can be computationally expensive ($O(b^3)$), operating on mini-batches ($b$) keeps the cost negligible compared to the neural network's gradient updates.

Key Results

CCL-K consistently outperformed state-of-the-art baselines that rely on traditional sampling or clustering:

  • Weakly Supervised Learning: On the CUB bird dataset, CCL-K achieved 29.9% accuracy, a massive jump over standard InfoNCE (14.1%) and the previous conditional baseline (20.6%).
  • Fairness: On ColorMNIST, CCL-K maintained high classification accuracy while significantly increasing the Mean Square Error (MSE) for color prediction. In fairness tasks, a higher MSE for the sensitive attribute indicates the model has successfully "forgotten" the biased information.
  • Hard Negatives: On CIFAR-10, CCL-K improved accuracy by 1.8% over standard contrastive learning by more effectively weighting "hard" negatives that are close in the embedding space.
Performance comparison showing CCL-K improving accuracy and fairness metrics

Limitations and Future Directions

While highly effective, CCL-K requires the conditioning variable $Z$ to be predefined; it cannot automatically discover which variables are "sensitive" or "auxiliary" without human input. Additionally, while results were generally consistent across different kernels (RBF, Laplacian, etc.), performance can be sensitive to hyper-parameters like the kernel bandwidth ($\sigma^2$). Future work may explore more flexible similarity measurements beyond standard kernels to add even greater adaptability to the framework.

Summary updated

BibTeX
@inproceedings{tsai2022conditional,
  author = {Yao-Hung Hubert Tsai and Tianqin Li and Martin Q. Ma and Han Zhao and Kun Zhang and Louis-Philippe Morency and Ruslan Salakhutdinov},
  title = {{Conditional Contrastive Learning with Kernel}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=AAJLBoGt0XM},
}
Figure