Skip to content

Commit

Permalink
raises ValueError when num_label !=1 when using Crossencoder.rank() (#…
Browse files Browse the repository at this point in the history
…3126)

* raises value error when num_label > 1 when using Crossencoder.rank()

* updated error message
  • Loading branch information
JINO-ROHIT authored Dec 12, 2024
1 parent fa23d4d commit afdf692
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sentence_transformers/cross_encoder/CrossEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ def rank(
'score': -5.082967,
'text': "The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era."}]
"""
if self.config.num_labels != 1:
raise ValueError(
"CrossEncoder.rank() only works for models with num_labels=1. "
"Consider using CrossEncoder.predict() with input pairs instead."
)
query_doc_pairs = [[query, doc] for doc in documents]
scores = self.predict(
sentences=query_doc_pairs,
Expand Down

0 comments on commit afdf692

Please sign in to comment.