1

機械翻訳の品質評価に NLTK の BLEU スコアを使用しようとしています。このコードを 2 つの同一の文でチェックしたかったのですが、コーパスではなく 2 つの文を比較しているため、ここでは method1 を平滑化関数として使用しています。4 グラムと重み 0.25 (1/4) を設定します。しかし、結果として、0.0088308 を取得しています。私は何を間違っていますか?2 つの同一の文は、スコア 1.0 を取得する必要があります。PyCharm の Python 3、Windows 7 でコーディングしています。

私のコード:

import nltk
from nltk import word_tokenize
from nltk.translate.bleu_score import SmoothingFunction
ref = 'You know that it would be untrue You know that I would be a liar If I was to say to you Girl, we couldnt get much higher.'
cand = 'You know that it would be untrue You know that I would be a liar If I was to say to you Girl, we couldnt get much higher.'
smoothie = SmoothingFunction().method1
reference = word_tokenize(ref)
candidate = word_tokenize(cand)
weights = (0.25, 0.25, 0.25, 0.25)
BLEUscore = nltk.translate.bleu_score.sentence_bleu(reference, candidate, weights, smoothing_function=smoothie)
print(BLEUscore)

私の結果:

0.008830895300928163

プロセスは終了コード 0 で終了しました

4

1 に答える 1

0

BLEU では、参考文献のセットを候補と比較することができます。使用する場合は、文のリストのリストを参考文献のリストとして設定する必要があります。つまり、参照を 1 つだけ取得したとしても、それはリストのリストである必要があります (私の例では、参照は [参照] である必要があります:

BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], candidate, weights, smoothing_function=smoothie)

[] に参照を入れると、1.0 になります。

于 2021-08-26T12:06:14.023 に答える