次のように、NLTK を使用して 2 つの文字列間の BLEU スコアを計算しようとしています。
from nltk import bleu_score
reference = ['The moon is very bright']
hypothesis = ['Dee']
print('bleu_score.corpus_bleu(reference, hypothesis): {0}'.
format(bleu_score.corpus_bleu(reference, hypothesis)))
実行すると、次のエラーが発生します。
Traceback (most recent call last):
File "C:\Users\Francky\Documents\GitHub\nlp\tests\SEbleu.py", line 28, in <module>
format(bleu_score.corpus_bleu(reference, hypothesis)))
File "C:\Anaconda\lib\site-packages\nltk\translate\bleu_score.py", line 146, in corpus_bleu
p_i = modified_precision(references, hypothesis, i)
File "C:\Anaconda\lib\site-packages\nltk\translate\bleu_score.py", line 287, in modified_precision
return Fraction(numerator, denominator, _normalize=False)
File "C:\Anaconda\lib\site-packages\nltk\compat.py", line 700, in __new__
cls = super(Fraction, cls).__new__(cls, numerator, denominator)
File "C:\Anaconda\lib\fractions.py", line 162, in __new__
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(0, 0)
に置き換えるhypothesis = ['Dee']
とhypothesis = ['Deee']
、エラーメッセージが消えます。なんで?
私のシステム:
- NLTK バージョン: 3.2.1。
- Python 2.7.11 x64