Semi-supervised Sentence Embeddings

Machine Learning
Introduced by
Gao, T.; Reimers, N. et al. (multiple contributors)
Year
2019–2021
Type
Semi-supervised representation learning
Family
Deep learning / NLP / CV

What does it do?

Semi-supervised sentence embeddings train dense vector representations of sentences by combining a small set of labeled sentence pairs with a large amount of unlabeled text.

The unlabeled text is typically used through a contrastive objective or through pseudo-labelling, while the labeled pairs shape the embedding space toward a task-relevant notion of similarity. The resulting embeddings are used for semantic similarity, retrieval, clustering, and classification, and the approach is most useful when annotated sentence pairs are scarce.

The intuition behind the method

Fully supervised sentence embedding requires manually annotated sentence pairs, which are expensive to produce. Semi-supervised methods reduce this dependence by training the encoder with two signals: a self-supervised signal from unlabeled text, such as treating two dropout-perturbed encodings of the same sentence as a positive pair, and a supervised signal from whatever labeled examples are available. The unlabeled signal encourages a general, well-spread geometry of sentence representations, and the labeled examples move that space toward the similarity judgments the downstream task needs. The expected benefit is a sentence encoder that depends less on the size of the labeled set than a model trained only on those labels.

History

Sentence-BERT (Reimers & Gurevych, 2019) introduced siamese BERT networks for producing sentence embeddings that are compared with similarity measures. SimCSE (Gao, Yao & Chen, 2021) showed that its unsupervised variant, which uses only dropout as noise, performs on par with earlier supervised counterparts on STS tasks, and that its supervised variant uses NLI entailment pairs as positives and contradiction pairs as hard negatives. The semi-supervised combination of unlabeled contrastive training with labeled fine-tuning described on this page builds on these two lines of work, while the pseudo-labelling stage is a general self-training technique.

When to use it

Choose semi-supervised sentence embeddings when a large unlabeled text collection is available but only a small set of labeled sentence pairs exists, and the goal is semantic similarity, retrieval, clustering, or classification. The approach is especially relevant for domain-specific encoders, such as legal, biomedical, or scientific text, where in-domain unlabeled text is plentiful but annotation is costly. Do not use it when the labeled set is already large enough for direct supervised fine-tuning to perform well, because the unlabeled stage then adds cost without a clear benefit. It is also a poor fit when sentences are very short or lack enough semantic content for pair similarity to be meaningful, or when available compute cannot support contrastive training with reasonably large batches.

Limitations and considerations

  • Contrastive objectives rely on in-batch negatives, so embedding quality depends on batch size; smaller batches provide fewer negatives and weaker separation.
  • The unsupervised signal uses dropout as its only augmentation, and the SimCSE paper reports that removing dropout leads to representation collapse. This result is reported for BERT-base, and the cited source does not establish it for other encoders, so the method should be assumed to depend on encoders that use dropout.
  • Pseudo-label quality depends on the confidence threshold, and noisy pseudo-labels can degrade the supervised fine-tuning stage.
  • Gains over unsupervised baselines may be small when the labeled set is very small or noisy, so the semi-supervised benefit is not guaranteed.
  • Encoding large batches of sentences in parallel requires substantial GPU memory, which constrains the batch sizes that are practical.

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

Strengths

  • Reduces the dependence on labeled sentence pairs by using unlabeled in-domain text in the contrastive stage.
  • The unsupervised SimCSE-style stage needs no labels and only standard dropout as augmentation; the SimCSE paper reports that this setup performs on par with earlier supervised counterparts on STS tasks, with results reported for BERT-base.
  • According to the SimCSE analysis, contrastive training makes the pre-trained embedding space more uniform, and adding supervised pairs improves the alignment of positive pairs. These results are reported for BERT-base on standard STS benchmarks; transfer to other encoders, languages, or specialised domains is not established by the cited source.
  • Starting from a pre-trained transformer means less labeled data is needed to reach competitive results than training an encoder from scratch.
  • Pseudo-labelling can enlarge the labeled training set without new annotation, provided the selection criterion is strict.

Applications

  • Semantic textual similarity scoring in question-answering and duplicate detection systems.
  • Dense passage retrieval for open-domain question answering and document search.
  • Sentence-level clustering of social media posts, customer feedback, or scientific abstracts.
  • Low-resource text classification via embedding-based nearest-neighbor or few-shot classifiers.
  • Domain-specific knowledge base construction in legal, biomedical, and scientific NLP.
  • Exploratory cross-lingual sentence alignment with multilingual encoders, which requires separate validation because cross-lingual performance is not evaluated in the cited sources.

How it works

How it works

1

