我正在进行文本摘要实验。得到解码后的句子和引用句子后,我用pyrouge得到了ROUGE得分,python代码如下:
from pyrouge import Rouge155
r=Rouge155()
r.model_filename_pattern = '#ID#——reference.txt'
r.system_filename_pattern = '(\d+)_decoded.txt'
r.model_dir = '/home/test/reference'
r.system_dir = '/home/test/decoded'
rouge_results = r.convert_and_evaluate()
print rouge_results
output_dict = r.output_to_dict(output)
但它似乎没有用,它报告了subprocess.CalledProcessError
和
Illegal division by zero at /.../.../ROUGE/RELEASE-1.5.5/ROUGE-1.5.5.pl
以下是具体的错误信息:
Traceback (most recent call last):
File "rouge.py", line 28, in <module>
rouge_results = r.convert_and_evaluate()
File "/home/username/env/local/lib/python2.7/site-packages/pyrouge-0.1.3.py2.7.egg/pyrouge/Rouge155.py", line 364, in convert_and_evaluate
rouge_output = self.evaluate(system_id, rouge_args)
File "/home/username/env/local/lib/python2.7/site-packages/pyrouge-0.1.3.py2.7.egg/pyrouge/Rouge155.py", line 339, in evaluate
rouge_output = check_output(command).decode("UTF-8")
File "/usr/lib/python2.7/subprocess.py", line 574, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '[u'/home/username/env/ROUGE/RELEASE-1.5.5/ROUGE-1.5.5.pl', '-e', '/home/username/env/ROUGE/RELEASE-1.5.5/data', '-c', '95','-2', '-1', '-U', '-r', '1000', '-n','4','-w','1.2','-a',u'-m', u' /tmp/tmpG9VKo9/rouge_conf.xml']' returned non-zero exit status 255
有没有人遇到过这种问题?感谢任何建议!非常感谢!
答案 0 :(得分:0)
我发现此问题是由参考语句中的<s>
和</s>
引起的。我删除了这些符号并最终获得了ROUGE分数。
答案 1 :(得分:0)
总的来说,我发现您必须从摘要中删除所有标记,例如:<something>
。就我而言,我按照以下说明删除了<n>
:
summary.replace('<n>', '')