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

feat(#1514): allow ent score None and change default value to 0.0 #1521

Merged
merged 3 commits into from
May 26, 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/client/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ def __entities_to_tuple__(
return [
(ent["label"], ent["start"], ent["end"])
if len(ent) == 3
else (ent["label"], ent["start"], ent["end"], ent["score"] or 1.0)
else (ent["label"], ent["start"], ent["end"], ent["score"] or 0.0)
for ent in entities
]

Expand Down
8 changes: 5 additions & 3 deletions src/rubrix/client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class TokenClassificationRecord(_Validators):
tokens: Optional[Union[List[str], Tuple[str, ...]]] = None

prediction: Optional[
List[Union[Tuple[str, int, int], Tuple[str, int, int, float]]]
List[Union[Tuple[str, int, int], Tuple[str, int, int, Optional[float]]]]
] = None
prediction_agent: Optional[str] = None
annotation: Optional[List[Tuple[str, int, int]]] = None
Expand Down Expand Up @@ -378,14 +378,16 @@ def _normalize_tokens(cls, value):
def add_default_score(
cls,
prediction: Optional[
List[Union[Tuple[str, int, int], Tuple[str, int, int, float]]]
List[Union[Tuple[str, int, int], Tuple[str, int, int, Optional[float]]]]
],
):
"""Adds the default score to the predictions if it is missing"""
if prediction is None:
return prediction
return [
(pred[0], pred[1], pred[2], 1.0) if len(pred) == 3 else pred
(pred[0], pred[1], pred[2], 0.0)
if len(pred) == 3
else (pred[0], pred[1], pred[2], pred[3] or 0.0)
for pred in prediction
]

Expand Down
7 changes: 6 additions & 1 deletion tests/client/sdk/token_classification/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def test_query_schema(helpers):


@pytest.mark.parametrize(
"prediction,expected", [([("label", 0, 4)], 1.0), ([("label", 0, 4, 0.5)], 0.5)]
"prediction,expected",
[
([("label", 0, 4)], 0.0),
([("label", 0, 4, None)], 0.0),
([("label", 0, 4, 0.5)], 0.5),
],
)
def test_from_client_prediction(prediction, expected):
record = TokenClassificationRecord(
Expand Down
7 changes: 4 additions & 3 deletions tests/client/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ def test_token_classification_with_mutation():
"prediction,expected",
[
(None, None),
([("mock", 0, 4)], [("mock", 0, 4, 1.0)]),
([("mock", 0, 4)], [("mock", 0, 4, 0.0)]),
([("mock", 0, 4, 0.5)], [("mock", 0, 4, 0.5)]),
([("mock", 0, 4, None)], [("mock", 0, 4, 0.0)]),
(
[("mock", 0, 4), ("mock", 0, 4, 0.5)],
[("mock", 0, 4, 1.0), ("mock", 0, 4, 0.5)],
[("mock", 0, 4), ("mock", 0, 4, None), ("mock", 0, 4, 0.5)],
[("mock", 0, 4, 0.0), ("mock", 0, 4, 0.0), ("mock", 0, 4, 0.5)],
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_log_record_that_makes_me_cry(mocked_client):
"chars_length": 6,
"density": 0.03225806451612903,
"label": "ENG",
"score": 1.0,
"score": 0.0,
"tokens_length": 1,
"value": "access",
}
Expand Down