# SimCSE: Simple Contrastive Learning of Sentence Embeddings

Contrastive learning with dropout noise produces strong sentence embeddings

Tianyu Gao, Xingcheng Yao, Danqi Chen · arXiv · 2021-4-18

- **Problem** Contrastive learning for sentence embeddings needs positive pairs, and text has no clean equivalent of the crops and flips used for images. Word-level edits change meaning, so the positives are noisy.
- **Method** SimCSE fine-tunes a BERT or RoBERTa encoder with a cross-entropy contrastive loss over cosine similarities. Unsupervised positives come from passing one sentence through the encoder twice under independent dropout masks, and supervised positives are NLI entailment pairs, with contradiction hypotheses added as hard negatives.
- **Results** Unsupervised SimCSE-BERTbase reaches 76.25 average Spearman's correlation on the STS tasks, above CT-BERTbase at 72.05.

## Why positive pairs are hard to get for sentences

Contrastive learning needs two inputs that should land close together, and for sentences the usual sources are labeled pairs or hand-written augmentations. In vision, two random transformations of one image serve as such a pair. Text does not transform this cleanly. Word deletion, reordering and substitution change the input in discrete steps, and each step can alter the meaning, so the positives are noisy.

Earlier sentence encoders often used a neighbouring sentence as the positive, as in the next-sentence objective that this paper later uses as a baseline. The study asks two questions: whether a contrastive objective can work when the only positive is the input sentence itself, and whether annotated NLI pairs can give a stronger training signal.

## Dropout as the source of positives

Unsupervised SimCSE sets the second view of a sentence equal to the sentence itself. The two views differ only because each forward pass samples its own dropout mask on the fully connected layers and attention probabilities of the Transformer. The method adds no dropout of its own: it reuses the default rate of 0.1 that the Transformer already applies.

For a mini-batch of N sentences, the loss for sentence i is a cross-entropy over cosine similarities scaled by the temperature, where the positive is the second dropout view of the same sentence and the negatives are the other sentences in the batch. \\\[ \\ell\_i = -\\log \\frac{e^{\\mathrm{sim}(h\_i^{z\_i}, h\_i^{z\_i'})/\\tau}}{\\sum\_{j=1}^{N} e^{\\mathrm{sim}(h\_i^{z\_i}, h\_j^{z\_j'})/\\tau}} \\\]

The encoder is a pre-trained BERT or RoBERTa, and the \[CLS\] vector serves as the sentence representation during training. The MLP layer on top of \[CLS\] is kept only during training, because test-time embeddings with the MLP scored lower in the authors' ablation.

## How dropout compares with other augmentations

On the STS-B development set with BERTbase, unsupervised SimCSE scores 82.5 Spearman's correlation. Cropping 10%, 20% and 30% of the sentence gives 77.8, 71.4 and 63.6. Word deletion at 10%, 20% and 30% gives 75.9, 72.2 and 68.2, deleting one word gives 75.9, synonym replacement gives 77.4, and MLM replacement of 15% of words gives 62.2.

Removing dropout entirely gives 74.2, so the dropout noise matters even inside the same design. The next-sentence objective reaches 67.1 with two encoders and 68.9 with one, while sampling one of the next three sentences gives 67.4 and 68.8. The self-prediction objective with one encoder reaches 82.5, and with two encoders it reaches 80.7.

## Alignment and uniformity as the evaluation lens

Alignment is the expected distance between the embeddings of positive pairs, taken over the positive distribution and assuming normalized representations. It is defined as follows. \\\[ \\ell\_{align} \\triangleq \\mathbb{E}\_{(x,x^+)\\sim p\_{pos}} \\\| f(x) - f(x^+) \\\|^2 \\\] Uniformity takes the logarithm of the average of a Gaussian-type potential over random pairs drawn from the data distribution, so that lower values mean the embeddings spread more evenly over the hypersphere.

## What happens when dropout is removed or shared

On the STS-B development set, the dropout probability varies from 0.0 to 0.5. The scores are 71.1 at 0.0, 72.6 at 0.01, 81.1 at 0.05, 82.5 at 0.1, 81.4 at 0.15, 80.5 at 0.2 and 71.0 at 0.5. Using the default rate 0.1 but the same mask for both views drops the score to 43.6, so the two views must differ in their masks.

Tracking alignment and uniformity every 10 training steps, every variant improves uniformity from its pre-trained starting point. The no-dropout and fixed-mask variants, however, lose alignment sharply, while unsupervised SimCSE keeps alignment steady. Deleting one word improves alignment, but its gain in uniformity is smaller, and it finishes below unsupervised SimCSE.

The authors attribute the importance of the pre-trained start to the good initial alignment it provides.

## Choosing supervised positive pairs

Supervised SimCSE takes premise and entailment-hypothesis pairs from SNLI and MNLI as positive instances, in place of a three-way classification head. The study compares this choice with QQP, Flickr30k, ParaNMT and the neutral and contradiction pairs. On the STS-B development set with BERTbase, the entailment pairs from SNLI and MNLI reach 84.1 with a 134k-pair subsample and 84.9 with the full 314k pairs.

