Sentence-BERT (SBERT)
Ask a BERT model whether two sentences mean the same thing and it answers well — but only if both sentences go in together. Matching one query against ten thousand candidates then costs ten thousand passes through the network. Sentence-BERT, or SBERT, removes that cost by turning each sentence into one fixed-length vector, once.
How the vectors are trained
Two copies of the same encoder run side by side — a siamese setup — and each one's token outputs are collapsed into a single vector by mean pooling:
- Training pairs come from inference data such as SNLI and MultiNLI, where the model judges whether one sentence entails or contradicts another.
- The two sentences never meet inside the network, so the only way to satisfy the objective is to push meaning into the vectors themselves.
- A further round on semantic textual similarity pairs, scored with a cosine objective, calibrates the distances.
Encode once, compare cheaply
Documents are encoded ahead of time into a vector index; a query is encoded at search time and its nearest neighbours come back in milliseconds. That is what makes semantic search over a catalogue, duplicate-question detection on a forum and the retrieval stage in front of a cross-encoder re-ranker practical. The sentence-transformers library is the usual entry point.
Why it matters
Pooling a pre-trained BERT into a sentence vector without this extra training scores worse on similarity than averaging static GloVe embeddings — masked language modelling never asked for vectors comparable by distance. SBERT supplies the missing objective, and with it the division every retrieval stack relies on: cheap vectors to shortlist, an expensive pairwise model only for the survivors.
Sentence-BERT (SBERT) is a fine-tuning scheme that adapts a pre-trained transformer encoder, through siamese training on inference and similarity pairs, to map a whole sentence to one fixed-length vector whose cosine distance reflects meaning. It converts semantic comparison from a pairwise network pass into a vector lookup, which is what makes semantic search, clustering and large-scale duplicate detection tractable. Naively pooled encoder outputs, without this step, compare worse than averaged static embeddings.
Imagine a librarian who, instead of comparing two books page by page whenever someone asks whether they are alike, gives every book a position on a huge map — books about the same thing end up close together. Answering "what else is like this?" becomes a glance at the map.
Sentence-BERT does that for sentences. It reads a sentence and places it as a point in a vast space, so sentences with the same meaning sit near each other even when they share no words at all. "How do I reset my password?" lands beside "I forgot my login". That is how a search box finds what you meant rather than what you typed, and how a help desk notices your question has been asked before.