Self-Guided Contrastive Learning for BERT Sentence Representations

Taeuk Kim, Kang Min Yoo, Sang-goo Lee

Introduction

Pre-trained Transformers like BERT have revolutionized natural language processing, yet they struggle to produce high-quality sentence-level embeddings out of the box. Naive extraction of the [CLS] token or mean pooling of word vectors often yields representations that perform worse than simple GloVe vectors on Semantic Textual Similarity (STS) tasks. This failure is largely attributed to "anisotropy"—a phenomenon where sentence embeddings are confined to a narrow cone in the vector space, leading to high cosine similarity even between unrelated sentences.

Existing remedies typically involve supervised fine-tuning on large labeled datasets (e.g., SBERT) or unsupervised post-processing techniques like BERT-flow and BERT-whitening. However, these methods either require expensive human annotations or rely on complex data augmentation strategies like back-translation. This paper introduces a "self-guided" contrastive learning framework that transforms BERT into a high-quality sentence encoder without requiring labeled data or external data augmentation.

Methodology: Self-Guided Contrastive Learning

The core innovation is to leverage the model's own internal knowledge to refine sentence representations. Instead of creating "positive pairs" by augmenting input text (e.g., cropping or translating), the authors create positive pairs from the internal representations of the model itself.

The Self-Guided Contrastive Learning framework uses internal representations from a fixed BERT model as positive views for training a tuned BERT model.

The framework employs a dual-model architecture: a fixed model ($BERT_F$) and a tuned model ($BERT_T$). For any given sentence $s_i$, it is passed through $BERT_F$ to extract hidden states ($h_{i,l}$) from various intermediate layers. These internal states serve as multiple "views" of the same sentence. The training objective is to optimize $BERT_T$ such that its final-layer representation ($c_i$) is pulled closer to these internal views while being pushed away from the representations of other sentences in the mini-batch.

This approach, termed SG-OPT, utilizes an optimized contrastive loss that focuses on aligning the tuned representation against a diverse set of fixed internal anchors. By "recycling" the rich linguistic information already present in BERT's intermediate layers, the model learns a more holistic and isotropic sentence space.

Experimental Results

The proposed method was evaluated across standard STS benchmarks and compared against various baselines, including non-BERT models, vanilla BERT, and other unsupervised contrastive methods.

Performance comparison of BERT-based models on STS tasks. SG-OPT consistently outperforms previous unsupervised methods like BERT-flow and contrastive learning with back-translation (BT).

As shown in the results table, the optimized self-guided method (SG-OPT) achieves state-of-the-art performance for unsupervised models. On the STS-B benchmark, BERT-base with SG-OPT reached a Spearman correlation of 77.23, a significant improvement over BERT-flow (71.35) and back-translation-based contrastive learning (63.27). Similar gains were observed across the BERT-large and SBERT architectures, demonstrating the method's broad applicability.

Key Advantages

Beyond raw accuracy, the self-guided approach offers several practical benefits:

  • Superior Efficiency: Unlike flow-based methods or complex pooling strategies, SG-OPT results in a standard refined BERT model. At inference time, one simply extracts the [CLS] token. This makes it approximately 3x faster than BERT-flow and 19x faster than WK-pooling.
  • Domain Robustness: When trained on NLI data and evaluated on STS tasks (a domain shift), SG-OPT demonstrated superior stability compared to BERT-flow, suggesting that the features learned through self-guidance are more generalizable.
  • Multilingual Success: The method successfully boosted Multilingual BERT's (MBERT) performance on Spanish and Arabic tasks, even when trained only on English raw text.

Conclusion

Self-guided contrastive learning provides a powerful, efficient, and unsupervised way to transform BERT into a high-quality sentence encoder. By utilizing internal layer representations as positive samples, the method addresses the anisotropy problem and outperforms more complex augmentation-based techniques. Future work may explore hybrid approaches that combine internal self-guidance with external data augmentation to further push the boundaries of sentence representation learning.

Summary updated

BibTeX
@inproceedings{kim2021self,
  author = {Taeuk Kim and Kang Min Yoo and Sang-goo Lee},
  title = {{Self-Guided Contrastive Learning for BERT Sentence Representations}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.acl-long.197},
}
Figure