Self-supervised Sentence Embeddings

Machine Learning
Introduced by
Gao, T., Yao, X., & Chen, D. (SimCSE); Reimers, N. & Gurevych, I. (Sentence-BERT)
Year
2019–2021
Type
Self-supervised representation learning
Family
Deep learning / NLP / CV

What does it do?

Self-supervised sentence embeddings train a neural encoder to map sentences into a dense vector space without manually labeled pairs.

Positive examples are constructed automatically, for example by passing the same sentence through the encoder twice with different dropout masks, and a contrastive objective pulls these views together while separating them from other sentences. The resulting representations are used for similarity, retrieval, and classification.

The intuition behind the method

The core idea is that a sentence encoded twice through the same transformer with different dropout masks should yield two representations that are closer to each other than to the representations of other sentences in the batch. Maximizing agreement between these two views while pushing apart unrelated sentences trains the encoder to place similar texts near each other, without a person annotating any pairs. In the SimCSE work, the unsupervised variant performs on par with earlier supervised counterparts on semantic textual similarity benchmarks.

History

Sentence-BERT (Reimers and Gurevych, 2019) adapted BERT into a siamese network to produce sentence embeddings. SimCSE (Gao, Yao and Chen, 2021) showed that a contrastive objective with only standard dropout as noise can learn sentence embeddings without labels, performing on par with supervised counterparts on STS tasks. Its supervised variant adds NLI pairs to the same framework.

When to use it

Choose self-supervised sentence embeddings when you need general-purpose sentence representations, you have a substantial unlabeled text corpus, and labeled sentence pairs are scarce or costly to produce. They suit semantic search, clustering, paraphrase detection, and nearest-neighbour classification. Because the contrastive loss relies on in-batch negatives, the method needs a batch size large enough to supply them; if the available hardware or data cannot support this, the method is a poor fit. Avoid it when the downstream task needs fine-grained, structured, or factual outputs that similarity alone does not capture. When labeled entailment or contradiction pairs exist, the supervised SimCSE variant is the cited route to stronger embeddings.

Limitations and considerations

  • Embedding quality is bounded by the pretrained backbone; a weak base model yields weak sentence representations.
  • The loss uses other sentences in the batch as negatives, so small batches reduce the number of negatives and weaken the training signal.
  • In the cited SimCSE framework, dropout is the noise source. The abstract reports that removing dropout leads to representation collapse, so training in that framework relies on dropout as its augmentation.
  • Embeddings capture semantic similarity but may not encode task-specific distinctions such as negation or sentiment polarity.
  • Quality is usually judged with benchmark datasets such as STS, since the training loss does not directly measure downstream usefulness.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The positive pairs come from two dropout views of the same sentence, so no human-labeled sentence pairs are required.
  • Dropout augmentation needs no external augmentation pipeline, which keeps the training setup simple.
  • In the SimCSE abstract, the unsupervised model with BERT-base performs on par with earlier supervised counterparts on semantic textual similarity benchmarks.
  • The approach is applied to standard transformer backbones such as BERT and RoBERTa, and the same framework can take labeled entailment and contradiction pairs when they are available.

Applications

  • Semantic search and dense passage retrieval in information retrieval systems.
  • Clustering of large document or sentence collections without labeled categories.
  • Paraphrase detection and duplicate question identification.
  • Zero-shot and few-shot text classification using nearest-neighbour lookup in embedding space.
  • Recommendation systems that match user queries to item descriptions by semantic similarity.

How it works

How it works

1

A large pretrained transformer (for example BERT or RoBERTa) is selected as the backbone encoder. The self-supervised objective replaces manually labeled sentence pairs with a signal derived from the text itself, so unlabeled corpora can be used directly as training data.

2

For each training sentence, two views are created automatically. In the SimCSE framework this is dropout alone: the same sentence is passed through the encoder twice with independent dropout masks, producing two slightly different representations. Other augmentations such as token deletion, word shuffling, or back-translation exist in the wider literature but are not the basis of the cited SimCSE approach.

