Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raises ValueError when num_label !=1 when using Crossencoder.rank() #3126

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentence_transformers/cross_encoder/CrossEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ 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.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
What do you think, should we maybe also refer people to CrossEncoder.predict()?
Something like:

Suggested change
raise ValueError("CrossEncoder.rank() only works for models with num_labels=1.")
raise ValueError(
"CrossEncoder.rank() only works for models with num_labels=1. "
"Consider using CrossEncoder.predict() with input pairs instead."
)

Otherwise people might just stop using Sentence Transformers altogether when CrossEncoder.rank fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

query_doc_pairs = [[query, doc] for doc in documents]
scores = self.predict(
sentences=query_doc_pairs,
Expand Down
Loading