ConSERT: A Contrastive Framework for Self-Supervised Sentence Representation Transfer

Yuanmeng Yan, Rumei Li, Sirui Wang, Fuzheng Zhang, Wei Wu, Weiran Xu

Abstract

Learning high-quality sentence representations benefits a wide range of natural language processing tasks. Though BERT-based pre-trained language models achieve high performance on many downstream tasks, the native derived sentence representations are proved to be collapsed and thus produce a poor performance on the semantic textual similarity (STS) tasks. In this paper, we present ConSERT, a Contrastive Framework for Self-Supervised Sentence Representation Transfer, that adopts contrastive learning to fine-tune BERT in an unsupervised and effective way. By making use of unlabeled texts, ConSERT solves the collapse issue of BERT-derived sentence representations and makes them more applicable for downstream tasks. Experiments on STS datasets demonstrate that ConSERT achieves an 8% relative improvement over the previous state-of-the-art, even comparable to the supervised SBERT-NLI. And when further incorporating NLI supervision, we achieve new state-of-the-art performance on STS tasks. Moreover, ConSERT obtains comparable results with only 1000 samples available, showing its robustness in data scarcity scenarios.

Introduction: Addressing the Representation Collapse

While BERT has revolutionized NLP, its "native" sentence embeddings—vectors produced by the [CLS] token or by averaging word embeddings—perform poorly on Semantic Textual Similarity (STS) tasks. This is due to a phenomenon known as representation collapse or anisotropy.

In BERT’s default state, sentence vectors are crowded into a narrow "cone" in the embedding space. Because high-frequency words dominate these vectors, even unrelated sentences often yield high cosine similarity scores (typically 0.6 to 1.0). This lack of discriminative power makes it difficult to distinguish subtle semantic differences without extensive supervised fine-tuning.

Comparison of predicted cosine similarity vs. gold similarity scores for native BERT (left) and ConSERT (right).

The ConSERT Framework

ConSERT addresses this by adopting a Contrastive Learning approach. The core objective is to take a sentence, create two slightly different "views" of it through data augmentation, and train the model to maximize the agreement between these views (positive pairs) while pushing views of different sentences (negative pairs) apart.

The ConSERT architecture, showing the pipeline from data augmentation to the contrastive loss layer.

The framework consists of three primary components:

  1. Data Augmentation Module: Since text is discrete, ConSERT applies augmentations at the embedding layer. Strategies include Adversarial Attacks (adding noise), Token Shuffling (reordering position IDs), Cutoff (zeroing out tokens or features), and Dropout.
  2. Shared BERT Encoder: A standard BERT model that processes the augmented views to produce sentence representations.
  3. Contrastive Loss Layer: The model uses the NT-Xent (Normalized Temperature-scaled Cross-Entropy) loss to optimize the embedding space.

Key Insights and Results

The Impact of Augmentation

Not all augmentations are equally effective. The authors found that Token Shuffling and Token Cutoff were particularly potent. These strategies force the model to focus on the semantic "bag of words" content rather than relying on specific token positions, which helps de-bias the space from high-frequency word dominance.

Performance and Data Efficiency

  • Unsupervised SOTA: ConSERT-large achieved an average Spearman correlation of 76.45 on STS tasks, an 8% relative improvement over previous methods like BERT-flow. It even outperformed several supervised models like InferSent.
  • Supervised Excellence: When combined with Natural Language Inference (NLI) supervision, ConSERT reached a new state-of-the-art score of 81.28.
  • Few-Shot Robustness: One of the most significant findings is ConSERT's efficiency. With only 1,000 unlabeled samples, the model achieves a 35% relative improvement over raw BERT, reaching performance levels comparable to models trained on much larger datasets.

Conclusion

ConSERT provides an effective, unsupervised solution to BERT's representation collapse. By leveraging contrastive learning and clever embedding-level augmentations, it reshapes the sentence representation space to be more isotropic and semantically meaningful. Its high performance in data-scarce scenarios makes it a practical tool for a wide variety of downstream NLP applications where labeled data is at a premium.

Summary updated

BibTeX
@inproceedings{yan2021consert,
  author = {Yuanmeng Yan and Rumei Li and Sirui Wang and Fuzheng Zhang and Wei Wu and Weiran Xu},
  title = {{ConSERT: A Contrastive Framework for Self-Supervised Sentence Representation Transfer}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.acl-long.393},
}
Figure