Skip to content
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