'rouge1'
如果您想直接访问 Score 对象,您应该定义字典的键 ( )。
所以scores.append(scorer.score(hyp,ref))
将变为scores.append(scorer.score(hyp,ref)['rouge1'])
。
以下代码是计算每个文档的 ROUGE 度量并在单个字典中分别记住结果的更通用版本:
# importing the native rouge library
from rouge_score import rouge_scorer
# a list of the hypothesis documents
hyp = ['This is the first sample', 'This is another example']
# a list of the references documents
ref = ['This is the first sentence', 'It is one more sentence']
# make a RougeScorer object with rouge_types=['rouge1']
scorer = rouge_scorer.RougeScorer(['rouge1'])
# a dictionary that will contain the results
results = {'precision': [], 'recall': [], 'fmeasure': []}
# for each of the hypothesis and reference documents pair
for (h, r) in zip(hyp, ref):
# computing the ROUGE
score = scorer.score(h, r)
# separating the measurements
precision, recall, fmeasure = score['rouge1']
# add them to the proper list in the dictionary
results['precision'].append(precision)
results['recall'].append(recall)
results['fmeasure'].append(fmeasure)
输出将如下所示:
{'fmeasure': [0.8000000000000002, 0.22222222222222224],
'precision': [0.8, 0.2],
'recall': [0.8, 0.25]}
此外,我将建议rouge 库,它是ROUGE 论文的另一种实现。结果可能略有不同,但它会引入一些有用的功能,包括通过传入整个文本文档来计算 rouge 度量的可能性,并计算所有文档的平均结果。