Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
baskrahmer committed Jul 19, 2024
1 parent 844240d commit b522ae5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/unittests/text/test_bertscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ def test_bertscore_differentiability(
metric_args=metric_args,
key=metric_key,
)


@skip_on_connection_issues()
@pytest.mark.skipif(not _TRANSFORMERS_GREATER_EQUAL_4_4, reason="test requires transformers>4.4")
@pytest.mark.parametrize(
"idf",
[(False,), (True,)],
)
def test_bertscore_sorting(idf: bool):
"""Test that BERTScore is invariant to the order of the inputs."""
short = "Short text"
long = "This is a longer text"

preds = [long, long]
targets = [long, short]

metric = BERTScore(idf=idf)
score = metric(preds, targets)

# First index should be the self-comparison - sorting by length should not shuffle this
assert score["f1"][0] > score["f1"][1]

0 comments on commit b522ae5

Please sign in to comment.