hezar.metrics.cer module

class hezar.metrics.cer.CER(config: CERConfig, **kwargs)[source]

Bases: Metric

CER metric for evaluating Character Error Rate using jiwer.

Parameters:
  • config (CERConfig) – 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 Character Error Rate (CER) for the given predictions against targets.

Parameters:
  • predictions – Predicted texts.

  • targets – Ground truth texts.

  • concatenate_texts (bool) – Flag to concatenate texts before computing CER.

  • 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.cer.CERConfig(objective: str = 'minimize', output_keys: tuple = ('cer',), n_decimals: int = 4, sentence_delimiter: str = ' ', concatenate_texts: bool = False)[source]

Bases: MetricConfig

Configuration class for CER (Character Error Rate) metric.

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

  • sentence_delimiter (str) – Delimiter for separating sentences in texts.

  • concatenate_texts (bool) – Flag to concatenate texts before computing CER.

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

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