Skip to content

Ensure consistentcy between labels and probabilities #599

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/setfit/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ def predict_proba(
probs = torch.stack(probs, axis=1)
else:
probs = np.stack(probs, axis=1)
if list(self.labels) != list(self.model_head.classes_):
# If the user has specified labels when instantiating the model, we have to take into account
# the possibility of the model head having reordered the labels.
head_labels = list(self.model_head.classes_)
user_labels = list(self.labels)
reorder_map = np.array([head_labels.index(label) for label in user_labels])
probs = probs[:, reorder_map]
outputs = self._output_type_conversion(probs, as_numpy=as_numpy)
return outputs[0] if is_singular else outputs

Expand Down