|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import print_function |
3 | | -import sys |
4 | 3 | from pythonrouge.pythonrouge import Pythonrouge |
5 | | - |
| 4 | +from pprint import pprint |
6 | 5 |
|
7 | 6 | if __name__ == '__main__': |
8 | | - ROUGE_path = "./pythonrouge/RELEASE-1.5.5/ROUGE-1.5.5.pl" |
9 | | - data_path = "./pythonrouge/RELEASE-1.5.5/data" |
10 | | - summary_dir = "./sample/summary/" |
11 | | - reference_dir = "./sample/reference/" |
12 | | - # setting rouge options |
13 | | - rouge = Pythonrouge(n_gram=2, ROUGE_SU4=True, ROUGE_L=True, stemming=True, stopwords=True, word_level=True, length_limit=True, length=50, use_cf=False, cf=95, scoring_formula="average", resampling=True, samples=1000, favor=True, p=0.5) |
14 | | - print("evaluate sumamry & reference in these dir\nsummary: {}\nreference: {}".format(summary_dir, reference_dir)) |
15 | | - print("\nAll metric") |
16 | | - setting_file = rouge.setting(files=True, summary_path=summary_dir, reference_path=reference_dir) |
17 | | - print(rouge.eval_rouge(setting_file, ROUGE_path=ROUGE_path, data_path=data_path)) |
18 | | - print("\nRecall Only and save setting.xml") |
19 | | - setting_file = rouge.setting(files=True, summary_path=summary_dir, reference_path=reference_dir, delete=False) |
20 | | - print(rouge.eval_rouge(setting_file, recall_only=True, ROUGE_path=ROUGE_path, data_path=data_path)) |
21 | | - print("\nEvaluate ROUGE based on sentecnce lists") |
22 | | - summary = [["Great location, very good selection of food for breakfast buffet.", |
| 7 | + summary = './sample/summary/' |
| 8 | + reference = './sample/reference/' |
| 9 | + ROUGE_dir = './pythonrouge/RELEASE-1.5.5/ROUGE-1.5.5.pl' |
| 10 | + data_dir = './pythonrouge/RELEASE-1.5.5/data/' |
| 11 | + print('evaluate sumamry & reference in these dirs') |
| 12 | + print('summary:\t{}\nreference:\t{}'.format(summary, reference)) |
| 13 | + rouge = Pythonrouge(summary_file_exist=True, |
| 14 | + peer_path=summary, model_path=reference, |
| 15 | + n_gram=2, ROUGE_SU4=True, ROUGE_L=False, |
| 16 | + recall_only=True, |
| 17 | + stemming=True, stopwords=True, |
| 18 | + word_level=True, length_limit=True, length=50, |
| 19 | + use_cf=False, cf=95, scoring_formula='average', |
| 20 | + resampling=True, samples=1000, favor=True, p=0.5) |
| 21 | + score = rouge.calc_score() |
| 22 | + print('ROUGE-N(1-2) & SU4 F-measure only') |
| 23 | + pprint(score) |
| 24 | + print('Evaluate ROUGE based on sentecnce lists') |
| 25 | + """ |
| 26 | + ROUGE evaluates all system summaries and its corresponding reference |
| 27 | + a summary or summaries at onece. |
| 28 | + Summary should be double list, in each list has each summary. |
| 29 | + Reference summaries should be triple list because some of reference |
| 30 | + has multiple gold summaries. |
| 31 | + """ |
| 32 | + summary = [["Great location, very good selection of food for\ |
| 33 | + breakfast buffet.", |
23 | 34 | "Stunning food, amazing service.", |
24 | 35 | "The food is excellent and the service great."], |
25 | | - ["The keyboard, more than 90% standard size, is just large enough .", |
| 36 | + ["The keyboard, more than 90% standard size, is just\ |
| 37 | + large enough .", |
26 | 38 | "Surprisingly readable screen for the size .", |
27 | 39 | "Smaller size videos play even smoother ."]] |
28 | | - reference = [[["Food was excellent with a wide range of choices and good services.", "It was a bit expensive though."], |
29 | | - ["Food can be a little bit overpriced, but is good for a hotel."], |
30 | | - ["The food in the hotel was a little over priced but excellent in taste and choice.", |
31 | | - "There were also many choices to eat in the near vicinity of the hotel."], |
32 | | - ["The food is good, the service great.", |
33 | | - "Very good selection of food for breakfast buffet."] |
34 | | - ], |
35 | | - [ |
36 | | - ["The size is great and allows for excellent portability.", |
37 | | - "Makes it exceptionally easy to tote around, and the keyboard is fairly big considering the size of this netbook."], |
38 | | - ["Size is small and manageable.", |
39 | | - "Perfect size and weight.", |
40 | | - "Great size for travel."], |
41 | | - ["The keyboard is a decent size, a bit smaller then average but good.", |
42 | | - "The laptop itself is small but big enough do do things on it."], |
43 | | - ["In spite of being small it is still comfortable.", |
44 | | - "The screen and keyboard are well sized for use"] |
45 | | - ] |
46 | | - ] |
47 | | - doc_id = 1 |
48 | | - for s, r in zip(summary, reference): |
49 | | - print("sytem summary_{}: {}".format(doc_id, " ".join(s))) |
50 | | - for i, doc in enumerate(r): |
51 | | - print("reference summary_{}_{}: {}".format(doc_id, i+1, " ".join(doc))) |
52 | | - doc_id += 1 |
53 | | - setting_file2 = rouge.setting(files=False, summary=summary, reference=reference) |
54 | | - print("\nF-measure Only") |
55 | | - print(rouge.eval_rouge(setting_file2, f_measure_only=True, ROUGE_path=ROUGE_path, data_path=data_path)) |
| 40 | + reference = [ |
| 41 | + [["Food was excellent with a wide range of choices and\ |
| 42 | + good services.", "It was a bit expensive though."], |
| 43 | + ["Food can be a little bit overpriced, but is good for\ |
| 44 | + hotel."], |
| 45 | + ["The food in the hotel was a little over priced but\ |
| 46 | + excellent in taste and choice.", |
| 47 | + "There were also many choices to eat in the near\ |
| 48 | + vicinity of the hotel."]], |
| 49 | + [["The size is great and allows for excellent\ |
| 50 | + portability.", |
| 51 | + "Makes it exceptionally easy to tote around, and the\ |
| 52 | + keyboard is fairly big considering the size of this\ |
| 53 | + netbook."], |
| 54 | + ["Size is small and manageable.", |
| 55 | + "Perfect size and weight.", |
| 56 | + "Great size for travel."], |
| 57 | + ["The keyboard is a decent size, a bit smaller then\ |
| 58 | + average but good.", |
| 59 | + "The laptop itself is small but big enough do do\ |
| 60 | + things on it."], |
| 61 | + ["In spite of being small it is still comfortable.", |
| 62 | + "The screen and keyboard are well sized for use"]] |
| 63 | + ] |
| 64 | + rouge = Pythonrouge(summary_file_exist=False, |
| 65 | + summary=summary, reference=reference, |
| 66 | + n_gram=2, ROUGE_SU4=True, ROUGE_L=False, |
| 67 | + recall_only=True, stemming=True, stopwords=True, |
| 68 | + word_level=True, length_limit=True, length=50, |
| 69 | + use_cf=False, cf=95, scoring_formula='average', |
| 70 | + resampling=True, samples=1000, favor=True, p=0.5) |
| 71 | + score = rouge.calc_score() |
| 72 | + print('ROUGE-N(1-2) & SU4 recall only') |
| 73 | + pprint(score) |
0 commit comments