espnet3.systems.esp2_lid.metrics.accuracy.Accuracy
espnet3.systems.esp2_lid.metrics.accuracy.Accuracy
class espnet3.systems.esp2_lid.metrics.accuracy.Accuracy
Bases: BaseMetric
Compute accuracy over utterances and average recall over languages.
MicroAccuracy counts every utterance once; MacroAccuracy averages the accuracy of each language in the references, so small languages weigh as much as large ones.
Examples
>>> metric = Accuracy()
>>> metric.update(ref=["eng", "eng", "fra"], hyp=["eng", "fra", "fra"])
>>> metric.compute()
{'MicroAccuracy': 66.67, 'MacroAccuracy': 75.0}Register the per-language counts.
compute() → Dict[str, float]
Return micro and macro accuracy percentages, rounded to two decimals.
- Raises:ValueError – If no prediction was added.
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='MicroAccuracy', kind='number', label='Microaccuracy', optional=False, channels=None), Field(name='MacroAccuracy', kind='number', label='Macroaccuracy', 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
update(, ref: Sequence[str], hyp: Sequence[str]) → None
Add the utterance and correct counts of one batch, per language.
- Parameters:
- ref – Reference language codes, one per utterance.
- hyp – Predicted language codes, aligned with
ref.
- Raises:ValueError – If a label is empty.
