我将两个相同的句子与 RIBES NLTK 进行比较并得到一个错误。为什么?

I compare two identical sentences with RIBES NLTK and get an error. Why?

我正在尝试使用 NLTK 的 RIBES 评分来评估机器翻译的质量。我想用两个相同的句子检查这段代码。但是当我 运行 我的代码出现错误时。

我的代码:

from nltk.translate.ribes_score import sentence_ribes

hyp1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which', 'ensures', 'that', 'the', 'military', 'always', 'obeys', 'the', 'commands', 'of', 'the', 'party']

ref1a = ['It', 'is', 'a', 'guide', 'to', 'action', 'which', 'ensures', 'that', 'the', 'military', 'always', 'obeys', 'the', 'commands', 'of', 'the', 'party']

ribes_score = sentence_ribes(ref1a, hyp1)

print(ribes_score)
 

错误:

Traceback (most recent call last):

  File "D:/Users/anastasia.emelyanova/PycharmProjects/Metrics_NLTK/ribes_test.py", line 4, in <module>

    ribes_score = sentence_ribes(ref1a, hyp1)

  File "D:\Users\anastasia.emelyanova\AppData\Local\Programs\Python\Python38\lib\site-packages\nltk\translate\ribes_score.py", line 55, in sentence_ribes

    nkt = kendall_tau(worder)

  File "D:\Users\anastasia.emelyanova\AppData\Local\Programs\Python\Python38\lib\site-packages\nltk\translate\ribes_score.py", line 290, in kendall_tau

    tau = 2 * num_increasing_pairs / num_possible_pairs - 1

ZeroDivisionError: division by zero


Process finished with exit code 1

为什么我会收到这些错误?我错了吗?我只是拿了两个相同的句子,不应该被零除,因为可能的对数应该大于 1。两个相同的句子应该得到 1.0 分。我正在 Python 3,Windows 7,PyCharm 中编码。请帮忙!

你将在这一行被零除:

tau = 2 * num_increasing_pairs / num_possible_pairs - 1

这是因为当 len(worder) 为 1 时 num_possible_pairs 为 0。所有这些都是因为您使用两个列表调用 sentence_ribes,而第一个参数应该是一个列表列表(句子列表,其中每个句子都是单词列表)。

试着这样称呼它:

ribes_score = sentence_ribes([ref1a], hyp1)