espnet3.systems.esp2_asr.metrics.cer.CER
espnet3.systems.esp2_asr.metrics.cer.CER
class espnet3.systems.esp2_asr.metrics.cer.CER(clean_types: Iterable[str] | None = None)
Bases: BaseMetric
Compute CER for a dataset.
Reads data["ref"]/data["hyp"], the declared names; the metrics config’s inputs: binds them to a source (see check_metric_inputs).
############# Examples
>>> [f.name for f in CER().inputs]
['ref', 'hyp']Initialize the CER metric.
- Parameters:clean_types – Optional cleaner types passed to TextCleaner.
compute() → Dict[str, float]
Return the CER of everything added so far, from the summed counts.
- Returns:
{"CER": <percentage>}, rounded to 2 places. - Return type: Dict[str, float]
- Raises:ValueError – If the references have no characters.
############# Examples
>>> metric = CER()
>>> metric.update(ref=["abc"], hyp=["axc"])
>>> metric.compute()
{'CER': 33.33}inputs : ClassVar[Tuple[Field, ...]] = (Field(name='ref', kind='text', label='Ref', optional=False, channels=None), Field(name='hyp', kind='text', label='Hyp', optional=False, channels=None))
one Field per SCP input. The name is the key of data (and the default SCP file name); the kind says what the SCP values hold (text: the value itself, audio: a path). A class attribute for a fixed contract; set on self instead, before calling super().__init__(), for one built from the instance’s own configuration.
- Type: What this metric reads
outputs : ClassVar[Tuple[Field, ...]] = (Field(name='CER', kind='number', label='Cer', optional=False, channels=None),)
one Field per key of the result dict, all of kind number. Same class-attribute-or-self choice as inputs.
- Type: What this metric returns
reset() → None
Reset the counts and drop alignment text from an unfinished run.
############# Examples
>>> metric = CER()
>>> metric.reset()update(, ref: Sequence[str], hyp: Sequence[str]) → None
Add the character error counts of one batch to the state.
- Parameters:
- ref – Reference texts, one per utterance.
- hyp – Hypothesis texts, aligned with
ref.
- Raises:RuntimeError – If
jiweris not installed.
############# Examples
>>> metric = CER()
>>> metric.update(ref=["abc"], hyp=["axc"])write_artifacts(test_dir: Path) → None
Write the alignments kept by this __call__ to test_dir/cer_alignment.
The file holds only the rows seen by the __call__ that wrote it, then one summary line from the summed counts; the kept text is cleared afterwards.
- Parameters:test_dir – The test set’s output directory, already created.
############# Examples
>>> metric.write_artifacts(Path("infer/test-clean"))