torcheval.metrics.WordInformationPreserved¶
- class torcheval.metrics.WordInformationPreserved(*, device: device | None = None)¶
计算预测词序列与参考词序列之间保留的单词信息。 其功能版本是
torcheval.metrics.functional.word_information_preserved()。示例
>>> import torch >>> from torcheval.metrics import WordInformationPreserved
>>> metric = WordInformationPreserved() >>> metric.update(["this is the prediction", "there is an other sample"], ["this is the reference", "there is another one"]) >>> metric.compute() tensor(0.3472)
>>> metric = WordInformationPreserved() >>> metric.update(["hello world", "welcome to the facebook"], ["hello metaverse", "welcome to meta"]) >>> metric.compute() tensor(0.3)
- __init__(*, device: device | None = None) None¶
初始化一个度量对象及其内部状态。
使用
self._add_state()来初始化你的度量类的状态变量。 状态变量应该是torch.Tensor,一个torch.Tensor的列表,一个以torch.Tensor为值的字典, 或者一个torch.Tensor的双端队列。
方法
__init__(*[, device])初始化一个度量对象及其内部状态。
compute()返回单词信息保留分数。
load_state_dict(state_dict[, strict])从state_dict加载度量状态变量。
merge_state(metrics)将度量状态与其他度量实例的对应部分合并。
reset()将度量状态变量重置为其默认值。
state_dict()将度量状态变量保存在state_dict中。
to(device, *args, **kwargs)将度量状态变量中的张量移动到设备。
update(input, target)使用correct_total、预测长度和参考长度更新度量状态。
属性
deviceMetric.to()的最后一个输入设备。