快捷方式

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

参数:
  • input – 要评分的翻译。

  • target – 每个翻译的参考列表。要求 len(input) = len(target)

  • n_gram – 计算 BLEU 分数时使用的最大 n 元语法。可以是 1、2、3 或 4。

  • weights – n 元语法的可选权重分布。要求 len(weights) = n_gram。如果未指定,将使用统一权重。

  • 示例

    >>> 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)
    

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并获得问题的解答

查看资源