espnet3.systems.esp2_cls.metrics.wa.WA
espnet3.systems.esp2_cls.metrics.wa.WA
class espnet3.systems.esp2_cls.metrics.wa.WA
Bases: BaseMetric
Compute weighted accuracy (WA) for a classification dataset.
WA is the fraction of utterances whose predicted label equals the reference label. It is the same quantity espnet2’s cls_score.py reports as mean_acc; the “mean” there averages one shared accuracy value across classes and is a no-op.
Declare it in conf/metrics.yaml:
- metric:
_target_: espnet3.systems.esp2_cls.metrics.wa.WA
inputs:
ref: dataset:label
hyp: hypInitialize the WA metric.
compute() → Dict[str, float]
Return the weighted accuracy of everything added so far.
- Returns:
{"WA": <percentage>}, rounded to 2 places. - Return type: Dict[str, float]
- Raises:ValueError – If no utterance was added.
####### Examples
>>> metric = WA()
>>> metric.update(ref=["joy", "anger"], hyp=["joy", "joy"])
>>> metric.compute()
{'WA': 50.0}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='WA', kind='number', label='Wa', 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 correct and total counts of one batch to the state.
- Parameters:
- ref – Reference labels, one per utterance.
- hyp – Predicted labels, aligned with
ref.
####### Examples
>>> metric = WA()
>>> metric.update(ref=["joy", "anger"], hyp=["joy", "joy"])