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、predicted length 和 reference length 更新度量状态。
属性
device
Metric.to()
的最后一个输入设备。