hezar.metrics.wer module

class hezar.metrics.wer.WER(config: WERConfig, **kwargs)[source]

Bases: Metric

WER metric for evaluating Word Error Rate using jiwer.

Parameters:
  • config (WERConfig) – Metric configuration object.

  • **kwargs – Extra configuration parameters passed as kwargs to update the config.

compute(predictions=None, targets=None, concatenate_texts=None, n_decimals=None, output_keys=None, **kwargs)[source]

Computes the WER for the given predictions against targets.

Parameters:
  • predictions – Predicted texts.

  • targets – Ground truth texts.

  • concatenate_texts (bool) – Flag to indicate whether to concatenate texts before WER calculation.

  • n_decimals (int) – Number of decimals for the final score.

  • output_keys (tuple) – Filter the output keys.

Returns:

A dictionary of the metric results, with keys specified by output_keys.

Return type:

dict

required_backends: List[str | Backends] = [Backends.JIWER]
class hezar.metrics.wer.WERConfig(objective: str = 'minimize', output_keys: tuple = ('wer',), n_decimals: int = 4, concatenate_texts: bool = False)[source]

Bases: MetricConfig

Configuration class for WER metric.

Parameters:
  • name (MetricType) – The type of metric, WER in this case.

  • concatenate_texts (bool) – Flag to indicate whether to concatenate texts before WER calculation.

  • output_keys (tuple) – Keys to filter the metric results for output.

concatenate_texts: bool = False
name: str = 'wer'
objective: str = 'minimize'
output_keys: tuple = ('wer',)