Spaces:
Sleeping
Sleeping
Rodrigo Ferreira Rodrigues commited on
Commit ·
93e15ce
1
Parent(s): fcb8803
adding missing function
Browse files- place_gen_evaluate.py +19 -1
place_gen_evaluate.py
CHANGED
|
@@ -81,6 +81,24 @@ class Place_gen_evaluate(evaluate.Metric):
|
|
| 81 |
self.bleu = evaluate.load('bleu')
|
| 82 |
self.bert_score = evaluate.load('bertscore')
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
def _compute(self, generations, golds):
|
| 85 |
'''Calculate Accuracy and BLEU-1 scores between model generations and golden answers.
|
| 86 |
We expect a set of generated answers and want to find it among a set of gold answers.'''
|
|
@@ -106,7 +124,7 @@ class Place_gen_evaluate(evaluate.Metric):
|
|
| 106 |
f_ans = list(set([a.lower().strip() for a in f_ans])) #get rid of duples values
|
| 107 |
f_gold = list(set(gold))
|
| 108 |
|
| 109 |
-
precision, recall =
|
| 110 |
|
| 111 |
precisions.append(precision)
|
| 112 |
recalls.append(recall)
|
|
|
|
| 81 |
self.bleu = evaluate.load('bleu')
|
| 82 |
self.bert_score = evaluate.load('bertscore')
|
| 83 |
|
| 84 |
+
def _calculate_pre_rec(self, gens, golds, d):
|
| 85 |
+
dists = []
|
| 86 |
+
|
| 87 |
+
for gold in golds:
|
| 88 |
+
g_dist = []
|
| 89 |
+
for gen in gens:
|
| 90 |
+
g_dist.append(d(gold, gen))
|
| 91 |
+
if len(g_dist) == 0:
|
| 92 |
+
g_dist.append(100) #penalty if the model doesnt generate anything
|
| 93 |
+
dists.append(g_dist)
|
| 94 |
+
|
| 95 |
+
dists = np.array(dists)
|
| 96 |
+
precision = np.min(dists, axis=0).sum()
|
| 97 |
+
|
| 98 |
+
recall = np.min(dists, axis=1).sum()
|
| 99 |
+
|
| 100 |
+
return precision, recall
|
| 101 |
+
|
| 102 |
def _compute(self, generations, golds):
|
| 103 |
'''Calculate Accuracy and BLEU-1 scores between model generations and golden answers.
|
| 104 |
We expect a set of generated answers and want to find it among a set of gold answers.'''
|
|
|
|
| 124 |
f_ans = list(set([a.lower().strip() for a in f_ans])) #get rid of duples values
|
| 125 |
f_gold = list(set(gold))
|
| 126 |
|
| 127 |
+
precision, recall = self._calculate_pre_rec(f_ans, f_gold, Levenshtein.distance)
|
| 128 |
|
| 129 |
precisions.append(precision)
|
| 130 |
recalls.append(recall)
|