Skip to content

Commit 9cfa9ad

Browse files
committed
Merge branch 'master' into v5.1-release
2 parents 22ff509 + 85ec645 commit 9cfa9ad

File tree

110 files changed

+1131
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1131
-597
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ env:
1515
TRANSFORMERS_IS_CI: 1
1616

1717
jobs:
18-
1918
test_sampling:
2019
name: Run unit tests
2120
strategy:
2221
matrix:
23-
python-version: ['3.9', '3.10', '3.11', '3.12']
22+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2423
os: [ubuntu-latest, windows-latest]
2524
fail-fast: false
2625
runs-on: ${{ matrix.os }}
@@ -71,7 +70,7 @@ jobs:
7170
7271
- name: Install model2vec
7372
run: python -m pip install model2vec
74-
if: ${{ contains(fromJSON('["3.10", "3.11", "3.12"]'), matrix.python-version) }}
73+
if: ${{ contains(fromJSON('["3.10", "3.11", "3.12", "3.13"]'), matrix.python-version) }}
7574

7675
- name: Run unit tests
7776
run: |

NOTICE.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
-------------------------------------------------------------------------------
2-
Copyright 2019
2+
Sentence Transformers
3+
4+
Copyright 2019-2025
35
Ubiquitous Knowledge Processing (UKP) Lab
46
Technische Universität Darmstadt
7+
8+
Copyright 2025-present
9+
Hugging Face, Inc.
510
-------------------------------------------------------------------------------

