首页 > 解决方案 > 使用 nltk 中的 meteor_score 模块评估模型时,如何实现流星分数?

问题描述

我目前有 2 个文件,reference.txt 和 model.txt。这两个文本文件包含原始字幕和训练后生成的字幕。
我可以简单地执行以下操作来获得流星分数:

score = nltk.translate.meteor_score.meteor_score(reference, model)
print(np.mean(meteor_score))

我也看过https://github.com/tylin/coco-caption但我不知道如何实现这一点。

标签: pythonnlpnltkmetrics

解决方案


让我们从定义术语开始

参考:实际文本/基本事实。如果有多个人为同一个数据点生成基本事实,您将有多个参考,并且所有参考都被认为是正确的

假设:候选/预测。

假设这 2 个人看一张图片,他们在标题

  • 这是一个苹果
  • 那是一个苹果

现在您的模型查看图像并预测

  • 这棵树上有一个苹果

您可以计算预测使用效果的meteor_score

print (nltk.translate.meteor_score.meteor_score(
    ["this is an apple", "that is an apple"], "an apple on this tree"))
print (nltk.translate.meteor_score.meteor_score(
    ["this is an apple", "that is an apple"], "a red color fruit"))

输出:

0.6233062330623306
0.0

在您的情况下,您必须阅读reference.txt一个列表并将预测模型类似地建模到另一个列表中。现在你必须得到meteor_score第一个列表中的每一行和第二个列表中的每一行,最后取一个平均值。


推荐阅读