Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

evaluatio.metrics.chrf

ChrF metric wrappers providing bootstrap confidence intervals and permutation tests.

This module provides thin wrappers around :class:sacrebleu.CHRF that add statistical inference capabilities: bootstrap confidence intervals (:func:chrf_ci) and paired permutation significance tests (:func:chrf_permutation_test).

Both functions operate at the corpus level but delegate the underlying ChrF arithmetic entirely to sacrebleu, ensuring scoring is identical to the reference implementation.

Note

Sentence-level scores used in :func:chrf_permutation_test are obtained via sacrebleu.CHRF.sentence_score; corpus-level scores and statistics used in :func:chrf_ci are obtained via the internal _extract_corpus_statistics and _compute_score_from_stats helpers, which may change across sacrebleu versions.

Functions

chrf_ci

chrf_ci(references: Iterable[Iterable[str]], hypotheses: Sequence[str], iterations: int, alpha: float, chrf: sacrebleu.CHRF | None=None, seed: int=0) -> ConfidenceInterval

Compute a bootstrap confidence interval for corpus ChrF score.

Draws iterations bootstrap resamples (with replacement) from the per-sentence sufficient statistics, recomputes the corpus ChrF score for each resample, and returns the percentile-based confidence interval.

Parameters

Returns

Raises

Examples

>>> ci = chrf_ci([["the cat sat"]], ["the cat sat"])
>>> ci.score
100.0

chrf_permutation_test

chrf_permutation_test(references: Iterable[Iterable[str]], hypotheses1: Sequence[str], hypotheses2: Sequence[str], iterations: int, two_tailed: bool=True, chrf: sacrebleu.CHRF | None=None) -> float

Run a paired approximate permutation test comparing two sets of hypotheses.

For each sentence the ChrF score is computed independently for each hypothesis set. The resulting paired score vectors are passed to :func:~evaluatio.inference.hypothesis.paired_permutation_test, which estimates the probability that the observed difference in means (or its absolute value, when two_tailed=True) could arise by chance under the null hypothesis that the two systems are equivalent.

Parameters

Returns

Raises

Examples

>>> p = chrf_permutation_test(
...     [["the cat sat", "a dog ran"]],
...     ["the cat sat", "a dog ran"],
...     ["a cat sat", "the dog ran"],
... )
>>> 0.0 <= p <= 1.0
True