Shortcuts

Char Error Rate

Module Interface

class torchmetrics.CharErrorRate(compute_on_step=None, **kwargs)[source]

Character Error Rate (CER) is a metric of the performance of an automatic speech recognition (ASR) system.

This value indicates the percentage of characters that were incorrectly predicted. The lower the value, the better the performance of the ASR system with a CharErrorRate of 0 being a perfect score. Character error rate can then be computed as:

CharErrorRate = \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 characters,

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

Compute CharErrorRate score of transcribed segments against references.

Parameters
  • compute_on_step (Optional[bool]) –

    Forward only calls update() and returns None if this is set to False.

    Deprecated since version v0.8: Argument has no use anymore and will be removed v0.9.

  • kwargs (Dict[str, Any]) – Additional keyword arguments, see Advanced metric settings for more info.

Returns

Character error rate score

Examples

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

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

compute()[source]

Calculate the character error rate.

Return type

Tensor

Returns

Character error rate score

update(preds, target)[source]

Store references/predictions for computing Character 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.char_error_rate(preds, target)[source]

character error rate is a common metric of the performance of an automatic speech recognition system. This value indicates the percentage of characters that were incorrectly predicted. The lower the value, the better the performance of the ASR system with a CER 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

Character error rate score

Examples

>>> preds = ["this is the prediction", "there is an other sample"]
>>> target = ["this is the reference", "there is another one"]
>>> char_error_rate(preds=preds, target=target)
tensor(0.3415)
Read the Docs v: v0.8.1
Versions
latest
stable
v0.8.1
v0.8.0
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.2
v0.6.1
v0.6.0
v0.5.1
v0.5.0
v0.4.1
v0.4.0
v0.3.2
v0.3.1
v0.3.0
v0.2.0
v0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.