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

fix(#1527): check agents instead labels for predicted computation #1528

Merged
merged 3 commits into from Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rubrix/server/apis/v0/models/text_classification.py
Expand Up @@ -297,7 +297,7 @@ def task(cls) -> TaskType:

@property
def predicted(self) -> Optional[PredictionStatus]:
if self.predicted_as and self.annotated_as:
if self.predicted_by and self.annotated_by:
return (
PredictionStatus.OK
if set(self.predicted_as) == set(self.annotated_as)
Expand Down
31 changes: 31 additions & 0 deletions tests/server/text_classification/test_model.py
Expand Up @@ -337,3 +337,34 @@ def test_query_with_uncovered_by_rules():
},
}
}


def test_empty_labels_for_no_multilabel():
with pytest.raises(
ValidationError,
match="Single label record must include only one annotation label",
):
TextClassificationRecord(
inputs={"text": "The input text"},
annotation=TextClassificationAnnotation(agent="ann.", labels=[]),
)

record = TextClassificationRecord(
inputs={"text": "The input text"},
prediction=TextClassificationAnnotation(agent="ann.", labels=[]),
annotation=TextClassificationAnnotation(
agent="ann.", labels=[ClassPrediction(class_label="B")]
),
)
assert record.predicted == PredictionStatus.KO


def test_annotated_without_labels_for_multilabel():
record = TextClassificationRecord(
inputs={"text": "The input text"},
multi_label=True,
prediction=TextClassificationAnnotation(agent="pred.", labels=[]),
annotation=TextClassificationAnnotation(agent="ann.", labels=[]),
)

assert record.predicted == PredictionStatus.OK
17 changes: 17 additions & 0 deletions tests/server/token_classification/test_model.py
Expand Up @@ -17,6 +17,7 @@
from pydantic import ValidationError

from rubrix._constants import MAX_KEYWORD_LENGTH
from rubrix.server.apis.v0.models.commons.model import PredictionStatus
from rubrix.server.apis.v0.models.token_classification import (
EntitySpan,
TokenClassificationAnnotation,
Expand Down Expand Up @@ -220,3 +221,19 @@ def test_record_scores():
),
)
assert record.scores == [0.8, 0.1, 0.2]


def test_annotated_without_entities():
text = "The text that i wrote"
record = TokenClassificationRecord(
text=text,
tokens=text.split(),
prediction=TokenClassificationAnnotation(
agent="pred.test", entities=[EntitySpan(start=0, end=3, label="DET")]
),
annotation=TokenClassificationAnnotation(agent="test", entities=[]),
)

assert record.annotated_by == [record.annotation.agent]
assert record.predicted_by == [record.prediction.agent]
assert record.predicted == PredictionStatus.KO