A pre-trained transformer such as BERT or RoBERTa is used as the sentence encoder backbone. Its weights already encode lexical and syntactic regularities, so the semi-supervised training starts from a stronger point than a randomly initialised encoder and needs less labeled data to reach competitive performance.

2

A self-supervised contrastive objective is applied to unlabeled sentences. In the unsupervised SimCSE variant, each sentence is encoded twice with different dropout masks, and the two encodings form a positive pair; the other sentences in the batch serve as negatives. The InfoNCE-style loss pulls each positive pair together and pushes the in-batch negatives away. In the formula, the sum over j runs over the N sentences of the current mini-batch, not over the whole dataset; h_i and h_i^+ are the two dropout-masked encodings of sentence i, and τ is a temperature hyperparameter. No labels are used at this step, and dropout is the only source of augmentation.

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

The encoder trained so far is used to score unlabeled sentence pairs, and pairs that pass a confidence threshold receive pseudo-labels (for example, high or low similarity). The selection rule should be stated explicitly: accept a pair only when its predicted similarity exceeds an upper threshold or falls below a lower threshold, and choose both thresholds on held-out validation pairs rather than fixing them in advance. This is a general self-training step rather than part of the SimCSE paper. The pseudo-labelled pairs are added to the labeled set, which can enlarge the supervised training data without new human annotation.

4

The labeled sentence pairs, together with any accepted pseudo-labelled pairs, are used to fine-tune the encoder with a supervised contrastive or regression objective. In the supervised SimCSE variant, NLI entailment pairs serve as positives and contradiction pairs as hard negatives, so the supervised objective keeps the contrastive form of the unsupervised stage while adding human-defined similarity to the same embedding space. This step aligns the embedding space with the similarity notion encoded in the labels.

5

The final encoder is evaluated on held-out semantic textual similarity benchmarks such as STS-B or SICK-R, using Spearman correlation, and on the downstream tasks of interest, such as retrieval, clustering, or classification. Embeddings are extracted as the mean-pooled or CLS-token representation of each sentence, and the pooling choice should match the one used during training so that the evaluated embeddings are the ones the model was optimised for.

Common pitfalls

  • Using a batch size that is too small for contrastive training, which reduces the number of negatives and can yield poorly separated embeddings.
  • Setting the pseudo-label selection threshold too low, which admits low-confidence pairs and pushes the fine-tuning towards incorrect similarity judgments.
  • Treating the dropout-only unsupervised stage as the complete semi-supervised pipeline; that stage uses no labels, so the labeled fine-tuning step is what injects human-defined similarity.
  • Evaluating only on STS-B without checking downstream retrieval or classification performance, since STS scores do not always predict task accuracy.
  • Skipping domain-adaptive pre-training before semi-supervised fine-tuning when the target text is specialised, so the backbone's lexical knowledge may not match the domain.

Frequently asked questions

How much labeled data is needed to benefit from semi-supervised sentence embeddings?

The amount depends on the task, the domain, and the quality of the labels, and no general threshold is established here. The benefit is expected to be largest when labels are scarce and the unlabeled pool is large and close to the target domain. Compare the semi-supervised model against a purely supervised baseline on a held-out validation set before relying on it.

What is the minimum batch size for contrastive training?

Contrastive objectives draw their negatives from the other sentences in the batch, so smaller batches give each anchor fewer negatives and weaker separation. There is no universal minimum; check the batch sizes reported in the original SimCSE publication and choose the largest batch your GPU memory allows.

Should I use dropout augmentation or explicit data augmentation for the unsupervised signal?

The SimCSE paper shows that standard dropout, applied twice to the same sentence, is a simple and effective augmentation, and that removing dropout leads to representation collapse. More elaborate augmentations such as back-translation or word deletion can be tried, but they also add noise, so dropout is usually the safest default.

How do I evaluate embedding quality before using them downstream?

Compute Spearman correlation with human similarity judgments on STS-B or SICK-R as a proxy. However, also validate on your actual downstream task (retrieval recall@K, classification accuracy) because STS scores do not always predict task performance.

Can I use this approach with non-English text?

Multilingual backbones such as mBERT or XLM-RoBERTa can be used with the same pipeline, provided you have sufficient unlabeled in-language text. Cross-lingual performance is not evaluated in the cited sources, so validate the embeddings on your own language pairs before relying on them.

Related methods

Sources

  1. Gao, T., Yao, X., & Chen, D. (2021). SimCSE: Simple Contrastive Learning of Sentence Embeddings. In Proceedings of EMNLP 2021 (pp. 6894–6910). Association for Computational Linguistics.

    Open DOI reference
  2. Reimers, N., & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. In Proceedings of EMNLP-IJCNLP 2019 (pp. 3982–3992). Association for Computational Linguistics.

    Open DOI reference