Clustering-Aware Negative Sampling for Unsupervised Sentence Representation

Jinghao Deng, Fanqi Wan, Tao Yang, Xiaojun Quan, Rui Wang

Introduction

In Natural Language Processing (NLP), the ability to map sentences into a continuous vector space where semantically similar sentences are close together is fundamental for tasks like information retrieval and semantic search. Contrastive learning has emerged as the leading paradigm for training these unsupervised sentence embeddings. However, standard contrastive methods often suffer from suboptimal negative sampling, which limits their ability to learn fine-grained semantic distinctions. This paper introduces ClusterNS (Clustering-aware Negative Sampling), a novel framework designed to enhance contrastive learning by leveraging real-time clustering to identify high-quality negative samples.

The Limitations of Standard Contrastive Learning

Most modern sentence embedding models, such as SimCSE, utilize a simple contrastive objective. For a given "anchor" sentence, the model creates a positive pair using data augmentation (e.g., different dropout masks) and treats all other sentences in the training batch as negatives. This approach faces two primary challenges:

  1. Easy Negatives: Most random sentences in a batch are semantically unrelated to the anchor. Pushing these "easy" negatives away provides a weak gradient signal, preventing the model from learning subtle differences.
  2. False Negatives: In large datasets, a random sentence in the batch may actually be semantically similar to the anchor. Treating these as negatives forces the model to push similar meanings apart, which degrades the quality of the representation space.

Methodology: The ClusterNS Framework

ClusterNS addresses these issues by introducing semantic awareness into the sampling process through three key components:

1. In-Batch Momentum Clustering

To maintain efficiency during training, ClusterNS performs clustering on the fly. Rather than recalculating clusters from scratch at every step, the authors employ momentum-based centroid updates. This allows the cluster centers to evolve smoothly as the model's embeddings improve, providing a stable and computationally efficient way to track the semantic distribution of the data.

2. Hard Negative Discovery

ClusterNS uses the identified clusters to find more informative negatives. For any anchor sentence, the model identifies its assigned cluster. Instead of sampling randomly, it selects negatives from the second nearest cluster centroid. The insight here is that the nearest cluster likely contains false negatives (sentences too similar to the anchor), while the second-nearest cluster provides the ideal "hard negatives"—sentences that are structurally or contextually similar enough to be challenging but semantically distinct.

3. Bidirectional Margin Loss (BML)

To handle potential false negatives—sentences that fall into the same cluster as the anchor—the authors introduce Bidirectional Margin Loss (BML). Rather than treating these sentences as standard negatives and pushing them far away, BML maintains them within a specific distance range. This "Goldilocks zone" prevents the model from collapsing these samples into the anchor while ensuring they are not treated as entirely unrelated, thereby preserving semantic nuances.

Experimental Results

The authors evaluated ClusterNS on the standard Semantic Textual Similarity (STS) tasks (STS 2012–2016, STS-B, and SICK-R) and several short-text clustering datasets.

Performance Benchmarks

ClusterNS achieved state-of-the-art results across multiple model backbones:

  • RoBERTa-base: Achieved an average Spearman’s correlation of 79.74 on STS tasks, significantly outperforming SimCSE (76.57) and PromptBERT (79.15).
  • Consistency: The performance gains were consistent across BERT-base and BERT-large architectures, demonstrating the robustness of the clustering-aware approach.

Ablation Studies

Ablation experiments confirmed that the cluster-based sampling strategy is the primary driver of performance. Removing the hard negative discovery component resulted in a significant performance drop (e.g., -1.52 on BERT-base), highlighting the importance of moving beyond random negative sampling.

Insights and Discussion

Beyond performance metrics, the paper demonstrates that clustering acts as an effective regularizer. It helps mitigate the "anisotropy" problem—a common issue in language models where embeddings occupy a narrow cone in the vector space—by improving the alignment and uniformity of the representations. By explicitly managing the relationship between similar and dissimilar clusters, the model develops a more balanced and discriminative embedding space.

Conclusion and Future Work

ClusterNS represents a significant step forward in unsupervised sentence representation by making negative sampling semantically informed. While the method introduces some computational overhead due to clustering and requires larger batch sizes for optimal cluster representation, the gains in embedding quality are substantial. Future research may focus on refining the clustering algorithms to be even more efficient and exploring ways to reduce the memory footprint for deployment on smaller hardware configurations.

Summary updated

BibTeX
@inproceedings{deng2023clustering,
  author = {Jinghao Deng and Fanqi Wan and Tao Yang and Xiaojun Quan and Rui Wang},
  title = {{Clustering-Aware Negative Sampling for Unsupervised Sentence Representation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.555},
}
Figure