torcheval.metrics.functional.bleu_score¶
- torcheval.metrics.functional.bleu_score(input: str | Sequence[str], target: Sequence[str | Sequence[str]], n_gram: int = 4, weights: Tensor | None = None, device: device | None = None) Tensor¶
计算给定翻译和每个翻译的参考的BLEU分数。 其类版本是
torcheval.metrics.texBLEUScore。- Parameters:
input – 需要评分的翻译。
target – 每个翻译的参考列表。要求 len(input) = len(target)
n_gram – 计算BLEU分数时使用的最大n-gram。可以是1、2、3或4。
weights – 可选的n-grams权重分布。要求len(weights) = n_gram。如果未指定,将使用均匀权重。
Examples –
>>> import torch >>> from torcheval.metrics.functional.text import bleu >>> candidates = ["the squirrel is eating the nut"] >>> references = [["a squirrel is eating a nut", "the squirrel is eating a tasty nut"]] >>> bleu_score(candidates, references, n_gram=4) tensor(0.53728497) >>> candidates = ["the squirrel is eating the nut", "the cat is on the mat"] >>> references = [["a squirrel is eating a nut", "the squirrel is eating a tasty nut"], ["there is a cat on the mat", "a cat is on the mat"]] >>> bleu_score(candidates, references, n_gram=4) tensor(0.65341892)