Spaces:
Sleeping
Sleeping
Update compute_score.py
Browse files- compute_score.py +12 -12
compute_score.py
CHANGED
@@ -46,17 +46,17 @@ def recall_score(prediction, ground_truth):
|
|
46 |
recall = 1.0 * num_same / len(ground_truth_tokens)
|
47 |
return recall
|
48 |
|
49 |
-
def f1_score(prediction, ground_truth):
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
|
62 |
def exact_match_score(prediction, ground_truth):
|
@@ -84,9 +84,9 @@ def compute_score(dataset, predictions):
|
|
84 |
ground_truths = list(map(lambda x: x["text"], qa["answers"]))
|
85 |
prediction = predictions[qa["id"]]
|
86 |
exact_match += metric_max_over_ground_truths(exact_match_score, prediction, ground_truths)
|
87 |
-
f1 += metric_max_over_ground_truths(f1_score, prediction, ground_truths)
|
88 |
precision += metric_max_over_ground_truths(precision_score, prediction, ground_truths)
|
89 |
recall += metric_max_over_ground_truths(recall_score, prediction, ground_truths)
|
|
|
90 |
exact_match = 100.0 * exact_match / total
|
91 |
f1 = 100.0 * f1 / total
|
92 |
recall = 100.0 * recall / total
|
|
|
46 |
recall = 1.0 * num_same / len(ground_truth_tokens)
|
47 |
return recall
|
48 |
|
49 |
+
# def f1_score(prediction, ground_truth):
|
50 |
+
# prediction_tokens = normalize_answer(prediction).split()
|
51 |
+
# ground_truth_tokens = normalize_answer(ground_truth).split()
|
52 |
+
# common = Counter(prediction_tokens) & Counter(ground_truth_tokens)
|
53 |
+
# num_same = sum(common.values())
|
54 |
+
# if num_same == 0:
|
55 |
+
# return 0
|
56 |
+
# precision = 1.0 * num_same / len(prediction_tokens)
|
57 |
+
# recall = 1.0 * num_same / len(ground_truth_tokens)
|
58 |
+
# f1 = (2 * precision * recall) / (precision + recall)
|
59 |
+
# return f1
|
60 |
|
61 |
|
62 |
def exact_match_score(prediction, ground_truth):
|
|
|
84 |
ground_truths = list(map(lambda x: x["text"], qa["answers"]))
|
85 |
prediction = predictions[qa["id"]]
|
86 |
exact_match += metric_max_over_ground_truths(exact_match_score, prediction, ground_truths)
|
|
|
87 |
precision += metric_max_over_ground_truths(precision_score, prediction, ground_truths)
|
88 |
recall += metric_max_over_ground_truths(recall_score, prediction, ground_truths)
|
89 |
+
f1 += (2 * precision * recall) / (precision + recall)
|
90 |
exact_match = 100.0 * exact_match / total
|
91 |
f1 = 100.0 * f1 / total
|
92 |
recall = 100.0 * recall / total
|