github UKPLab/sentence-transformers v2.5.1
v2.5.1 - fix CrossEncoder.rank bug with default top_k

latest releases: v2.7.0, v2.6.1, v2.6.0...
one month ago

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 #2515
  • [feat] Add get_config_dict to new Matryoshka2dLoss & AdaptiveLayerLoss by @tomaarsen in #2516
  • [chore] Update to ruff 0.3.0; update ruff.toml by @tomaarsen in #2517
  • [example] Don't always normalize the embeddings in clustering example by @tomaarsen in #2520
  • Fix CrossEncoder.rank default value for top_k by @xenova in #2518

New Contributors

Full Changelog: v2.5.0...v2.5.1

Don't miss a new sentence-transformers release

NewReleases is sending notifications on new releases.