Instance Smoothed Contrastive Learning for Unsupervised Sentence Embedding

Hongliang He, Junlei Zhang, Zhenzhong Lan, Yue Zhang

Introduction

Generating high-quality sentence embeddings without labeled data is a cornerstone of modern natural language processing. Recent breakthroughs, most notably SimCSE, have utilized contrastive learning to pull different views of the same sentence (created via dropout) together while pushing different sentences apart. However, this "instance-level" approach treats every sentence as a unique, isolated class—a paradigm that ignores the inherent semantic overlap in natural language. This paper introduces Instance Smoothed Contrastive Learning (IS-CSE), a method that moves beyond the "one sentence, one class" mindset by incorporating semantically similar neighbors into the learning objective.

The Limitations of Instance-Level Contrastive Learning

Standard unsupervised contrastive learning frameworks typically rely on a binary distinction: a sentence is either a positive match (itself under a different dropout mask) or a negative match (any other sentence in the batch). The authors identify two primary issues with this rigid classification:

  1. Over-confidence: The model becomes excessively certain that a sentence is only similar to itself, leading to poor generalization when encountering subtle semantic variations.
  2. False Negatives: In large-scale datasets, a training batch often contains different sentences that share nearly identical meanings. Standard contrastive learning incorrectly penalizes the model for placing these semantically equivalent sentences close together in the embedding space.

Proposed Method: IS-CSE

To address these issues, IS-CSE introduces a smoothing layer that transforms the contrastive target from a single point into a semantic neighborhood. The architecture consists of several key innovations:

Dynamic Memory Buffer

Finding semantic neighbors across a massive dataset is computationally expensive. To mitigate this, the authors maintain a First-In-First-Out (FIFO) memory buffer. This buffer stores embeddings from previous training iterations, providing a large pool of candidates for neighborhood retrieval without the need to re-encode the entire dataset at every step.

kNN Retrieval and Self-Attention Aggregation

For each input sentence, the model performs a k-Nearest Neighbors (kNN) search within the memory buffer. Instead of treating all neighbors equally, IS-CSE employs a self-attention mechanism to weight these neighbors based on their relevance to the anchor sentence. This aggregation creates a "smoothed instance embedding" that represents a broader semantic region rather than a discrete point.

Dual Loss Objective and Scheduling

The model is trained using a composite loss function:

  • Instance-level Loss: The standard SimCSE loss that maintains basic discriminative power.
  • Smoothing Loss: A new objective that encourages the anchor sentence to align with its smoothed neighborhood.

To ensure stability, the authors use a cosine scheduler for the smoothing weight ($\alpha$). This allows the model to focus on basic instance discrimination in early training stages when embeddings are noisy, gradually increasing the influence of the neighborhood smoothing as the representation space matures.

Experimental Results

IS-CSE was evaluated on standard Semantic Textual Similarity (STS) benchmarks and several transfer learning tasks. The model was trained on 1 million randomly sampled sentences from English Wikipedia.

Performance Benchmarks

The results demonstrate that IS-CSE consistently outperforms the SimCSE baseline across various architectures:

  • BERT-base: Achieved an average Spearman’s correlation of 78.30%, representing a 2.05% improvement over the unsupervised SimCSE baseline.
  • RoBERTa-large: Reached 79.42%, surpassing other competitive unsupervised methods like DCLR.

Alignment and Uniformity

In the context of representation learning, "alignment" refers to how close similar items are, while "uniformity" refers to how well embeddings are distributed across the feature space. The authors found that IS-CSE significantly improves alignment. While it can lead to a slight decrease in uniformity compared to SimCSE, the substantial gains in semantic alignment result in superior overall performance on downstream tasks.

Discussion and Insights

The success of IS-CSE suggests that "label smoothing"—a common technique in supervised learning—is equally valuable in the unsupervised domain. By acknowledging that language similarity is a spectrum rather than a binary state, IS-CSE creates a more robust feature space. Furthermore, the authors noted that direct kNN retrieval outperformed K-means clustering, suggesting that local, instance-specific context is more beneficial for smoothing than global cluster assignments.

Conclusion and Future Work

Instance Smoothed Contrastive Learning provides a simple yet effective refinement to the contrastive learning pipeline. By leveraging a dynamic memory buffer and self-attention, it effectively mitigates the issues of over-confidence and false negatives. Future research may explore "negative smoothing"—refining how the model treats dissimilar examples—and the application of these smoothed embeddings to generative NLP tasks such as dialogue systems and summarization.

Summary updated

BibTeX
@inproceedings{he2023instance,
  author = {Hongliang He and Junlei Zhang and Zhenzhong Lan and Yue Zhang},
  title = {{Instance Smoothed Contrastive Learning for Unsupervised Sentence Embedding}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i11.26512},
}
Figure