espnet3.systems.esp2_lid.metrics.classification_report.ClassificationReport
espnet3.systems.esp2_lid.metrics.classification_report.ClassificationReport
class espnet3.systems.esp2_lid.metrics.classification_report.ClassificationReport
Bases: BaseMetric
Compute macro precision/recall/F1 and write per-language reports.
Macro averages run over the languages in the references, as in ESPnet2 LID scoring; a predicted language that no reference has is counted only as a false positive. With one language per utterance, micro precision, recall and F1 all equal Accuracy’s MicroAccuracy, so they are not reported again here.
Examples
>>> metric = ClassificationReport()
>>> metric.update(ref=["eng", "eng", "fra"], hyp=["eng", "fra", "fra"])
>>> metric.compute()
{'MacroPrecision': 75.0, 'MacroRecall': 75.0, 'MacroF1': 66.67}Register the counts of reference/prediction pairs.
compute() → Dict[str, float]
Return macro-averaged 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='MacroPrecision', kind='number', label='Macroprecision', optional=False, channels=None), Field(name='MacroRecall', kind='number', label='Macrorecall', optional=False, channels=None), Field(name='MacroF1', kind='number', label='Macrof1', 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 reference/prediction pair counts of one batch.
- Parameters:
- ref – Reference language codes, one per utterance.
- hyp – Predicted language codes, aligned with
ref.
- Raises:ValueError – If a label is empty.
write_artifacts(test_dir: Path) → None
Write lid_per_language.json and lid_error_counts.json.
The first holds each reference language’s counts and percentages, the second each confusion such as "deu->eng" with its count, most frequent first. Re-running replaces both.
- Parameters:test_dir – The test set’s output directory, already created.
