espnet3.contract.metrics.check_metric_batch
Less than 1 minute
espnet3.contract.metrics.check_metric_batch
espnet3.contract.metrics.check_metric_batch(metric: Any, values: Mapping[str, Any]) → None
Raise unless values is one good batch for metric.update.
values maps each declared input name to a list or tuple with one element per utterance. Checks, in order: no undeclared name; every required name present (an optional one may be absent or None); each value a list or tuple; all lengths equal; every element accepted by its field’s kind (Kind.accepts, no model needed).
- Parameters:
- metric – A
BaseMetricinstance. - values – The keyword arguments given to
update.
- metric – A
- Returns: None.
- Raises:MetricContractError – The batch breaks one of the checks. The message names the input and, for a bad element, its position and the expected kind.
Examples
>>> from espnet3.systems.esp2_asr.metrics.wer import WER
>>> check_metric_batch(WER(), {"ref": ["a b"], "hyp": ["a c"]})
>>> check_metric_batch(WER(), {"ref": ["a b"], "hyp": [3]})
Traceback (most recent call last):
espnet3.contract.metrics.MetricContractError: WER input ...