Neutral pairs reach 82.6 and 82.9, contradiction pairs 77.5 and 77.6, and all NLI pairs together 81.7 and 81.9. QQP reaches 81.8 with both sampling choices, Flickr30k 81.5 and 81.4, and ParaNMT 79.7 and 78.7.

The authors suggest that NLI pairs work better because they are crowd-sourced and show less lexical overlap. The F1 overlap between bags of words is 39% for the entailment pairs, against 60% for QQP and 55% for ParaNMT.

## Contradictions as hard negatives

For each premise, the objective keeps its entailment hypothesis as the positive and adds the paired contradiction hypothesis as a hard negative. The contradiction terms join the denominator alongside the in-batch terms. \\\[ \\ell\_i = -\\log \\frac{e^{\\mathrm{sim}(h\_i,h\_i^+)/\\tau}}{\\sum\_{j=1}^{N}\\left(e^{\\mathrm{sim}(h\_i,h\_j^+)/\\tau}+e^{\\mathrm{sim}(h\_i,h\_j^-)/\\tau}\\right)} \\\]

On the STS-B development set, adding the hard negatives raises the score from 84.9 to 86.2. Weighting the hard negatives by a factor alpha gives 86.1 at 0.5, 86.2 at 1.0 and 86.2 at 2.0, while also treating neutral hypotheses as hard negatives gives 85.3. The authors keep alpha at 1.0 in the final model. A dual-encoder version of supervised SimCSE lowers the score from 86.2 to 84.2, and adding ANLI brought no meaningful gain in the authors' tests.

## Why contrastive learning flattens the spectrum

Pre-trained embeddings occupy a narrow cone, which is the anisotropy problem. Singular values of the word embedding matrix also decay quickly, with only a few dominating. With normalized embeddings and infinitely many negatives, the asymptotic form of the contrastive objective has a positive-pair term and a negative-pair term, and the authors study the negative term.

When the data distribution is uniform over a finite sample, Jensen's inequality bounds the negative term from below by a scaled sum of all inner products between sentence embeddings. \\\[ \\frac{1}{m}\\sum\_{i=1}^{m}\\log\\frac{1}{m}\\sum\_{j=1}^{m}e^{h\_i^\\top h\_j/\\tau} \\ge \\frac{1}{\\tau m^2}\\sum\_{i=1}^{m}\\sum\_{j=1}^{m} h\_i^\\top h\_j \\\]

Writing W for the matrix whose rows are the normalized embeddings, the sum of all entries of WW^T is an upper bound on its largest eigenvalue when all entries are positive. The authors state that this positivity holds in most cases, citing their figure of the Gram matrix. Minimizing the negative term therefore reduces the top eigenvalue, which the authors read as flattening the singular spectrum.

Unlike post-processing methods that only push toward isotropy, the positive term also keeps positive pairs aligned.

Figure F.1 plots normalized singular values of the sentence embedding matrix from STS-B. Vanilla BERT and SBERT drop fastest, SimCSE flattens the curve, and the post-processing methods flatten it further.

## Results on the STS tasks

Under the all setting with Spearman's correlation, unsupervised SimCSE-BERTbase averages 76.25 over the STS tasks, above CT-BERTbase at 72.05. Unsupervised SimCSE-RoBERTabase averages 76.57 and SimCSE-RoBERTalarge 78.90, from the same table.

With NLI supervision, SimCSE-BERTbase averages 81.57, above SBERTbase at 74.89, and SimCSE-RoBERTalarge reaches 83.76. The authors choose the all setting, which pools all topics of a year's STS challenge, together with no extra regressor and Spearman's correlation, and they reproduced some baselines under other settings.

## Transfer tasks and the MLM variant

The transfer evaluation trains a logistic regression on top of frozen sentence embeddings. Unsupervised SimCSE-BERTbase averages 85.81 accuracy, close to IS-BERTbase at 85.83. Adding the MLM objective with lambda 0.1 lifts the unsupervised BERTbase average to 86.64 and the supervised BERTbase average to 86.86.

Post-processing with BERT-flow or BERT-whitening lowers transfer performance compared with the base models, and the authors read this as good uniformity not translating into transfer gains.

## Limits of the evidence

Evaluation protocols differ across the papers compared, and the authors list the regressor, correlation metric and aggregation choice for each. Their own table reports baselines under several settings.

Most ablations and comparisons, including pooling, temperature and hard-negative weighting, were run on the STS-B development set. The spectrum argument rests on an analytic bound and on a figure of singular values, and the paper does not test whether the flattening alone explains the STS gains.

## Paper info

- **Authors**: Tianyu Gao, Xingcheng Yao, Danqi Chen
- **Venue**: arXiv · Preprint
- **First published**: 2021-4-18
- **Added**: 2026-11-12
- **Updated**: 2022-5-18
- **Version**: v4
- **arXiv**: 2104.08821
- **Category**: cs.CL · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2104.08821v4) · [PDF ↗](https://arxiv.org/pdf/2104.08821v4)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Tianyu Gao, Xingcheng Yao, Danqi Chen (2021). SimCSE: Simple Contrastive Learning of Sentence Embeddings. arXiv:2104.08821v4. https://arxiv.org/abs/2104.08821v4

**BibTeX**

```
@misc{gao2021simcse,
  title = {{SimCSE: Simple Contrastive Learning of Sentence Embeddings}},
  author = {Tianyu Gao and Xingcheng Yao and Danqi Chen},
  year = {2021},
  eprint = {2104.08821},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.08821v4}
}
```

## Other paper commentary

- [Supervised Contrastive Learning](https://refivu.com/en/papers/a5818cfe-00fa-4e85-a38e-cdce6aa6cad5-supervised-contrastive-learning.md)
- [iCaRL: Incremental Classifier and Representation Learning](https://refivu.com/en/papers/1de3af5b-26d7-4577-82d5-dabe37a7e63a-icarl-incremental-classifier-and-representation-learning.md)
- [Exploring Simple Siamese Representation Learning](https://refivu.com/en/papers/d32975a6-8149-4095-86b6-ad11d1642a75-exploring-simple-siamese-representation-learning.md)
- [Unsupervised Cross-lingual Representation Learning at Scale](https://refivu.com/en/papers/6b2842f9-6ee4-433e-84ed-ae8dc85bdb0a-unsupervised-cross-lingual-representation-learning-at-scale.md)
- [DeepWalk: Online Learning of Social Representations](https://refivu.com/en/papers/dd05ed66-43b8-4f25-93ca-264ea076a439-deepwalk-online-learning-of-social-representations.md)
- [Representation Learning: A Review and New Perspectives](https://refivu.com/en/papers/b38149f8-9f53-4406-8d25-bb93c21c4bc9-representation-learning-a-review-and-new-perspectives.md)
- [CornerNet: Detecting Objects as Paired Keypoints](https://refivu.com/en/papers/f70d57a2-b48d-4fc2-baa1-2e7e2057bad5-cornernet-detecting-objects-as-paired-keypoints.md)
- [An Overview of Multi-Task Learning in Deep Neural Networks](https://refivu.com/en/papers/ec3f88d3-e942-4848-9ca0-597d43563c84-an-overview-of-multi-task-learning-in-deep.md)
- [Datasheets for Datasets](https://refivu.com/en/papers/aac36b7e-c8f1-4fe7-a9fb-2e09532542d6-datasheets-for-datasets.md)
- [Deep CORAL: Correlation Alignment for Deep Domain Adaptation](https://refivu.com/en/papers/0a5f5341-f013-4a47-b5c4-af4c12f6a0aa-deep-coral-correlation-alignment-for-deep-domain-adaptation.md)
- [Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics](https://refivu.com/en/papers/7546f3a0-585b-406e-b199-f4b06c78a42f-multi-task-learning-using-uncertainty-to-weigh-losses.md)
- [Universal and Transferable Adversarial Attacks on Aligned Language Models](https://refivu.com/en/papers/6bc6f22f-cd10-41c0-ba7c-3e3d376cf3b9-universal-and-transferable-adversarial-attacks-on-aligned.md)

## Terms in this paper

- [dropout](https://refivu.com/en/terms/db73f75bbdd3-dropout)
- [BERT](https://refivu.com/en/terms/45b639a1d317-bert)
- [Data Augmentation](https://refivu.com/en/terms/cc5618231f4a-data-augmentation)
- [cosine similarity](https://refivu.com/en/terms/3baa01a8760d-cosine-similarity)
- [ROBERTA](https://refivu.com/en/terms/f42b278690e5-roberta)
- [contrastive learning](https://refivu.com/en/terms/180d2c06550d-contrastive-learning)
- [in-batch negatives](https://refivu.com/en/terms/a4ee4e02506f-in-batch-negatives)
- [temperature](https://refivu.com/en/terms/13dee949c770-temperature)
- [masked language modeling (MLM)](https://refivu.com/en/terms/b69aff1c3ded-masked-language-modeling-mlm)
- [alignment](https://refivu.com/en/terms/03481008b426-alignment)
- [sBERT](https://refivu.com/en/terms/d551156f28b2-sbert)
- [hard negatives](https://refivu.com/en/terms/17c156ae3902-hard-negatives)
- [SimCSE](https://refivu.com/en/terms/6ab4fc4a98e8-simcse)
- [STS-B](https://refivu.com/en/terms/bf29129d07ec-sts-b)
- [transfer tasks](https://refivu.com/en/terms/37218d94f9a1-transfer-tasks)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/be6ac7d7-6b80-4ef3-905e-9b7eecc4765c-simcse-simple-contrastive-learning-of-sentence-embeddings)
