ChrF (Character F-Score)¶
API reference for the chrf module. For metric and evaluation documentation, see: ChrF
evaluatio.metrics.chrf
¶
ChrF metric wrappers providing bootstrap confidence intervals and permutation tests.
This module provides thin wrappers around sacrebleu.CHRF that add
statistical inference capabilities: bootstrap confidence intervals
(chrf_ci) and paired permutation significance tests
(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.
Notes
Sentence-level scores used in chrf_permutation_test are obtained via
sacrebleu.CHRF.sentence_score; corpus-level scores and statistics used in
chrf_ci are obtained via the internal _extract_corpus_statistics
and _compute_score_from_stats helpers, which may change across sacrebleu
versions.
chrf_ci ¶
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:
| Name | Type | Description | Default |
|---|---|---|---|
references
|
Iterable[Iterable[str]]
|
Reference translations. Each element is an iterable of strings
representing row in a test set. Has to be the same length as |
required |
hypotheses
|
Sequence[str]
|
Model hypotheses, one string per sentence. |
required |
iterations
|
int
|
Number of bootstrap resamples. Default is |
required |
alpha
|
float
|
Significance level. The returned interval covers
|
required |
chrf
|
CHRF or None
|
A pre-configured :class: |
None
|
seed
|
int
|
Seed for the NumPy random number generator used during resampling,
ensuring reproducibility. Default is |
0
|
Returns:
| Type | Description |
|---|---|
ConfidenceInterval
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the reference sets do not all have the same number of sentences. |
Examples:
chrf_permutation_test ¶
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
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:
| Name | Type | Description | Default |
|---|---|---|---|
references
|
Iterable[Iterable[str]]
|
Reference translations. Each element is an iterable of strings representing one reference set. All reference sets must contain one string per sentence and have the same length as the hypothesis sequences. |
required |
hypotheses1
|
Sequence[str]
|
Hypothesis strings for system 1, one per sentence. |
required |
hypotheses2
|
Sequence[str]
|
Hypothesis strings for system 2, one per sentence. |
required |
iterations
|
int
|
Number of permutation iterations. |
required |
two_tailed
|
bool
|
If |
True
|
chrf
|
CHRF or None
|
A pre-configured |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Estimated p-value. Small values (e.g. < 0.05) indicate that the observed score difference is unlikely under the null hypothesis. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the reference sets do not all have the same number of sentences. |
Examples: