Semantically-Conditioned Negative Samples for Efficient Contrastive Learning

James O'Neill, Danushka BollegalaarXiv 2021

Contrastive learning has become a cornerstone of modern deep learning, powering everything from computer vision to natural language processing. However, its efficiency is often bottlenecked by how we choose "negative" examples—the samples the model is told not to look like. A new paper from researchers at the University of Liverpool, titled "Semantically-Conditioned Negative Samples for Efficient Contrastive Learning," proposes a more intelligent way to pick these negatives, leading to faster training and better accuracy.

The Challenge of Uniform Sampling

In contrastive learning, a model learns by pulling "positive" pairs (different views of the same image) closer together in a latent space while pushing "negative" pairs (different images) apart.

The standard approach uses Uniform Negative Sampling (USN), where negatives are picked at random from the dataset. The problem is that most random negatives are "easy." If you are training a model to recognize a Siberian Husky, comparing it to a picture of a toaster doesn't teach the model much about the fine-grained boundaries of the "dog" category. To learn effectively, the model needs "hard negatives"—samples that are similar enough to be confusing, like a Malamute or a Wolf.

Finding these hard negatives usually requires large batch sizes or complex memory banks, which are computationally expensive. This paper seeks to provide a more efficient, informed way to select these informative samples.

Methodology: SCNS and Latent Mixup

The authors propose three main strategies to move beyond random sampling:

  1. Class-Level SCNS: Instead of picking any random class as a negative, the model uses pretrained word embeddings (like skip-gram) of class labels. It calculates the cosine similarity between labels and samples negatives from the top-k most semantically similar classes.
  2. Instance-Level SCNS: This goes a step further by using a pretrained image classifier to find the top-k most similar specific images across the entire dataset, regardless of their class label.
  3. Latent Mixup (LM): Inspired by the "Mixup" data augmentation technique, the authors interpolate between the latent representations of positive and negative samples. This creates "pseudo-negatives" that lie right on the classification boundary, forcing the model to learn more robust features.
Semantic similarity heatmap showing how related classes (e.g., tractor and pickup truck) are identified for hard negative sampling.

Crucially, these methods are combined with a lookup table to store features, ensuring that the search for "hard" neighbors doesn't slow down the training loop.

Key Insights and Efficiency

  • Tightening the Bound: The authors provide a theoretical analysis showing that SCNS tightens the InfoNCE (Information Noise-Contrastive Estimation) lower bound on mutual information. By picking negatives that are "closer" to the anchor, the model receives a stronger signal about where the category boundaries actually lie.
  • Efficiency over Quantity: The paper demonstrates that the quality of negatives matters more than quantity. Using a few semantically relevant negatives is more effective than using thousands of random ones.
  • Faster Convergence: One of the most practical findings is the convergence speed. In CIFAR-100 tests, Instance-SCNS reached peak accuracy in nearly half the epochs required by uniform sampling (106 vs. 181 epochs).
Convergence plot comparing Test Accuracy over Training Epochs for SCNS variants versus standard InfoNCE (CRD).

Experimental Results

  • Supervised Learning: On CIFAR-10, SCNS and Latent Mixup increased test accuracy by an average of 1.52 percentage points across various ResNet architectures.
  • Knowledge Distillation (KD): This is where the method truly shines. When training a small "student" network to mimic a large "teacher" network, student performance increased by 4.56% on Tiny-ImageNet-200. It outperformed the classic Hinton et al. (2015) distillation baseline by 1.23% to 1.72%.
  • Robustness: The improvements were consistent across different network depths (ResNet-20 to ResNet-110) and types (Wide-ResNet, ResNeXt).

Limitations and Future Work

SCNS requires a pretrained network (either for word embeddings or image features) to define the initial similarity. While these are widely available, the quality of the "hard" negatives is capped by the quality of this prior model. The authors suggest that this approach could be extended to purely unsupervised settings where no class labels are available at all, potentially by iteratively updating the similarity matrix as the model learns.

Reference: O’ Neill, J., & Bollegala, D. (2021). Semantically-Conditioned Negative Samples for Efficient Contrastive Learning. arXiv:2102.06603v1 [cs.LG].

Summary updated

BibTeX
@misc{oneill2021semantically,
  author = {James O'Neill and Danushka Bollegala},
  title = {{Semantically-Conditioned Negative Samples for Efficient Contrastive Learning}},
  year = {2021},
  eprint = {2102.06603},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2102.06603},
}
Figure