Shortcuts

Word Error Rate

Module Interface

class torchmetrics.WordErrorRate(**kwargs)[source]

Word error rate (WordErrorRate) is a common metric of the performance of an automatic speech recognition system. This value indicates the percentage of words that were incorrectly predicted. The lower the value, the better the performance of the ASR system with a WER of 0 being a perfect score. Word error rate can then be computed as:

WER = \frac{S + D + I}{N} = \frac{S + D + I}{S + D + C}

where:
  • S is the number of substitutions,

  • D is the number of deletions,

  • I is the number of insertions,

  • C is the number of correct words,

  • N is the number of words in the reference (N=S+D+C).

Compute WER score of transcribed segments against references.

Parameters

kwargs (Any) – Additional keyword arguments, see Advanced metric settings for more info.

Returns

Word error rate score

Examples

>>> preds = ["this is the prediction", "there is an other sample"]
>>> target = ["this is the reference", "there is another one"]
>>> metric = WordErrorRate()
>>> metric(preds, target)
tensor(0.5000)

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute()[source]

Calculate the word error rate.

Return type

Tensor

Returns

Word error rate score

update(preds, target)[source]

Store references/predictions for computing Word Error Rate scores.

Parameters
  • preds (Union[str, List[str]]) – Transcription(s) to score as a string or list of strings

  • target (Union[str, List[str]]) – Reference(s) for each speech input as a string or list of strings

Return type

None

Functional Interface

torchmetrics.functional.word_error_rate(preds, target)[source]

Word error rate (WordErrorRate) is a common metric of the performance of an automatic speech recognition system. This value indicates the percentage of words that were incorrectly predicted. The lower the value, the better the performance of the ASR system with a WER of 0 being a perfect score.

Parameters
  • preds (Union[str, List[str]]) – Transcription(s) to score as a string or list of strings

  • target (Union[str, List[str]]) – Reference(s) for each speech input as a string or list of strings

Return type

Tensor

Returns

Word error rate score

Examples

>>> preds = ["this is the prediction", "there is an other sample"]
>>> target = ["this is the reference", "there is another one"]
>>> word_error_rate(preds=preds, target=target)
tensor(0.5000)