Skip to content

CER (Character Error Rate)

API reference for the cer module. For metric and evaluation documentation, see: CER

evaluatio.metrics.cer

Character-level error metrics

This module provides utilities to compute character error rate (CER) and character-level edit distance between reference and hypothesis text sequences.

The functions accept any iterable of strings and internally convert them to a format compatible with the underlying native bindings.

Notes
  • If a reference string is empty, the corresponding CER is defined as inf.
  • These functions are thin wrappers around optimized native implementations.

character_error_rate_per_pair

Compute character error rate (CER) for each reference-hypothesis pair.

Parameters:

Name Type Description Default
references Iterable[str]

Iterable of reference strings.

required
hypotheses Iterable[str]

Iterable of hypothesis strings. Must be the same length as references.

required

Returns:

Type Description
List[float]

Character error rate for each pair of reference and hypothesis.

Raises:

Type Description
ValueError

If the lists are of different lengths.

See Also

metrics.uer.universal_error_rate_per_pair : Type-agnostic version.

Notes
  • If a reference string is empty or contains no characters, the resulting CER is inf.

character_edit_distance_per_pair

Compute character-level edit distance for each reference-hypothesis pair.

Parameters:

Name Type Description Default
references Iterable[str]

Iterable of reference strings.

required
hypotheses Iterable[str]

Iterable of hypothesis strings. Must be the same length as references.

required

Returns:

Type Description
List[int]

character-level edit distance for each pair.

character_error_rate

Compute the corpus level character error rate (CER) over all pairs.

Parameters:

Name Type Description Default
references Iterable[str]

Iterable of reference strings.

required
hypotheses Iterable[str]

Iterable of hypothesis strings. Must be the same length as references.

required

Returns:

Type Description
float

Corpus level character error rate across all pairs.

Notes
  • Equivalent to common CER implementations (e.g., jiwer-based metrics).
  • If all reference strings are empty, the resulting CER is inf.

character_error_rate_ci

Estimate a confidence interval for the character error rate via bootstrapping.

Parameters:

Name Type Description Default
references Iterable[str]

Iterable of reference strings.

required
hypotheses Iterable[str]

Iterable of hypothesis strings. Must be the same length as references.

required
iterations int

Number of bootstrap iterations.

required
alpha float

Significance level for the confidence interval.

required

Returns:

Type Description
ConfidenceInterval

Estimated confidence interval for the corpus level character error rate.

Notes
  • The bootstrapped metric corresponds to character_error_rate.
  • If any reference string is empty or contains no characters, the resulting CER can be inf.