TL;DR
SimCSE is a simple way to train a language model so that each sentence gets one vector that captures its meaning. The unsupervised version passes the same sentence through the model twice, with different random dropout masks, and asks the two outputs to match more than they match other sentences in the batch. The supervised version uses entailment pairs from natural language inference data as the matching pairs and contradiction pairs as extra negatives. With BERT-base, the paper reports average Spearman correlation of 76.3% (unsupervised) and 81.6% (supervised) on semantic textual similarity tasks.
Builds on: Sentence Embedding, Contrastive Learning, Dropout, Transformer · Leads to: Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks, which takes a different route to the same embeddings
Why it mattered
Sentence embeddings are used whenever a system needs to compare texts: searching documents by meaning, grouping similar questions, or checking whether two sentences say the same thing. Before SimCSE, the best unsupervised sentence vectors came from post-processing BERT's outputs or from contrastive objectives that needed specially built positive pairs. In the paper's Table 5, the best prior unsupervised BERT-base result is 72.05 average Spearman (CT-BERT), and SimCSE-BERT-base reaches 76.25.
The paper's supervised result also changed what training data was useful. Natural language inference (NLI) datasets were already used for sentence embeddings, but as three-way classification. Using entailment pairs as positives and contradiction pairs as hard negatives gave 81.57 average Spearman with BERT-base, and 83.76 with RoBERTa-large, against 79.39 for the best prior supervised contrastive model in the same table (CT-SBERT-base).
The paper also audits evaluation. It shows that published sentence-embedding comparisons used different settings (regressors, Spearman versus Pearson correlation, and aggregation), and it asks the field to unify them. That call matters as much as the numbers, because a gain of 2 points means little if the two systems were measured differently.
The problem
A sentence encoder such as BERT produces one vector per token. Averaging these vectors, or taking the first-token vector, does not give a good sentence representation. The paper's background places the problem in contrastive learning, which needs positive pairs. For images, positives are easy: two random crops of one photo. For text, data augmentation is harder, because deleting or replacing a word can change the meaning. The paper cites this difficulty, and its own tests show that discrete augmentations such as word deletion and replacement underperform.
A second problem is anisotropy: pre-trained embeddings tend to occupy a narrow cone of the vector space, so most pairs look similar even when their meanings differ. The paper says that contrastive learning can counteract this, and it analyses why through two quantities, alignment and uniformity, defined in the math section below.
How it works
The toy example below uses a batch of two sentences and two-dimensional vectors. The numbers are invented for illustration; they are not from the paper.
flowchart LR A["Sentence x"] --> B["Encoder pass 1, dropout mask z"] A --> C["Encoder pass 2, dropout mask z prime"] B --> D["Embedding h"] C --> E["Embedding h prime: the positive"] F["Other sentences in the batch"] --> G["Embeddings: the negatives"] D --> H["Cosine similarity with each candidate"] E --> H G --> H H --> I["Cross-entropy: pull the positive up, push negatives down"]
Setup: temperature . Sentence 1 is "A dog runs" and sentence 2 is "A cat sleeps". Their embeddings after the first pass are and .
- Pick a sentence. Take sentence 1.
- Encode it twice. The same sentence goes through the model twice. Dropout is switched on each time, so the two passes use different random masks. Toy: the second pass gives . Check: its length is , so the vectors are normalised, as cosine similarity needs.
- Score the positive. The positive is the other pass of the same sentence. Its cosine similarity with is .
- Score the negatives. The other sentences in the batch are negatives. Sentence 2's second pass is . Its similarity with is .
- Compute the loss. Divide each similarity by and apply a softmax over the candidates. The probability on the positive is . The loss is . Check: a probability of 0.5 would give a loss of , so 0.184 is lower, as expected for a positive that scores higher than the negative.
- Update. Gradient descent changes the encoder so that and move closer, and moves away from . Toy: if the positive similarity rose to 1, the probability would rise to and the loss would fall to about 0.127.
- Use the result. At test time there is no second pass. The embedding of a sentence is its vector from one pass, and similarity between sentences is cosine similarity between these vectors.
The supervised version uses the same steps, with the positive taken from an annotated entailment pair and an extra contradiction candidate per premise.
The math
Notation: a sentence with positive , embeddings and , cosine similarity , temperature , and a mini-batch of pairs.
For pair in a batch of pairs, the loss is the negative log of the probability that the positive is chosen among the batch: .
Step 2 in symbols: two passes with different masks
For the unsupervised model, the positive is the same sentence. Write for the embedding of with dropout mask . The objective is
The paper uses the standard Transformer dropout (probability 0.1) and adds no other noise. The numerator is the positive pair, and the denominator sums over all sentences in the batch. Note that the denominator includes the positive, as in the toy calculation.
Steps 3 and 4 in symbols: the supervised objective
For supervised SimCSE, each example is a premise , an entailment hypothesis , and a contradiction hypothesis . The objective becomes
The contradiction term is added to the denominator for every example in the batch. This is the hard-negative step. A variant weights the contradiction terms by ; the paper finds best.
Alignment and uniformity (the paper's analysis)
The paper analyses the objective with two quantities from Wang and Isola (2020). For a distribution of positive pairs and normalised embeddings :
Lower is better for both. Alignment says positives are close; uniformity says embeddings are spread over the sphere. The unsupervised experiments show dropout keeps alignment steady while improving uniformity.
Connecting to anisotropy
With infinitely many negatives and normalised embeddings, the paper writes the asymptotic objective as
The first term keeps positives similar. For a finite set of sentences with embedding matrix (row is ), Jensen's inequality gives a lower bound on the second term that is a constant times . The paper states that minimising the second term therefore essentially minimises an upper bound on this sum. Because the diagonal of is fixed at 1 by normalisation, the trace is constant. Since all entries are positive in practice, the sum bounds the largest eigenvalue from above, so reducing it flattens the singular spectrum. The paper presents this as a reason the contrastive objective reduces anisotropy.
Results
The numbers below are from the paper's tables. Spearman correlation measures how well a model's similarity scores rank sentence pairs in the same order as human ratings. Scores are Spearman correlations on STS tasks, averaged over the seven tasks in the "all" setting, unless marked as a development set.
Main result (Table 5). Average STS score:
| Model | Average |
|---|---|
| Best prior unsupervised BERT-base (CT-BERT) | 72.05 |
| SimCSE-BERT-base, unsupervised | 76.25 |
| Best prior supervised BERT-base (CT-SBERT-base) | 79.39 |
| SimCSE-BERT-base, supervised | 81.57 |
| SimCSE-RoBERTa-large, supervised | 83.76 |
The abstract rounds the BERT-base figures to 76.3% and 81.6%.
Dropout ablations (Table 3, STS-B development set, BERT-base). Dropout probability and the score:
| Probability | 0.01 | 0.05 | 0.1 | 0.15 | 0.2 | 0.5 |
|---|---|---|---|---|---|---|
| Score | 72.6 | 81.1 | 82.5 | 81.4 | 80.5 | 71.0 |
Every nonzero rate other than 0.1 scores lower. The paper's no-dropout case (p = 0) also scores far below 0.1, but its two tables give different values for it, so this lesson does not quote one. Using the default 0.1 dropout but the same mask for both passes ("fixed 0.1") gives 43.6.
Augmentation and objectives (Tables 1 and 2, STS-B development set). Unsupervised SimCSE scores 82.5. Among discrete augmentations, cropping 10% gives 77.8, deleting one word gives 75.9, word deletion of 10% gives 75.9, synonym replacement gives 77.4, and masked-language-model replacement of 15% of words gives 62.2. With one encoder for both sentences, the next-sentence objective scores far below SimCSE; the paper's text and table disagree on its exact value, so it is not quoted here. SimCSE scores 82.5 with one encoder and 80.7 with two independent encoders.
Choice of NLI-style data (Table 4, full training sets). Entailment pairs from SNLI and MNLI give 84.9 on the development set; QQP gives 81.8; Flickr30k gives 81.4; ParaNMT gives 78.7. Contradiction pairs alone give 77.6. Adding the contradiction hard negative lifts the entailment setting from 84.9 to 86.2. A dual-encoder version drops to 84.2. The paper gives lexical overlap (bag-of-words F1) of 39% for entailment pairs, against 60% for QQP and 55% for ParaNMT, and reads the lower overlap as a reason human-written hypotheses make better positives.
Limits. The unsupervised model is trained on 10 to the power 6 random English Wikipedia sentences. The paper reports that adding the ANLI dataset did not help. The gains are reported on STS and seven transfer tasks, and the paper notes that some published comparisons used different evaluation settings, so it reports results under a single setting. The analysis of anisotropy relies on an asymptotic argument and a spectrum view, and the paper presents the link to uniformity as an argument rather than a complete proof.
Reading guide
- Section 1, Introduction. Needs Sentence Embedding. Read the two-line summary of the unsupervised and supervised methods.
- Section 2, Background. Needs Contrastive Learning, Cosine Similarity and Softmax Temperature. The objective in Equation 1 is the one the rest of the paper modifies.
- Section 3, Unsupervised SimCSE. Needs Dropout and Transformer. The dropout-mask argument in Equation 3 is the key step.
- Section 4, Supervised SimCSE. Needs Cross-Entropy Loss and Data Augmentation for the comparison with discrete augmentations.
- Section 5, Anisotropy. Needs Word Embedding for the origin of the anisotropy observation and Representation Collapse for the failure the paper describes.
- Section 6, Experiments. Needs BERT: Pre-training of Deep Bidirectional Transformers and RoBERTa: A Robustly Optimized BERT Pretraining Approach for the encoders. Appendix B covers the evaluation settings.
- Section 7, Analysis. Needs Self-Supervised Learning for the training signal without labels.
Check yourself
QuestionIn unsupervised SimCSE, what is the positive pair for a sentence, and what is the only source of difference between its two embeddings?Show answer
The positive pair is the sentence and itself. The sentence goes through the encoder twice, and the two embeddings differ only because independent dropout masks are applied, with the standard Transformer dropout probability of 0.1.
QuestionIn the toy example, the positive similarity is 0.8 and the negative similarity is 0, with . What is the loss for sentence 1, to three decimal places?Show answer
The probability on the positive is . The loss is .
QuestionThe paper's no-dropout and fixed-mask variants both perform much worse. What does the paper say happens to alignment in those variants, and why does it matter?Show answer
In both variants the two embeddings of a sentence are identical, so the positive pair carries no noise, and the paper reports that alignment degrades drastically during training, while unsupervised SimCSE keeps a steady alignment. Alignment measures whether positives stay close, so losing it means the model no longer ties a sentence to its own variants. This is why the paper treats dropout noise as minimal augmentation that keeps alignment while uniformity improves.
QuestionTable 4 shows entailment pairs from NLI beat QQP and ParaNMT as positives. A team building positives from paraphrase pairs asks whether lexical overlap explains the gap. What does the paper report, and what would you check before adopting its conclusion?Show answer
The paper reports bag-of-words F1 of 39% for entailment pairs, against 60% for QQP and 55% for ParaNMT, and suggests that lower overlap makes hypotheses more informative positives. Before adopting this, check whether the overlap difference holds on your own data, and whether your positives are of the same kind as the paper's: the paper's sample sizes were matched at 134k pairs per dataset for its fair comparison, so the comparison assumes that size.
Sources
- Gao, Yao and Chen (2021), SimCSE: Simple Contrastive Learning of Sentence Embeddings, arXiv:2104.08821. https://arxiv.org/abs/2104.08821
- Gao, Yao and Chen (2021), arXiv:2104.08821, PDF. https://arxiv.org/pdf/2104.08821