Paper commentary
Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Sentence-BERT fine-tunes BERT so sentences can be compared with cosine-similarity
- Problem BERT compares sentence pairs too slowly for large collections.
- Method SBERT is a siamese BERT network that encodes each sentence on its own, so each sentence is embedded once. Fine-tuning pulls vectors of related sentences together, and cosine-similarity then compares them directly.
- Results SBERT-NLI-large reached a mean Spearman of 76.55 on the STS tasks, compared to 71.22 for Universal Sentence Encoder. The most-similar-pair search drops from about 65 hours to about 5 seconds.
Why pairwise BERT scoring stalls on large collections
BERT is a cross-encoder: it reads two sentences together in one pass and outputs a target value for the pair. That works well for a single pair, but the number of pairs grows quadratically with the size of the collection. For n = 10 000 sentences, finding the most similar pair means 49 995 000 inference computations, roughly 65 hours on a V100 GPU.
Quora shows the same problem at a larger scale, where answering one new question with BERT would take over 50 hours.
A cheaper route is to encode each sentence on its own and compare the resulting vectors. Plain BERT does not give useful vectors this way, because its outputs were never shaped for comparison. Averaging the output layer gives a mean Spearman of 54.81 on the STS tasks, compared to 61.32 for averaged GloVe embeddings. Using the [CLS] output is worse, at a mean Spearman of 29.19.
The authors conclude that the vector space BERT produces out of the box is poorly suited to cosine-similarity.
So the open question is whether fine-tuning can give BERT the geometry that search needs without losing its accuracy.
A siamese encoder that yields one vector per sentence
The key idea is to run each sentence through the same BERT or RoBERTa weights, so both inputs are encoded by one shared network. Fine-tuning then pulls the vectors of related sentences together, so that cosine-similarity can compare them directly. Because the network encodes one sentence at a time, each sentence needs to be encoded only once.
BERT outputs one vector per token, so a pooling step is needed to reduce them to a single fixed-size vector. The default MEAN strategy averages the token vectors, MAX takes the maximum over time, and CLS uses the output of the first token. The ablation later shows that the choice of pooling matters most under the regression objective.
At inference, the two pooled vectors u and v give a cosine-similarity between -1 and 1. Scoring a whole collection then means computing each sentence vector once and comparing vectors, instead of running BERT for every pair. Starting from pretrained weights lets SBERT be tuned in less than 20 minutes.
Three objectives and the data that trains them
For labeled sentence pairs, the classification objective concatenates u, v and the element-wise difference |u-v|, then applies a trainable weight matrix and a softmax. Training minimizes cross-entropy loss, and the |u-v| block tells the classifier how far apart the two vectors are in each dimension.
For similarity labels, the regression objective takes the cosine-similarity of u and v and is trained with mean-squared-error loss. For triplets of anchor, positive and negative sentences, the loss is \[ \max(\|s_a-s_p\|-\|s_a-s_n\|+\epsilon,0) \] using Euclidean distance. Here the margin ε is set to 1, and the loss reaches zero once the positive sentence is at least ε closer to the anchor than the negative one.
The classification model is trained on SNLI, with 570,000 sentence pairs, and MultiNLI, with 430,000 pairs, for one epoch. The authors used batch size 16, the Adam optimizer with learning rate 2e-5, and a linear warm-up over 10% of the training data.
Unsupervised and supervised STS results
The first test asks whether the embeddings are useful on STS without any STS-specific training data. SBERT-NLI-large reached a mean Spearman of 76.55 over the STS tasks, compared to 71.22 for Universal Sentence Encoder and 65.01 for InferSent - GloVe. The base model reached 74.89, and SRoBERTa-NLI-large reached 76.68, so the backbone choice made only a small difference.
The gap to the 54.81 of averaged, untuned BERT outputs points to the fine-tuning as the source of the improvement.
Universal Sentence Encoder was the stronger model on SICK-R, scoring 76.69, compared to 73.75 for SBERT-NLI-large. The authors attribute this to the training data of Universal Sentence Encoder, which includes news, question-answer pages and discussion forums. SBERT, by contrast, was pretrained only on Wikipedia through BERT and on NLI data.
Pretraining on NLI and then fine-tuning on STSb gave a 1-2 point improvement, and a 3-4 point gain for the BERT cross-encoder. With NLI and STSb training, BERT scored 88.33 for the base model, compared to 85.35 for SBERT-NLI-STSb-base. Each system was trained with 10 random seeds, because single runs vary too much to compare.
Argument, Wikipedia and SentEval results
The Argument Facet Similarity corpus has 6,000 argument pairs from dialogs on three topics, and similarity there requires matching both the claim and the reasoning. Under 10-fold cross-validation, SBERT-AFS-large reached a Pearson r of 77.85, compared to 78.68 for BERT-AFS-large. In the cross-topic setup, where two topics train and the third is tested, SBERT-AFS-large fell to a Spearman of 53.10, compared to 60.34 for BERT-AFS-large.
The authors describe this as a drop of about 7 points Spearman, which they explain by BERT comparing both sentences directly while SBERT must map each sentence alone.
The Wikipedia section task trains on about 1.8 million triplets and tests on 222,957 triplets from articles not used in training. SBERT-WikiSec-large reached an accuracy of 0.8078, compared to 0.74 for the BiLSTM triplet model of Dor et al.
SBERT-NLI-large averaged 87.69 over the seven tasks, compared to 85.59 for InferSent - GloVe and 85.10 for Universal Sentence Encoder. SBERT was best on 5 of the 7 tasks, but Universal Sentence Encoder scored 93.2 on TREC, compared to 87.4 for SBERT-NLI-large. The authors link that gap to Universal Sentence Encoder being pretrained on question-answering data.
Which design choices matter
Each configuration was trained with 10 random seeds, and the scores are measured on the STSb development split. For the NLI-trained classifier, MEAN scored 80.78, MAX 79.07 and CLS 79.80. For regression on STSb, MEAN reached 87.44, while MAX fell to 69.92 and CLS reached 86.62. So pooling matters little for the classifier but a great deal for regression, where MAX fails, which the authors contrast with InferSent benefiting from MAX.
Concatenating (u,v,|u-v|) gave 80.78, while adding the element-wise product u*v lowered the score to 80.44. Using only |u-v| gave 69.78, and using only (u,v) gave 66.04, so the difference term carries most of the signal. InferSent and Universal Sentence Encoder both use u*v, but in this architecture adding it decreased performance. The concatenation matters only while training the classifier, because inference uses u and v with cosine-similarity alone.
Speed on GPU and CPU
The authors timed embedding of STS benchmark sentences on an Intel i7-5820K CPU and an Nvidia Tesla V100 GPU. GloVe averages ran in a Python loop with NumPy, InferSent in PyTorch, Universal Sentence Encoder through TensorFlow Hub, and SBERT in PyTorch. Smart batching groups sentences of similar length, so padding only reaches the longest item in each mini-batch.
Smart batching added a 48% speed-up on GPU and 89% on CPU.
The authors attribute this to InferSent's single BiLSTM layer, while BERT stacks 12 transformer layers, and transformers gain more on GPUs.
Where the evidence stops
The cross-topic AFS result is the clearest weak point, since SBERT drops about 7 points Spearman when only two topics train it. The authors suspect that more than two training topics are needed for SBERT to match BERT on this task.
Universal Sentence Encoder beats SBERT on SICK-R and on TREC, so SBERT is not the best embedding on every task. Replacing BERT with RoBERTa did not yield a significant improvement in the authors' experiments. Pearson correlation is reported on AFS only to match Misra et al., because the authors consider it poorly suited for STS.
SBERT is not meant as a general transfer learner, and the authors suggest fine-tuning BERT for new tasks instead. The speed measurements use STS benchmark sentences on one hardware setup, so the throughput figures hold for that setting.
Paper info
- Authors
- Nils Reimers, Iryna Gurevych
- Venue
- arXiv · Preprint
- First published
- 2019-8-27
- Added
- 2026-11-6
- Updated
- 2019-8-27
- Version
- v1
- arXiv
- 1908.10084
- Category
- cs.CL
- Original paper terms
- CC BY-SA 4.0
- What we show
- Paper info and commentary
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
Nils Reimers, Iryna Gurevych (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. arXiv:1908.10084v1. https://arxiv.org/abs/1908.10084v1
BibTeX
@misc{reimers2019sentence,
title = {{Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks}},
author = {Nils Reimers and Iryna Gurevych},
year = {2019},
eprint = {1908.10084},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1908.10084v1}
}