3

Both views of each sentence in a mini-batch are encoded independently by the shared transformer to produce fixed-dimensional embedding vectors, typically taken from the [CLS] token or obtained by mean pooling over token representations.

4

A contrastive loss (for example NT-Xent or InfoNCE) is minimized. Here sim(u, v) is the similarity function between two embedding vectors; in this formula it is cosine similarity, the standard choice for this method. For sentence i, the numerator uses its positive h_i^+ (the second view of the same sentence), and the denominator sums over all N sentences in the batch, including that positive; the other sentences act as negatives. The temperature tau is a hyperparameter that scales the similarities before the softmax and controls how sharply the loss separates positives from negatives. The per-sentence losses are averaged over the batch to give the training loss.

Formula
\mathcal{L} = -\log \frac{e^{\text{sim}(h_i, h_i^+)/\tau}}{\sum_{j=1}^{N} e^{\text{sim}(h_i, h_j^+)/\tau}}
5

After training, the encoder projects any sentence into a fixed-length vector. These embeddings can be indexed for semantic search, compared with cosine similarity for paraphrase detection, or used as features for downstream classifiers without further fine-tuning.

Common pitfalls

  • Using too small a batch size. In-batch negatives are the main learning signal, so small batches starve the contrastive objective.
  • Removing dropout in SimCSE-style training to reduce noise. The SimCSE abstract reports that removing dropout led to representation collapse, so dropout should be kept in that setup.
  • Comparing embeddings with a similarity measure different from the one the training objective uses. The loss is defined through a similarity function and temperature tau, and evaluation should use a consistent measure.
  • Applying general-domain embeddings to specialized text such as medical, legal, or scientific documents without domain-adaptive continued pretraining.
  • Skipping evaluation on a semantic textual similarity benchmark and assuming the training loss reflects embedding quality.
  • Ignoring labeled pairs when they exist. SimCSE's supervised variant uses entailment pairs as positives and contradiction pairs as hard negatives, and it is the cited route to higher scores.

Frequently asked questions

How does self-supervised differ from supervised sentence embedding?

Supervised methods use labeled sentence pairs to shape the training objective, and this generally helps when high-quality labels exist. For example, the supervised SimCSE variant adds NLI entailment pairs as positives and contradiction pairs as hard negatives. Self-supervised methods replace labels with automatic augmentation, so they can be used when annotations are unavailable, but they may underperform on fine-grained similarity tasks compared with supervised training.

What batch size should I use?

Larger batches are generally better. The contrastive loss relies on in-batch negatives, so the number of negatives available at each step grows with the batch size, subject to available GPU memory. The batch size used in the original training setup should be checked against the source paper before choosing a value for your own training run.

Can I add labeled data on top of the self-supervised objective?

Yes. The SimCSE supervised variant incorporates NLI entailment pairs as positives and contradiction pairs as hard negatives in the same contrastive framework. Its abstract reports an average Spearman correlation on STS of 81.6% with BERT-base, compared with 76.3% for the unsupervised variant.

How do I evaluate the quality of my sentence embeddings?

The standard benchmark is the STS (Semantic Textual Similarity) suite. Spearman correlation between cosine similarity scores and human judgments on STS-B or STS12–16 is the most widely reported metric. For retrieval applications, BEIR benchmarks provide a broader evaluation across diverse tasks.

Which pretrained model should I use as the backbone?

BERT-base and RoBERTa-base are standard starting points. For domain-specific text, a backbone pretrained or continued-pretrained on in-domain text (for example BioBERT for biomedical text or SciBERT for scientific text) often produces better embeddings than a general-domain backbone.

Related methods

Sources

  1. Gao, T., Yao, X., & Chen, D. (2021). SimCSE: Simple Contrastive Learning of Sentence Embeddings. Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing (EMNLP), 6894–6910.

    Open DOI reference
  2. Reimers, N., & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 3982–3992.

    Open DOI reference