Skip to content

Commit

Permalink
fix: 'MajorityVoter.score' when using multi-labels (#1678)
Browse files Browse the repository at this point in the history
Fixes the issue mentioned in #1628.
Now the MajorityVoter.score works for multi-label cases with a number of labels > 2.

(cherry picked from commit 1c11c10)
  • Loading branch information
David Fidalgo authored and frascuchon committed Sep 29, 2022
1 parent 4273388 commit 0b94c86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/rubrix/labeling/text_classification/label_models.py
Expand Up @@ -375,6 +375,7 @@ def score(
probabilities = self._compute_multi_label_probs(wl_matrix)

annotation, prediction = self._score_multi_label(probabilities)
target_names = self._weak_labels.labels
else:
if isinstance(tie_break_policy, str):
tie_break_policy = TieBreakPolicy(tie_break_policy)
Expand All @@ -384,11 +385,12 @@ def score(
annotation, prediction = self._score_single_label(
probabilities, tie_break_policy
)
target_names = self._weak_labels.labels[: annotation.max() + 1]

return classification_report(
annotation,
prediction,
target_names=self._weak_labels.labels[: annotation.max() + 1],
target_names=target_names,
output_dict=not output_str,
)

Expand Down
7 changes: 4 additions & 3 deletions tests/labeling/text_classification/test_label_models.py
Expand Up @@ -320,9 +320,10 @@ def score(self, probabilities, tie_break_policy=None):
assert probabilities is None
if wls == "weak_labels":
assert tie_break_policy == TieBreakPolicy.ABSTAIN
else:
assert tie_break_policy is None
return np.array([[1, 1], [0, 0]]), np.array([[1, 1], [1, 0]])
return np.array([1, 0]), np.array([1, 1])

assert tie_break_policy is None
return np.array([[1, 1, 1], [0, 0, 0]]), np.array([[1, 1, 1], [1, 0, 0]])

single_or_multi = "multi" if wls == "weak_multi_labels" else "single"
monkeypatch.setattr(
Expand Down

0 comments on commit 0b94c86

Please sign in to comment.