Запуск NLTK remace_bleu в Пандах
Я пытаюсь применить предложение_блок к столбцу в Пандас, чтобы оценить качество некоторых машинных переводов. Но результаты, которые он выводит, неверны. Кто-нибудь может увидеть мою ошибку?
import pandas as pd
from nltk.translate.bleu_score import sentence_bleu
translations = {
'reference': [['this', 'is', 'a', 'test'],['this', 'is', 'a', 'test'],['this', 'is', 'a', 'test']],
'candidate': [['this', 'is', 'a', 'test'],['this', 'is', 'not','a', 'quiz'],['I', 'like', 'kitties', '.']]
}
df = pd.DataFrame(translations)
df['BLEU'] = df.apply(lambda row: sentence_bleu(row['reference'],row['candidate']), axis=1)
df
Это выводит это:
Index reference candidate BLEU
0 [this, is, a, test] [this, is, a, test] 1.288230e-231
1 [this, is, a, test] [this, is, not, a, quiz] 1.218332e-231
2 [this, is, a, test] [I, like, kitties, .] 0.000000e+00
Строка 0 должна быть равна 1,0, а строка 1 должна быть меньше 1,0. Вероятно, около 0,9. Что я делаю неправильно?
0 ответов
В настоящее время вы сравниваете строки внутри списка. Поскольку эти строки содержат только отдельные слова, оценка будет оценивать все n-граммы с n > 1 как 0.
Вместо этого вы хотите, чтобы ваша ссылка была ['this is a test']
(список основополагающих ссылок на правду), и кандидат на 'this is a test'
(один кандидат).
from nltk.translate.bleu_score import sentence_bleu
translations = {
'reference': [['this is a test'],['this is a test'],['this is a test']],
'candidate': ['this is a test','this is not a test','I like kitties']
}
df = pd.DataFrame(translations)
df['BLEU'] = df.apply(lambda row: sentence_bleu(row['reference'],row['candidate']), axis=1)
df
Что приводит к:
reference candidate BLEU
0 [this is a test] this is a test 1.000000e+00
1 [this is a test] this is not a test 7.037906e-01
2 [this is a test] I like kitties 6.830097e-155