-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccuracy_fns.py
42 lines (38 loc) · 1.35 KB
/
accuracy_fns.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
42
from postproc_utils import gqa_postproc, general_postprocessing
def GQA_accuracy(prediction, ground_truth, *args):
"""
Args:
prediction (list): List of predicted answers.
ground_truth (list): List of ground truth answers.
Returns:
score (float): Score of the prediction.
"""
if len(prediction) == 0: # if no prediction, return 0
return 0
assert len(prediction) == len(ground_truth)
score = 0
for p, g in zip(prediction, ground_truth):
if gqa_postproc(p) == g:
score += 1
return score / len(prediction)
def general_accuracy(prediction, ground_truth, *args):
"""
Args:
prediction (list): List of predicted answers.
ground_truth (list): List of ground truth answers.
Returns:
score (float): Score of the prediction.
"""
if len(prediction) == 0: # if no prediction, return 0
return 0
assert len(prediction) == len(ground_truth)
score = 0
for p, g in zip(prediction, ground_truth):
if general_postprocessing(p) == g:
score += 1
return score / len(prediction)
def get_accuracy_fn(dataset):
if dataset == "GQA":
return GQA_accuracy
else:
return general_accuracy