CharacterErrorRate#
- class ignite.metrics.CharacterErrorRate(output_transform=<function CharacterErrorRate.<lambda>>, device=device(type='cpu'), skip_unrolling=False)[source]#
Calculates the Character Error Rate (CER).
CER is defined as the total number of errors (substitutions, deletions, and insertions) at the character level divided by the total number of characters in the reference sequence.
where is the number of substitutions, is the number of deletions, is the number of insertions, is the number of correct characters, and is the total number of characters in the reference ().
updatemust receive input of the form(y_pred, y).y_pred and y both must be either
stror list ofstr.When both inputs are plain
str, they are treated as a single-element batch.
- Parameters:
output_transform (Callable) – a callable that is used to transform the
Engine’sprocess_function’s output into the form expected by the metric.device (str | device) – specifies which device updates are accumulated on. By default, CPU.
skip_unrolling (bool) – specifies whether output should be unrolled before being fed to update method.
Examples
For more information on how metric works with
Engine, visit Attach Engine API.from ignite.metrics.nlp import CharacterErrorRate cer = CharacterErrorRate() y_pred = ["the cat sat on the mat", "hello world"] y = ["the cat sat on mat", "hello world"] cer.update((y_pred, y)) print(round(cer.compute(), 4))
0.1379
New in version 0.5.2.
Methods
Computes the metric based on its accumulated state.
Resets the metric to its initial state.
Updates the metric's state using the passed batch output.
- compute()[source]#
Computes the metric based on its accumulated state.
By default, this is called at the end of each epoch.
- Returns:
- the actual quantity of interest. However, if a
Mappingis returned, it will be (shallow) flattened into engine.state.metrics whencompleted()is called. - Return type:
Any
- Raises:
NotComputableError – raised when the metric cannot be computed.