Introduction
Sentence-BERT (SBERT) addresses the computational bottleneck inherent in using BERT for large-scale semantic similarity tasks. While BERT and RoBERTa achieve state-of-the-art performance on sentence-pair tasks using a cross-encoder architecture, this setup requires feeding both sentences into the network simultaneously. This approach does not scale: finding the most similar pair in a collection of 10,000 sentences requires approximately 50 million inference computations, taking roughly 65 hours on a modern GPU. SBERT introduces a siamese network structure to generate independent, semantically meaningful sentence embeddings, reducing this search time to just 5 seconds while maintaining high accuracy.
Methodology
SBERT adapts the BERT architecture into a siamese network to derive fixed-sized sentence embeddings. A pooling operation is added to the output of BERT; the authors found that taking the MEAN of all output vectors provides the most effective representation.
Training Objectives
The model is fine-tuned using different objective functions based on the available training data:
- Classification Objective: For datasets like Natural Language Inference (NLI), the embeddings $u$ and $v$ are concatenated with their element-wise difference $|u - v|$. This combined vector is then fed into a softmax classifier. The inclusion of the difference $|u - v|$ is a critical insight, as it effectively captures the distance between dimensions.
- Regression Objective: The model minimizes the mean-squared error between the cosine similarity of the two embeddings and a gold-standard similarity score.
- Triplet Objective: This objective ensures that an "anchor" sentence is closer in vector space to a "positive" example than to a "negative" one.
Evaluation and Results
The authors evaluated SBERT on several Semantic Textual Similarity (STS) tasks and transfer learning benchmarks.
Semantic Textual Similarity (STS)
A significant finding is that "out-of-the-box" BERT embeddings (e.g., averaging layers or using the [CLS] token) perform poorly, often trailing behind simple GloVe word averages. In contrast, SBERT significantly outperforms previous state-of-the-art methods such as InferSent and the Universal Sentence Encoder (USE). For instance, SBERT achieves over an 11-point improvement over InferSent on certain benchmarks.
Efficiency and Practicality
The primary advantage of SBERT is its efficiency. By producing independent embeddings, it enables the use of optimized similarity search libraries like FAISS, allowing for sub-millisecond retrieval. While this approach loses the fine-grained "cross-attention" of the original BERT cross-encoder, the massive gain in speed makes SBERT viable for production-scale semantic search and clustering.
Conclusion
Sentence-BERT provides a practical solution for generating high-quality sentence embeddings using transformer-based models. By employing a siamese network architecture, it overcomes the scaling limitations of cross-encoders, enabling massive speedups for large-scale applications. While cross-encoders remain superior for certain complex tasks requiring token-level interaction, SBERT's balance of performance and efficiency represents a major step forward for semantic information retrieval.
Summary updated