How to Install sentence-transformers in Python
Embeddings, Retrieval, and Reranking
pip install sentence-transformers
What is sentence-transformers?
Embeddings, Retrieval, and Reranking
[]( [][#github-license] [][#pypi-package] [][#pypi-package] [][#docs-package] Sentence Transformers: Embeddings, Retrieval, and Reranking This framework provides an easy method to compute embeddings for accessing, using, and training state-of-the-art embedding and reranker models. It can be used to compute embeddings using Sentence Transformer models (quickstart), to calculate similarity scores using Cross-Encoder (a.k.a. reranker) models (quickstart) or to generate sparse embeddings using Sparse Encoder models (quickstart). This unlocks a wide range of applications, including semantic search, semantic textual similarity, and paraphrase mining. A wide selection of over 15,000 pre-trained Sentence Transformers models are available for immediate use on 🤗 Hugging Face, including many of the state-of-the-art models from the Massive Text Embeddings Benchmark (MTEB) leaderboard. Additionally, it is easy to train or finetune your own embedding models, reranker models or sparse encoder models using Sentence Transformers, enabling you to create custom models for your specific use cases. For the full documentation, see www.SBERT.net. Installation We recommend Python 3.10+, PyTorch 1.11.0+, and transformers v4.34.0+. Install with pip Install with conda Install from sources Alternatively, you can also clone the latest version from the repository and install it directly from the source code: PyTorch with CUDA If you want to use a GPU / CUDA, you must install PyTorch with the matching CUDA Version. Follow PyTorch - Get Started for further details how to install PyTorch. Getting Started See Quickstart in our documentation. Embedding Models First download a pretrained embedding a.k.a. Sentence Transformer model. Then provide some texts to the model. And that's already it. We now have numpy arrays with the embeddings, one for each text. We can use these to compute similarities. Reranker Models First download a pretrained reranker a.k.a. Cross Encoder model. Then provide some texts to the model. And we're good to go. You can also use to avoid having to perform the reranking manually: Sparse Encoder Models First download a pretrained sparse embedding a.k.a. Sparse Encoder model. Pre-Trained Models We provide a large list of pretrained models for more than 100 languages. Some models are general purpose models, while others produce embeddings for specific use cases. - Pretrained Sentence Transformer (Embedding) Models - Pretrained Cross Encoder (Reranker) Models - Pretrained Sparse Encoder (Sparse Embeddings) Models Training This framework allows you to fine-tune your own sentence embedding methods, so that you get task-specific sentence embeddings. You have various options to choose from in order to get perfect sentence embeddings for your specific task. - Embedding Models - Sentence Transformer > Training Overview - Sentence Transformer > Training Examples or training examples on GitHub. - Reranker Models - Cross Encoder > Training Overview - Cross Encoder > Training Examples or training examples on GitHub. - Sparse Embedding Models - Sparse Encoder > Training Overview - Sparse Encoder > Training Examples or training examples on GitHub. Some highlights across the different types of training are: - Support of various transformer networks including BERT, RoBERTa, XLM-R, DistilBERT, Electra, BART, ... - Multi-Lingual and multi-task learning - Evaluation during training to find optimal model - 20+ loss functions for embedding models, 10+ loss functions for reranker models and 10+ loss functions for sparse embedding models, allowing you to tune models specifically for semantic search, paraphrase mining, semantic similarity comparison, clustering, triplet loss, contrastive loss, etc. Application Examples You can use this framework for: - Computing Sentence Embeddings - Dense Embeddings - Sparse Embeddings - Semantic Textual Similarity - Dense STS - Sparse STS - Semantic Search - Dense Search - Sparse Search - Retrieve & Re-Rank - Dense only Retrieval - Sparse/Dense/Hybrid Retrieval - Clustering - Paraphrase Mining - Translated Sentence Mining - Multilingual Image Search, Clustering & Duplicate Detection and many more use-cases. For all examples, see examples/sentence_transformer/applications. Development setup After cloning the repo (or a fork) to your machine, in a virtual environment, run: To test your changes, run: Citing & Authors If you find this repository helpful, feel free to cite our publication Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks: If you use one of the multilingual models, feel free to cite our publication Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation: Please have a look at Publications for our different publications that are integrated into SentenceTransformers. Maintainers Maintainer: Tom Aarsen, 🤗 Hugging Face Don't hesitate to open an issue if something is broken (and it shouldn't be) or if you have further questions. --- This project was originally developed by the Ubiquitous Knowledge Processing (UKP) Lab at TU Darmstadt. We're grateful for their foundational work and continued contributions to the field. > This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.
Quick Start
Minimal example to get started with sentence-transformers:
import sentence_transformers
print(sentence_transformers.__version__)
Installation
pip (standard)
pip install sentence-transformers
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install sentence-transformers
pip3
pip3 install sentence-transformers
conda
conda install -c conda-forge sentence-transformers
Poetry
poetry add sentence-transformers
Dependencies
Installing sentence-transformers will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import sentence_transformers; print(sentence_transformers.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing sentence-transformers with pip.
ModuleNotFoundError: No module named 'sentence_transformers'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install sentence-transformers. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'sentence_transformers' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install sentence-transformers to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'sentence_transformers'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show sentence-transformers and upgrade with pip install --upgrade sentence-transformers.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install sentence-transformers. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user sentence-transformers
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org sentence-transformers
RuntimeError: CUDA out of memory
Cause: Model or batch size exceeds GPU memory.
Fix: Reduce batch size, call torch.cuda.empty_cache(), or run on CPU.
Recent Releases
| Version | Released |
|---|---|
5.4.0 latest |
2026-04-09 |
5.3.0 |
2026-03-12 |
5.2.3 |
2026-02-17 |
5.2.2 |
2026-01-27 |
5.2.1 |
2026-01-26 |
Manage sentence-transformers
Upgrade to latest version
pip install --upgrade sentence-transformers
Install a specific version
pip install sentence-transformers==5.4.0
Uninstall
pip uninstall sentence-transformers
Check what is installed
pip show sentence-transformers