Spaces:
Configuration error
Configuration error
File size: 1,302 Bytes
3a2e5f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | """Smoke tests for the BLEU evaluator.
We don't validate sacrebleu's correctness here — that's its own test suite.
We *do* validate our adapter: parallel-list shape handling, ragged references,
and that perfect predictions score 100.
"""
from __future__ import annotations
import pytest
sacrebleu = pytest.importorskip("sacrebleu")
from captioning.evaluation.bleu import corpus_bleu_score # noqa: E402
def test_perfect_predictions_score_100() -> None:
refs = [["a man riding a bike"], ["a dog in the park"]]
preds = ["a man riding a bike", "a dog in the park"]
assert corpus_bleu_score(preds, refs) == pytest.approx(100.0)
def test_completely_wrong_predictions_score_low() -> None:
refs = [["a man riding a bike"], ["a dog in the park"]]
preds = ["xyz qrs", "abc def"]
score = corpus_bleu_score(preds, refs)
assert 0.0 <= score < 5.0
def test_ragged_references_supported() -> None:
refs = [
["a man riding a bike", "a person on a bicycle", "someone biking"],
["a dog in the park"],
]
preds = ["a man riding a bike", "a dog in the park"]
score = corpus_bleu_score(preds, refs)
assert score > 50.0
def test_length_mismatch_raises() -> None:
with pytest.raises(ValueError):
corpus_bleu_score(["a", "b"], [["a"]])
|