README.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<!--- BADGES: START --->
2+
23
[![HF Models](https://img.shields.io/badge/%F0%9F%A4%97-models-yellow)](https://huggingface.co/models?library=sentence-transformers)
34
[![GitHub - License](https://img.shields.io/github/license/UKPLab/sentence-transformers?logo=github&style=flat&color=green)][#github-license]
45
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sentence-transformers?logo=pypi&style=flat&color=blue)][#pypi-package]
56
[![PyPI - Package Version](https://img.shields.io/pypi/v/sentence-transformers?logo=pypi&style=flat&color=orange)][#pypi-package]
67
[![Docs - GitHub.io](https://img.shields.io/static/v1?logo=github&style=flat&color=pink&label=docs&message=sentence-transformers)][#docs-package]
8+
79
<!-- [![PyPI - Downloads](https://img.shields.io/pypi/dm/sentence-transformers?logo=pypi&style=flat&color=green)][#pypi-package] -->
810

9-
[#github-license]: https://github.com/UKPLab/sentence-transformers/blob/master/LICENSE
10-
[#pypi-package]: https://pypi.org/project/sentence-transformers/
11-
[#conda-forge-package]: https://anaconda.org/conda-forge/sentence-transformers
12-
[#docs-package]: https://www.sbert.net/
1311
<!--- BADGES: END --->
1412

1513
# Sentence Transformers: Embeddings, Retrieval, and Reranking
@@ -38,11 +36,11 @@ conda install -c conda-forge sentence-transformers
3836

3937
**Install from sources**
4038

41-
Alternatively, you can also clone the latest version from the [repository](https://github.com/UKPLab/sentence-transformers) and install it directly from the source code:
39+
Alternatively, you can also clone the latest version from the [repository](https://github.com/huggingface/sentence-transformers) and install it directly from the source code:
4240

43-
````
41+
```
4442
pip install -e .
45-
````
43+
```
4644

4745
**PyTorch with CUDA**
4846

@@ -57,15 +55,15 @@ See [Quickstart](https://www.sbert.net/docs/quickstart.html) in our documentatio
5755

5856
First download a pretrained embedding a.k.a. Sentence Transformer model.
5957

60-
````python
58+
```python
6159
from sentence_transformers import SentenceTransformer
6260

6361
model = SentenceTransformer("all-MiniLM-L6-v2")
64-
````
62+
```
6563

6664
Then provide some texts to the model.
6765

68-
````python
66+
```python
6967
sentences = [
7068
"The weather is lovely today.",
7169
"It's so sunny outside!",
@@ -74,17 +72,17 @@ sentences = [
7472
embeddings = model.encode(sentences)
7573
print(embeddings.shape)
7674
# => (3, 384)
77-
````
75+
```
7876

7977
And that's already it. We now have numpy arrays with the embeddings, one for each text. We can use these to compute similarities.
8078

81-
````python
79+
```python
8280
similarities = model.similarity(embeddings, embeddings)
8381
print(similarities)
8482
# tensor([[1.0000, 0.6660, 0.1046],
8583
# [0.6660, 1.0000, 0.1411],
8684
# [0.1046, 0.1411, 1.0000]])
87-
````
85+
```
8886

8987
### Reranker Models
9088

@@ -130,6 +128,7 @@ Query: How many people live in Berlin?
130128
- #1 (5.51): Berlin has a yearly total of about 135 million day visitors, making it one of the most-visited cities in the European Union.
131129
"""
132130
```
131+
133132
### Sparse Encoder Models
134133

135134
First download a pretrained sparse embedding a.k.a. Sparse Encoder model.
@@ -168,27 +167,28 @@ print(f"Sparsity: {stats['sparsity_ratio']:.2%}")
168167

169168
## Pre-Trained Models
170169

171-
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.
170+
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.
172171

173-
* [Pretrained Sentence Transformer (Embedding) Models](https://sbert.net/docs/sentence_transformer/pretrained_models.html)
174-
* [Pretrained Cross Encoder (Reranker) Models](https://sbert.net/docs/cross_encoder/pretrained_models.html)
175-
* [Pretrained Sparse Encoder (Sparse Embeddings) Models](https://sbert.net/docs/sparse_encoder/pretrained_models.html)
172+
- [Pretrained Sentence Transformer (Embedding) Models](https://sbert.net/docs/sentence_transformer/pretrained_models.html)
173+
- [Pretrained Cross Encoder (Reranker) Models](https://sbert.net/docs/cross_encoder/pretrained_models.html)
174+
- [Pretrained Sparse Encoder (Sparse Embeddings) Models](https://sbert.net/docs/sparse_encoder/pretrained_models.html)
176175

177176
## Training
178177

179-
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.
178+
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.
180179

181-
* Embedding Models
182-
* [Sentence Transformer > Training Overview](https://www.sbert.net/docs/sentence_transformer/training_overview.html)
183-
* [Sentence Transformer > Training Examples](https://www.sbert.net/docs/sentence_transformer/training/examples.html) or [training examples on GitHub](https://github.com/UKPLab/sentence-transformers/tree/master/examples/sentence_transformer/training).
184-
* Reranker Models
185-
* [Cross Encoder > Training Overview](https://www.sbert.net/docs/cross_encoder/training_overview.html)
186-
* [Cross Encoder > Training Examples](https://www.sbert.net/docs/cross_encoder/training/examples.html) or [training examples on GitHub](https://github.com/UKPLab/sentence-transformers/tree/master/examples/cross_encoder/training).
187-
* Sparse Embedding Models
188-
* [Sparse Encoder > Training Overview](https://www.sbert.net/docs/sparse_encoder/training_overview.html)
189-
* [Sparse Encoder > Training Examples](https://www.sbert.net/docs/sparse_encoder/training/examples.html) or [training examples on GitHub](https://github.com/UKPLab/sentence-transformers/tree/master/examples/sparse_encoder/training).
180+
- Embedding Models
181+
- [Sentence Transformer > Training Overview](https://www.sbert.net/docs/sentence_transformer/training_overview.html)
182+
- [Sentence Transformer > Training Examples](https://www.sbert.net/docs/sentence_transformer/training/examples.html) or [training examples on GitHub](https://github.com/huggingface/sentence-transformers/tree/master/examples/sentence_transformer/training).
183+
- Reranker Models
184+
- [Cross Encoder > Training Overview](https://www.sbert.net/docs/cross_encoder/training_overview.html)
185+
- [Cross Encoder > Training Examples](https://www.sbert.net/docs/cross_encoder/training/examples.html) or [training examples on GitHub](https://github.com/huggingface/sentence-transformers/tree/master/examples/cross_encoder/training).
186+
- Sparse Embedding Models
187+
- [Sparse Encoder > Training Overview](https://www.sbert.net/docs/sparse_encoder/training_overview.html)
188+
- [Sparse Encoder > Training Examples](https://www.sbert.net/docs/sparse_encoder/training/examples.html) or [training examples on GitHub](https://github.com/huggingface/sentence-transformers/tree/master/examples/sparse_encoder/training).
190189

191190
Some highlights across the different types of training are:
191+
192192
- Support of various transformer networks including BERT, RoBERTa, XLM-R, DistilBERT, Electra, BART, ...
193193
- Multi-Lingual and multi-task learning
194194
- Evaluation during training to find optimal model
@@ -199,29 +199,36 @@ Some highlights across the different types of training are:
199199
You can use this framework for:
200200

201201
- **Computing Sentence Embeddings**
202+
202203
- [Dense Embeddings](https://www.sbert.net/examples/sentence_transformer/applications/computing-embeddings/README.html)
203204
- [Sparse Embeddings](https://www.sbert.net/examples/sparse_encoder/applications/computing_embeddings/README.html)
204205

205-
- **Semantic Textual Similarity**
206+
- **Semantic Textual Similarity**
207+
206208
- [Dense STS](https://www.sbert.net/docs/sentence_transformer/usage/semantic_textual_similarity.html)
207209
- [Sparse STS](https://www.sbert.net/examples/sparse_encoder/applications/semantic_textual_similarity/README.html)
208210

209211
- **Semantic Search**
210-
- [Dense Search](https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html)
212+
213+
- [Dense Search](https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html)
211214
- [Sparse Search](https://www.sbert.net/examples/sparse_encoder/applications/semantic_search/README.html)
212215

213216
- **Retrieve & Re-Rank**
217+
214218
- [Dense only Retrieval](https://www.sbert.net/examples/sentence_transformer/applications/retrieve_rerank/README.html)
215219
- [Sparse/Dense/Hybrid Retrieval](https://www.sbert.net/examples/sentence_transformer/applications/retrieve_rerank/README.html)
216220

217221
- [Clustering](https://www.sbert.net/examples/sentence_transformer/applications/clustering/README.html)
222+
218223
- [Paraphrase Mining](https://www.sbert.net/examples/sentence_transformer/applications/paraphrase-mining/README.html)
224+
219225
- [Translated Sentence Mining](https://www.sbert.net/examples/sentence_transformer/applications/parallel-sentence-mining/README.html)
226+
220227
- [Multilingual Image Search, Clustering & Duplicate Detection](https://www.sbert.net/examples/sentence_transformer/applications/image-search/README.html)
221228

222229
and many more use-cases.
223230

224-
For all examples, see [examples/sentence_transformer/applications](https://github.com/UKPLab/sentence-transformers/tree/master/examples/sentence_transformer/applications).
231+
For all examples, see [examples/sentence_transformer/applications](https://github.com/huggingface/sentence-transformers/tree/master/examples/sentence_transformer/applications).
225232

226233
## Development setup
227234

@@ -243,7 +250,7 @@ pytest
243250

244251
If you find this repository helpful, feel free to cite our publication [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084):
245252

246-
```bibtex
253+
```bibtex
247254
@inproceedings{reimers-2019-sentence-bert,
248255
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
249256
author = "Reimers, Nils and Gurevych, Iryna",
@@ -271,10 +278,18 @@ If you use one of the multilingual models, feel free to cite our publication [Ma
271278

272279
Please have a look at [Publications](https://www.sbert.net/docs/publications.html) for our different publications that are integrated into SentenceTransformers.
273280

274-
Maintainer: [Tom Aarsen](https://github.com/tomaarsen), 🤗 Hugging Face
281+
### Maintainers
275282

276-
https://www.ukp.tu-darmstadt.de/
283+
Maintainer: [Tom Aarsen](https://github.com/tomaarsen), 🤗 Hugging Face
277284

278285
Don't hesitate to open an issue if something is broken (and it shouldn't be) or if you have further questions.
279286

287+
---
288+
289+
This project was originally developed by the [Ubiquitous Knowledge Processing (UKP) Lab](https://www.ukp.tu-darmstadt.de/) at TU Darmstadt. We're grateful for their foundational work and continued contributions to the field.
290+
280291
> This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.
292+
293+
[#docs-package]: https://www.sbert.net/
294+
[#github-license]: https://github.com/huggingface/sentence-transformers/blob/master/LICENSE
295+
[#pypi-package]: https://pypi.org/project/sentence-transformers/

docs/_static/js/custom.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ def linkcode_resolve(domain, info):
153153
return None
154154
start, end = lines[1], lines[1] + len(lines[0]) - 1
155155

156-
return f"https://github.com/UKPLab/sentence-transformers/blob/master/{file}#L{start}-L{end}"
156+
return f"https://github.com/huggingface/sentence-transformers/blob/master/{file}#L{start}-L{end}"
157157

158158

159159
def visit_download_reference(self, node):
160-
root = "https://github.com/UKPLab/sentence-transformers/tree/master"
160+
root = "https://github.com/huggingface/sentence-transformers/tree/master"
161161
atts = {"class": "reference download", "download": ""}
162162

163163
if not self.builder.download_support:

docs/cross_encoder/loss_overview.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Loss functions play a critical role in the performance of your fine-tuned Cross
2828
| `(query, [doc1, doc2, ..., docN])` | `[score1, score2, ..., scoreN]` | `1` | <ol style="margin-bottom: 0;line-height: inherit;"><li><a href="../package_reference/cross_encoder/losses.html#lambdaloss">`LambdaLoss`</a></li><li><a href="../package_reference/cross_encoder/losses.html#plistmleloss">`PListMLELoss`</a></li><li><a href="../package_reference/cross_encoder/losses.html#listnetloss">`ListNetLoss`</a></li><li><a href="../package_reference/cross_encoder/losses.html#ranknetloss">`RankNetLoss`</a></li><li><a href="../package_reference/cross_encoder/losses.html#listmleloss">`ListMLELoss`</a></li></ol> |
2929

3030
## Distillation
31+
3132
These loss functions are specifically designed to be used when distilling the knowledge from one model into another.
3233
For example, when finetuning a small model to behave more like a larger & stronger one, or when finetuning a model to become multi-lingual.
3334

@@ -40,12 +41,13 @@ For example, when finetuning a small model to behave more like a larger & strong
4041
| `(query, positive, negative_1, ..., negative_n) ` | `[gold_sim(query, positive), gold_sim(query, negative_i)...] ` | <a href="../package_reference/cross_encoder/losses.html#marginmseloss">`MarginMSELoss`</a> |
4142

4243
## Commonly used Loss Functions
44+
4345
In practice, not all loss functions get used equally often. The most common scenarios are:
4446

45-
* `(sentence_A, sentence_B) pairs` with `float similarity score` or `1 if positive, 0 if negative`: <a href="../package_reference/cross_encoder/losses.html#binarycrossentropyloss"><code>BinaryCrossEntropyLoss</code></a> is a traditional option that remains very challenging to outperform.
46-
* `(anchor, positive) pairs` without any labels: combined with <a href="../package_reference/util.html#sentence_transformers.util.mine_hard_negatives"><code>mine_hard_negatives</code></a>
47-
* with <code>output_format="labeled-list"</code>, then <a href="../package_reference/cross_encoder/losses.html#lambdaloss"><code>LambdaLoss</code></a> is frequently used for learning-to-rank tasks.
48-
* with <code>output_format="labeled-pair"</code>, then <a href="../package_reference/cross_encoder/losses.html#binarycrossentropyloss"><code>BinaryCrossEntropyLoss</code></a> remains a strong option.
47+
- `(sentence_A, sentence_B) pairs` with `float similarity score` or `1 if positive, 0 if negative`: <a href="../package_reference/cross_encoder/losses.html#binarycrossentropyloss"><code>BinaryCrossEntropyLoss</code></a> is a traditional option that remains very challenging to outperform.
48+
- `(anchor, positive) pairs` without any labels: combined with <a href="../package_reference/util.html#sentence_transformers.util.mine_hard_negatives"><code>mine_hard_negatives</code></a>
49+
- with <code>output_format="labeled-list"</code>, then <a href="../package_reference/cross_encoder/losses.html#lambdaloss"><code>LambdaLoss</code></a> is frequently used for learning-to-rank tasks.
50+
- with <code>output_format="labeled-pair"</code>, then <a href="../package_reference/cross_encoder/losses.html#binarycrossentropyloss"><code>BinaryCrossEntropyLoss</code></a> remains a strong option.
4951

5052
## Custom Loss Functions
5153

@@ -62,4 +64,4 @@ To get full support with the automatic model card generation, you may also wish
6264
- a ``citation`` property so your work gets cited in all models that train with the loss.
6365
6466
Consider inspecting existing loss functions to get a feel for how loss functions are commonly implemented.
65-
```
67+
```

0 commit comments

Comments
 (0)