v2.5.1
版本发布时间: 2024-03-01 16:18:33
UKPLab/sentence-transformers最新发布版本:v3.0.1(2024-06-07 21:01:30)
This is a patch release to fix a bug in CrossEncoder.rank
that caused the last value to be discarded when using the default top_k=-1
.
CrossEncoder.rank
patch:
from sentence_transformers.cross_encoder import CrossEncoder
# Pre-trained cross encoder
model = CrossEncoder("cross-encoder/stsb-distilroberta-base")
# We want to compute the similarity between the query sentence
query = "A man is eating pasta."
# With all sentences in the corpus
corpus = [
"A man is eating food.",
"A man is eating a piece of bread.",
"The girl is carrying a baby.",
"A man is riding a horse.",
"A woman is playing violin.",
"Two men pushed carts through the woods.",
"A man is riding a white horse on an enclosed ground.",
"A monkey is playing drums.",
"A cheetah is running behind its prey.",
]
# We rank all sentences in the corpus for the query
ranks = model.rank(query, corpus)
# Print the scores
print("Query:", query)
for rank in ranks:
print(f"{rank['score']:.2f}\t{corpus[rank['corpus_id']]}")
Query: A man is eating pasta.
0.67 A man is eating food.
0.34 A man is eating a piece of bread.
0.08 A man is riding a horse.
0.07 A man is riding a white horse on an enclosed ground.
0.01 The girl is carrying a baby.
0.01 Two men pushed carts through the woods.
0.01 A monkey is playing drums.
0.01 A woman is playing violin.
0.01 A cheetah is running behind its prey.
Previously, the lowest score document would be removed from the output.
All changes
- [
examples
] Update model repo_id in 2dMatryoshka example by @tomaarsen in https://github.com/UKPLab/sentence-transformers/pull/2515 - [
feat
] Add get_config_dict to new Matryoshka2dLoss & AdaptiveLayerLoss by @tomaarsen in https://github.com/UKPLab/sentence-transformers/pull/2516 - [
chore
] Update to ruff 0.3.0; update ruff.toml by @tomaarsen in https://github.com/UKPLab/sentence-transformers/pull/2517 - [
example
] Don't always normalize the embeddings in clustering example by @tomaarsen in https://github.com/UKPLab/sentence-transformers/pull/2520 - Fix CrossEncoder.rank default value for
top_k
by @xenova in https://github.com/UKPLab/sentence-transformers/pull/2518
New Contributors
- @xenova made their first contribution in https://github.com/UKPLab/sentence-transformers/pull/2518
Full Changelog: https://github.com/UKPLab/sentence-transformers/compare/v2.5.0...v2.5.1