Skip to content
AI360Xpert
Paper Breakdowns
Paper breakdown

Sentence-BERT (SBERT)

The 2019 paper that adapted BERT for generating semantically meaningful sentence embeddings that can be compared using cosine similarity.

Paper: Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks

Authors: Nils Reimers, Iryna Gurevych · 2019

Read the paper
SBERT uses a Siamese network architecture where two sentences pass through identical BERT models to produce embeddings that are compared via cosine similarity.
SBERT uses a Siamese network architecture where two sentences pass through identical BERT models to produce embeddings that are compared via cosine similarity.

The Problem

BERT achieved state-of-the-art performance on sentence-pair tasks (like semantic textual similarity) by using a cross-encoder: feeding both sentences into the model simultaneously and letting them attend to each other. However, this is computationally disastrous for search. Finding the most similar pair in a collection of 10,000 sentences requires 50 million BERT inference calls (taking ~65 hours). BERT did not produce good standalone sentence embeddings; extracting the [CLS] token or averaging outputs yielded embeddings worse than simple GloVe embeddings.

The Idea

The authors introduced Sentence-BERT (SBERT), modifying the pre-trained BERT network to use a siamese (and triplet) network structure. This allows SBERT to derive semantically meaningful sentence embeddings that can be compared using a simple distance metric like cosine similarity. This reduced the time to find the most similar pair from 65 hours to 5 seconds, while maintaining high accuracy.

How It Works

SBERT uses a siamese architecture where two sentences (A and B) are processed by the same BERT network with tied weights.

Pooling: SBERT adds a pooling operation to the output of BERT to derive a fixed-sized sentence vector. They experimented with using the [CLS] token, computing the mean of all output vectors (MEAN-strategy), or computing a max-over-time of the output vectors (MAX-strategy). The MEAN strategy performed best.

Objective Functions: Depending on the training data, SBERT is trained with different structures:

  • Classification Objective: For datasets with categorical labels (like contradiction/entailment), it concatenates the embeddings u, v, and their difference |u-v|, passing them to a softmax classifier.
  • Regression Objective: For datasets with continuous similarity scores, it directly computes the cosine similarity between the embeddings and uses mean squared error loss.

Why It Mattered

SBERT made BERT usable for semantic search, clustering, and massive-scale similarity tasks. It birthed the sentence-transformers library, which became the standard tool in the Python ecosystem for generating text embeddings.

What Came After

SBERT laid the foundation for the massive proliferation of embedding models on the Hugging Face Hub (the Massive Text Embedding Benchmark / MTEB). While newer models (like E5, BGE, or modern OpenAI embeddings) use more data and contrastive learning techniques, they almost all follow the siamese dual-encoder paradigm pioneered by SBERT.