torcheval.metrics.WordErrorRate¶
- class torcheval.metrics.WordErrorRate(*, device: device | None = None)¶
Compute the word error rate of the predicted word sequence(s) with the reference word sequence(s). Its functional version is
torcheval.metrics.functional.word_error_rate().Examples
>>> import torch >>> from torcheval.metrics import WordErrorRate
>>> metric = WordErrorRate() >>> metric.update(["this is the prediction", "there is an other sample"], ["this is the reference", "there is another one"]) >>> metric.compute() tensor(0.5)
>>> metric = WordErrorRate() >>> metric.update(["this is the prediction", "there is an other sample"], ["this is the reference", "there is another one"]) >>> metric.update(["hello world", "welcome to the facebook"], ["hello metaverse", "welcome to meta"]) >>> metric.compute() tensor(0.53846)
- __init__(*, device: device | None = None) None¶
Initialize a metric object and its internal states.
Use
self._add_state()to initialize state variables of your metric class. The state variables should be eithertorch.Tensor, a list oftorch.Tensor, a dictionary withtorch.Tensoras values, or a deque oftorch.Tensor.
Methods
__init__(*[, device])Initialize a metric object and its internal states.
compute()Return the word error rate score
load_state_dict(state_dict[, strict])Loads metric state variables from state_dict.
merge_state(metrics)Merge the metric state with its counterparts from other metric instances.
reset()Reset the metric state variables to their default value.
state_dict()Save metric state variables in state_dict.
to(device, *args, **kwargs)Move tensors in metric state variables to device.
update(input, target)Update the metric state with edit distance and the length of the reference sequence.
Attributes
deviceThe last input device of
Metric.to().