File size: 2,669 Bytes
4290ca8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
import argparse


def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("--file", required=True, type=str)

    args = parser.parse_args()

    input_path = args.file
    with open(input_path, 'r') as reader:
        data = json.load(reader)

    """
    Predict label format:
    [{
            "id": "1",
            "pred": "A"
    }]
    """


    with open("bai-scieval-valid.json", 'r') as reader:
        label_data = json.load(reader)

    label_data = dict([(label["id"], label) for label in label_data] )

    category_judge = {
        "biology": [0, 0, 0, 0],
        "chemistry": [0, 0, 0, 0],
        "physics": [0, 0, 0, 0]
    }
    category_num = {
        "biology": [0, 0, 0, 0],
        "chemistry": [0, 0, 0, 0],
        "physics": [0, 0, 0, 0]
    }
    ability_index = {
        "Base Knowledge": 0,
        "Knowledge Application": 1,
        "Scientific Calculation": 2,
        "Research Ability": 3,
    }
    index_ability = dict([(value, key) for key, value in ability_index.items()])

    all_cnt = 0

    for d in data:
        data_id = d["id"]
        pred = d["pred"]
        
        answer = label_data[data_id]["answer"][0]
        question_type = label_data[data_id]["type"]
        question_category = label_data[data_id]["category"]
        ability = label_data[data_id]["ability"]
        category_num[question_category][ability_index[ability]] += 1
        if question_type == "multiple-choice":
            if answer.lower() == pred[0].lower():
                category_judge[question_category][ability_index[ability]] += 1
                all_cnt += 1
        elif question_type == "judge":
            if answer.lower() in pred.lower():
                category_judge[question_category][ability_index[ability]] += 1
                all_cnt += 1
        elif question_type == "filling":
            if answer.lower() in pred.lower():
                category_judge[question_category][ability_index[ability]] += 1
                all_cnt += 1
        else:
            raise ValueError


    results = {}
    for category in category_judge.keys():
        # print(f"==== {category} ====")
        results[category] = {}
        category_j = category_judge[category]
        category_n = category_num[category]
        for i in range(len(category_j)):
            if category_n[i] == 0:
                continue
            results[category][index_ability[i]] = category_j[i] / category_n[i]
            print(index_ability[i], category_j[i] / category_n[i])
        results[category]["all"] = sum(category_j)/sum(category_n)


    results["all"] = all_cnt / len(data)
    
    return results