Skip to content

Commit

Permalink
fix(text): predicted ok with unordered labels (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon authored May 4, 2021
1 parent 0d6aaf9 commit e6e17f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rubrix/server/tasks/text_classification/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def predicted(self) -> Optional[PredictionStatus]:
if self.predicted_as and self.annotated_as:
return (
PredictionStatus.OK
if self.predicted_as == self.annotated_as
if set(self.predicted_as) == set(self.annotated_as)
else PredictionStatus.KO
)
return None
Expand Down
21 changes: 21 additions & 0 deletions tests/server/text_classification/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@ def test_created_record_with_default_status():

record = TextClassificationRecord.parse_obj(data)
assert record.status == TaskStatus.default


def test_predicted_ok_for_multilabel_unordered():
record = TextClassificationRecord(
inputs={"text": "The text"},
prediction=TextClassificationAnnotation(
agent="test",
labels=[
ClassPrediction(class_label="B"),
ClassPrediction(class_label="C", score=0.3),
ClassPrediction(class_label="A"),
],
),
annotation=TextClassificationAnnotation(
agent="test",
labels=[ClassPrediction(class_label="A"), ClassPrediction(class_label="B")],
),
multi_label=True,
)

assert record.predicted == PredictionStatus.OK

0 comments on commit e6e17f5

Please sign in to comment.