git clone https://github.com/pltrdy/rouge
cd rouge
python setup.py install
新建一个py文件进行测试
注意:不能命名为rouge,否则导入相同的模块会因重名而报错!
测试1(文本测试)
from rouge import Rouge hypothesis ="the #### transcript is a written version of each day 's cnn student news program use this transcript to he lp students with reading comprehension and vocabulary use the weekly newsquiz to test your knowledge of storie s you saw on cnn student news"reference ="this page includes the show transcript use the transcript to help students with reading comprehension and vocabulary at the bottom of the page , comment for a chance to be mentioned on cnn student news . you must be a teac her or a student age # # or older to request a mention on the cnn student news roll call . the weekly newsquiz tests students ' knowledge of even ts in the news"rouge = Rouge()
scores = rouge.get_scores(hypothesis, reference)
测试2(文件测试)
import json
from rouge import Rouge# Load some sentences
with open('./tests/data.json') as f:data = json.load(f)hyps, refs = map(list, zip(*[[d['hyp'], d['ref']]fordin data]))
rouge = Rouge()
scores = rouge.get_scores(hyps, refs)# or
scores = rouge.get_scores(hyps, refs, avg=True)