1.rouge介紹
ROUGE評價方法與pyramid惕橙,BLUE方法一起作為評價自動摘要質(zhì)量的內(nèi)部評價方法的三大中流砥柱。
- ROUGE:recall-oriented understand for gisting evalution
- 2004年谓形,Chin-Yew Lin 提出
- 基本思想
由多個專家分別生成人工摘要灶伊,構(gòu)成標準摘要集,將系統(tǒng)生成的自動摘要與人工生成的標準摘要相比較寒跳,通過統(tǒng)計二者之間重疊的基本單元(n元語法聘萨,詞序列和詞對)的數(shù)目,來評價摘要的質(zhì)量童太。通過多專家人工摘要的對比米辐,提高評價系統(tǒng)的穩(wěn)定性和健壯性碾牌。
這個方法已經(jīng)成為評價摘要技術(shù)的通用標準之一。
2.評價標準
- ROUGE-N
- ROUGE-L
- ROUGE-S
- ROUGE-W
- ROUGE-SU
3. ROUGE-N(N-gram Co-Occurrence Statistics)
-
N-gram模型
n-gram模型.png
句子S由詞序列[圖片上傳失敗...(image-a49417-1542860196809)]組成儡循,計算句子S出現(xiàn)的概率 [圖片上傳失敗...(image-31d2bd-1542860196809)])最簡單舶吗,最直接的方法是計數(shù)后做除法,也就是最大似然估計(MLE)择膝,但是這樣做會面臨數(shù)據(jù)稀疏嚴重和參數(shù)空間巨大的問題誓琼,導致無法實用。于是一般采用n-gram模型肴捉,n-gram模型基于馬爾科夫假設(shè)腹侣,他認為,一個詞的出現(xiàn)僅僅依賴于他前面出現(xiàn)的有限的一個或者幾個詞齿穗。
其中分母是n-gram的個數(shù)傲隶,分子是參考摘要和自動摘要共有的n-gram的個數(shù)窃页。舉例說明一下:
自動摘要Y(一般是自動生成的):
the cat was found under the bed
參考摘要跺株,X1 (gold standard ,人工生成的):
the cat was under the bed
summary的1-gram脖卖、2-gram如下乒省,N-gram以此類推:
rouge_1(X1,Y)= 6/6=1.0,分子是待評測摘要和參考摘要都出現(xiàn)的1-gram的個數(shù)畦木,分子是參考摘要的1-gram個數(shù)袖扛。(其實分母也可以是待評測摘要的,但是在精確率和召回率之間十籍,我們更關(guān)心的是召回率Recall蛆封,同時這也和上面ROUGN-N的公式相同)
同樣,Rouge_2(X1,Y)=4/5=0.8
4. ROUGE-L
5.ROUGE-W
ROUGE-W是ROUGW-L的改進版勾栗,例如下面這種情況
圖中惨篱,X 是參考文摘,Y1械姻,Y2是兩個待評測文摘妒蛇,明顯Y1 要優(yōu)于Y2 ,因為Y1 可以和參考摘要X 連續(xù)匹配楷拳,但是Rouge_L(X,Y1)=Rouge_L(X,Y2) ,針對這個問題論文作者提出了改進的方案—加權(quán)最長公共子序列(Weighted Longest Common Subsequence)吏奸。
6.ROUGE-S
即使用了skip-grams欢揖,在參考摘要和待評測摘要進行匹配時,不要求gram之間必須是連續(xù)的奋蔚,可以“跳過”幾個單詞她混,比如skip-bigram烈钞,在產(chǎn)生grams時,允許最多跳過兩個詞坤按。比如“cat in the hat”的 skip-bigrams 就是 “cat in, cat the, cat hat, in the, in hat, the hat”.
7.總結(jié)
8.rouge與pyrouge的安裝
使用pyrouge前毯欣,需要安裝好rouge.
下面兩個鏈接有相應(yīng)的安裝工具和教程
https://blog.csdn.net/qq_32458499/article/details/78994388
https://blog.csdn.net/Hay54/article/details/78744912
注意:Github上的ROUGE已經(jīng)不可以用了。
9.使用
def rouge(ref, hyp, log_path):
assert len(ref) == len(hyp)
ref_dir = log_path + 'reference/'
cand_dir = log_path + 'candidate/'
if not os.path.exists(ref_dir):
os.mkdir(ref_dir)
if not os.path.exists(cand_dir):
os.mkdir(cand_dir)
for i in range(len(ref)):
with codecs.open(ref_dir+"%06d_reference.txt" % i, 'w', 'utf-8') as f:
f.write(" ".join(ref[i]).replace(' ', '') + '\n')
with codecs.open(cand_dir+"%06d_candidate.txt" % i, 'w', 'utf-8') as f:
f.write(" ".join(hyp[i]).replace(' ', '').replace('<unk>', 'UNK') + '\n')
r = pyrouge.Rouge155()
r.model_filename_pattern = '#ID#_reference.txt'
r.system_filename_pattern = '(\d+)_candidate.txt'
r.model_dir = ref_dir
r.system_dir = cand_dir
logging.getLogger('global').setLevel(logging.WARNING)
rouge_results = r.convert_and_evaluate()
scores = r.output_to_dict(rouge_results)
recall = [round(scores["rouge_1_recall"] * 100, 2),
round(scores["rouge_2_recall"] * 100, 2),
round(scores["rouge_l_recall"] * 100, 2)]
precision = [round(scores["rouge_1_precision"] * 100, 2),
round(scores["rouge_2_precision"] * 100, 2),
round(scores["rouge_l_precision"] * 100, 2)]
f_score = [round(scores["rouge_1_f_score"] * 100, 2),
round(scores["rouge_2_f_score"] * 100, 2),
round(scores["rouge_l_f_score"] * 100, 2)]
print("F_measure: %s Recall: %s Precision: %s\n"
% (str(f_score), str(recall), str(precision)))
with codecs.open(ref_dir+"rougeScore", 'w+', 'utf-8') as f:
f.write("F_measure: %s Recall: %s Precision: %s\n"
% (str(f_score), str(recall), str(precision)))
return f_score[:], recall[:], precision[:]
首先記得:import pyrouge
這里的ref是生成的摘要臭脓,hyp是系統(tǒng)參考摘要
regerence文件夾下酗钞,文件名為reference00.txt, 00代表數(shù)字編號
一定要記住
文件中都是一行一個句子!来累。
TXT文件中好像不允許出現(xiàn)'<'符號砚作,例如'<unk>',如果有可能會報錯嘹锁!
參考
https://blog.csdn.net/lime1991/article/details/42521029
https://blog.csdn.net/qq_25222361/article/details/78694617