- Introduced by
- Kiros et al. (Skip-Thought, 2015); Reimers & Gurevych (Sentence-BERT, 2019)
- Year
- 2015–2019
- Type
- Representation learning / embedding
- Family
- Deep learning / NLP / CV
What does it do?
Sentence embeddings map a sentence or short text to a single fixed-length dense vector that encodes its meaning.
Downstream tasks such as semantic similarity, clustering, retrieval and classification can then operate on these numerical vectors instead of raw text. The vectors are typically produced by a pre-trained Transformer encoder whose per-token states are pooled into one vector.
The intuition behind the method
Think of each sentence as a point in a high-dimensional space in which distance reflects meaning: two sentences that paraphrase each other should lie close together, and unrelated sentences should lie further apart. A sentence embedding model learns this geometry from text. Once trained, embedding a new sentence requires only a forward pass through the encoder, with no further training. Downstream tasks reuse the same coordinates, so texts can be compared or grouped without labels for each task. Whether this geometry suits your data is the main thing to check, because the encoder was trained on someone else's corpus and objective.
History
Early sentence representations averaged pre-trained word vectors such as word2vec and GloVe. Skip-Thought Vectors (Kiros et al., 2015) trained an encoder to predict the sentences surrounding a given sentence, yielding learned sentence encoders of this kind. Sentence-BERT (Reimers & Gurevych, 2019) applied Siamese BERT networks trained on NLI data; the paper reports that this markedly improved BERT-derived sentence vectors and reduced the time to find the most similar pair among 10,000 sentences from 65 hours to about 5 seconds.
When to use it
Choose sentence embeddings when a task depends on semantic closeness between texts, such as semantic similarity, paraphrase detection, clustering, dense retrieval, or classification with few or no labels per example. They suit collections of sentences or short paragraphs where one general-purpose representation is needed across several tasks. Do not rely on raw embeddings when you need calibrated probabilities or interpretable feature weights; these usually require a task-specific head or calibration. Avoid them for very short inputs such as one or two words, which carry too little context for a stable vector, for languages without a suitable pre-trained encoder, and for long documents unless you chunk them to fit the encoder's token limit. Cost grows with corpus size and encoder size, so check the compute budget before encoding large collections. The central assumption is that the encoder's training corpus and objective define the similarity geometry, so the vectors are reliable only where the target texts resemble that training domain; check this on a labelled sample before relying on the embeddings.
Limitations and considerations
- Quality depends on how close the pre-trained model's training data is to your domain; specialised jargon or out-of-domain text can degrade the similarity scores.
- Encoders have a fixed token limit (512 tokens for BERT-based models), so longer documents must be chunked, and a single fixed-length vector can lose local detail from long texts.
- Cosine similarity values are specific to each model, so cut-offs used for downstream decisions must be calibrated empirically on the target data.
- Large Transformer encoders need substantial GPU memory to run, and storing vectors for millions of documents requires considerable disk space.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Capture meaning beyond shared vocabulary, so paraphrases with little word overlap can still score as similar, which bag-of-words and TF-IDF representations generally miss.
- A pre-trained encoder can be applied to a new collection directly, without labelled training data, which helps when annotation is scarce.
- Once the corpus is encoded, similarity search reduces to vector comparison, which can be accelerated with approximate nearest-neighbour indices.
- A single set of vectors can serve several tasks, including clustering, retrieval, de-duplication and classification.
- Multilingual encoders such as paraphrase-multilingual-mpnet-base-v2 can compare sentences across languages with one model.
Applications
- Semantic textual similarity and paraphrase detection in academic and commercial text corpora.
- Dense passage retrieval in open-domain question answering and search engines.
- Document and paragraph clustering for topic discovery without predefined categories.
- Zero-shot and few-shot text classification by comparing embeddings to label prototypes.
- Near-duplicate detection and de-duplication in large bibliographic databases.
- Cross-lingual semantic alignment in multilingual research synthesis.
How it works
How it works
The input sentence is split into tokens (subwords or words) according to the encoder vocabulary — typically a BERT-style WordPiece or SentencePiece tokeniser. Special tokens such as [CLS] and [SEP] are inserted to mark sentence boundaries, preparing the sequence for the encoder.
A deep encoder — most commonly a pre-trained Transformer such as BERT or RoBERTa — processes the token sequence and produces a contextual hidden state for every position. Each hidden state carries information about its token in the context of the entire sentence.
Formula
\mathbf{s} = \text{Pooling}(\text{Encoder}(w_1, \ldots, w_n)) \in \mathbb{R}^dThe per-token hidden states are collapsed into one fixed-size vector by a pooling operation. The two common choices are mean pooling, which averages all token vectors, and extracting the [CLS] token vector. Sentence-BERT adopts mean pooling as its default; a raw [CLS] vector from an encoder not trained for sentence comparison is generally a weaker sentence representation.
A pre-trained encoder is usually fine-tuned before its vectors are useful for sentence comparison. Sentence-BERT is trained as a Siamese network on natural-language inference pairs: the pooled vectors of the two sentences are combined (for example through their concatenation and difference) and passed to a softmax classification objective, which shapes the space so that related sentence pairs end up closer together. This is a supervised classification objective rather than a contrastive loss.
At inference time, two sentence vectors are compared with cosine similarity: the dot product of the unit-normalised vectors. Higher cosine values mean the model places the two sentences closer together, and a value near 0 means the vectors are orthogonal. The absolute number has no fixed meaning across models, so thresholds for 'equivalent' or 'related' must be calibrated on labelled pairs from the target data. This single number drives retrieval, de-duplication, clustering, and classification tasks.
Formula
\text{sim}(\mathbf{s}_i, \mathbf{s}_j) = \frac{\mathbf{s}_i \cdot \mathbf{s}_j}{\|\mathbf{s}_i\|\|\mathbf{s}_j\|}Common pitfalls
- Using the raw [CLS] vector of a base BERT model as a sentence embedding without fine-tuning, which typically gives weak cosine-similarity results.
- Comparing vectors produced by different encoders or pooling strategies; their cosine scores are not comparable and should not be mixed in one ranking.
- Setting a fixed similarity cut-off for 'duplicate' or 'related' without calibrating it on labelled sentence pairs from your own domain.
- Skipping vector normalisation when the search index uses only dot products; unnormalised dot products rank pairs differently from cosine similarity.
- Reading individual embedding dimensions as interpretable features; no single coordinate is expected to correspond to a specific semantic property.
Frequently asked questions
Which pre-trained model should I use?
For English general-purpose similarity, 'all-mpnet-base-v2' from the sentence-transformers library is a reasonable starting point. For multilingual tasks, 'paraphrase-multilingual-mpnet-base-v2' is a candidate. Benchmark both on a small labelled sample from your target domain before committing to one.
How is this different from using BERT directly?
Standard BERT produces per-token representations trained for token-level objectives, and its raw [CLS] vector is usually a weak sentence embedding for cosine comparison. Sentence-BERT fine-tunes BERT in a Siamese architecture with a training objective on sentence pairs, so the resulting vectors are better suited to sentence-level comparison.
How many labelled examples do I need?
Off-the-shelf sentence embedding models from the sentence-transformers library require zero labelled examples for inference. If you fine-tune on your domain, even a few hundred sentence pairs with similarity labels can noticeably improve performance.
Can I use sentence embeddings for long documents?
Most encoders have a token limit (512 tokens for BERT-based models). For longer texts you can chunk the document into sentences or paragraphs, embed each chunk, and pool the chunk vectors. Alternatively, models like Longformer handle longer contexts natively.
How do I evaluate the quality of my embeddings?
Standard benchmarks include STS-B (Semantic Textual Similarity Benchmark) and MTEB (Massive Text Embedding Benchmark). On your own data, human-annotated sentence pairs with similarity scores let you compute Spearman correlation between model scores and human judgements.
Related methods
Sources
Reimers, N., & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 3980–3990.
Open DOI referenceKiros, R., Zhu, Y., Salakhutdinov, R., Zemel, R. S., Torralba, A., Urtasun, R., & Fidler, S. (2015). Skip-Thought Vectors. Advances in Neural Information Processing Systems (NeurIPS), 28.
Open publication reference