开始使用免费开始使用

评估预训练文本生成模型

PyBooks 团队使用了您之前试验过的预训练 GPT-2 模型,根据给定提示生成了文本。现在,他们希望评估该生成文本的质量。为此,他们委托您使用一段参考文本来评估生成文本。

BLEUScoreROUGEScore 已为您加载。

本练习是课程的一部分

使用 PyTorch 的文本深度学习

查看课程

练习说明

  • 先从 torchmetrics.text 初始化提供的两个指标(BLEU 和 ROUGE)。
  • 使用这些已初始化的指标来计算生成文本与参考文本之间的分数。
  • 显示计算得到的 BLEU 和 ROUGE 分数。

交互式实操练习

通过完成这段示例代码来试试这个练习。

reference_text = "Once upon a time, there was a little girl who lived in a village near the forest."
generated_text = "Once upon a time, the world was a place of great beauty and great danger. The world of the gods was the place where the great gods were born, and where they were to live."

# Initialize BLEU and ROUGE scorers
bleu = ____()
rouge = ____()

# Calculate the BLEU and ROUGE scores
bleu_score = bleu([____], [[reference_text]])
rouge_score = rouge([generated_text], [[____]])

# Print the BLEU and ROUGE scores
print("BLEU Score:", bleu_score.____())
print("ROUGE Score:", rouge_score)
编辑并运行代码