-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
41 lines (31 loc) · 1.37 KB
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random
import loadData as ld
#Rouge code Github : https://github.com/pltrdy/rouge
from rouge import Rouge
def get_rouge_scores(source_summaries, generated_summaries):
# source: list of source documents
# generated: list of generated texts
# return the Rouge-1 Score, Rouge-2 Score, Rouge-l Score
rouge = Rouge()
return rouge.get_scores(hyps=source_summaries, refs=generated_summaries, avg=True)
def evaluate_supervised_model(model, source, source_summaries, N, idxToWords):
# source: list of source documents
# source_summaries: list of source summaries
# model: Seq2Seq Keras model
# N: Pick n random documents from sources
# idxToWords: Is like an array where an index corresponds to his word
# Evaluate a supervised model with ROUGE metrics on N random documents from sources
result_Y = []
result_summary = []
random_indexes = random.sample(range(len(source)), N)
rouge = Rouge()
i=0
for index in random_indexes:
if( i%100 == 0):
print(i)
result_Y.append(ld.convertIndexToWords(source_summaries[index], idxToWords).replace('_start_', ''))
summary = model.demo_model_predictions(source[index])
result_summary.append(summary.replace('_start_', ''))
i+=1
print("Done !")
return rouge.get_scores(hyps=result_Y, refs=result_summary, avg=True)