espnet3.components.metrics.base_metric.BaseMetric
Less than 1 minute
espnet3.components.metrics.base_metric.BaseMetric
class espnet3.components.metrics.base_metric.BaseMetric
Bases: ABC
Base class for metrics that consume inference output paths.
iter_inputs(data: Dict[str, Path], *keys: str) → Iterator[Tuple[str, Dict[str, str]]]
Yield rows from one or more SCP inputs with shared utterance IDs.
This helper reads one or more SCP files in lockstep. For a single key, it behaves as a streaming SCP iterator that returns (utt_id, row) pairs. For multiple keys, it additionally validates that all files contain the same utterance IDs in the same order. It is intended for metrics that want a single streaming API regardless of how many input files they consume.
- Parameters:
- data (Dict *[*str , Path ]) – Mapping from input aliases to SCP paths.
- *keys (str) – Input aliases to read together, e.g.
("ref",)or("ref", "hyp").
- Yields:Iterator[Tuple[str, Dict[str, str]]] – Tuples of
(utt_id, row), whererowis an alias -> value mapping for that utterance.( "utt1", {"ref": "the cat", "hyp": "the bat"}, ) - Raises:AssertionError – If no keys are provided, if one file has more entries than another, or if utterance IDs do not match across files.
Example
>>> for utt_id, row in self.iter_inputs(data, "ref", "hyp"):
... print(utt_id, row["ref"], row["hyp"])
utt1 the cat the bat
utt2 a dog a dog>>> for utt_id, row in self.iter_inputs(data, "ref"):
... print(utt_id, row["ref"])
utt1 the cat
utt2 a dogNotes
- Alignment is checked in file order.
- This helper does not sort utterance IDs.
- Each input is expected to be in SCP format:
utt1 value utt2 another value
