Repo of the Day
huggingface/sentence-transformers
Published: May 21, 2025
Open repository ↗State-of-the-Art Text Embeddings
Summary
Sentence Transformers is a Python framework for computing, training, and using text embeddings, rerankers, sparse encoders, and late-interaction retrievers. It exposes four model classes — SentenceTransformer, CrossEncoder, SparseEncoder, and MultiVectorEncoder — that share a common API and load from 15,000+ pretrained checkpoints on Hugging Face. The project is published under Apache-2.0 and the README states it "contains experimental software and is published for the sole purpose of giving additional background details on the respective publication."
What it is useful for
- Semantic search and semantic textual similarity across 100+ languages.
- Two-stage retrieve-and-rerank pipelines, where a fast bi-encoder retrieves candidates and a Cross-Encoder reranks them.
- Sparse retrieval with SPLADE-style models when you want inverted-index-friendly vectors instead of dense ones.
- ColBERT-style late interaction for higher-quality retrieval using token-level multi-vector representations.
- Fine-tuning on domain data. The README documents 20+ loss functions for embedding models, 10+ for rerankers, and 10+ for sparse encoders, with multilingual and multi-task learning support and evaluation during training.
- Multimodal embeddings and reranking for text, image, audio, and video through a single API.
How engineers can use it
The README recommends Python 3.10+, PyTorch 2.2+, and transformers v5.0+, installed with pip install -U sentence-transformers. For an editable dev install, clone the repo and run python -m pip install -e ".[dev]", pre-commit install, then pytest.
The four APIs follow the same pattern: load by Hub id, call encode (or predict for rerankers), then score.
- Dense embeddings:
SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2").encode(sentences)returns NumPy arrays (README example shape(3, 384));model.similarity(embeddings, embeddings)returns a cosine-style matrix. - Reranking:
CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")withmodel.predict([(query, passage), ...])returns scores, andmodel.rank(query, passages, return_documents=True)sorts candidates. The README example correctly ranks Berlin-population passages by relevance. - Sparse embeddings:
SparseEncoder("naver/splade-cocondenser-ensembledistil")produces vocabulary-sized sparse vectors (README example shape(3, 30522)with ~99.84% sparsity).SparseEncoder.sparsity(embeddings)reports stats. - Multi-vector (late interaction):
MultiVectorEncoder("lightonai/GTE-ModernColBERT-v1")usesencode_query/encode_documentto produce per-token 128-d vectors, scored via MaxSim.
For training, the README links to per-model overviews on sbert.net and to blog posts covering Matryoshka embeddings, static (CPU-friendly) embeddings, and binary/scalar quantization for post-training compression. The sbert.net docs cover installation variants (uv, conda, source), CUDA setup, and extras such as [image], [audio], [video], [train], [onnx], [openvino], and [dev].