"hopper/flash.h" did not exist on "a03f6f8e9ea6692568d98411b464034c22304afd"
utils.py 1006 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
from sklearn.metrics import f1_score


def doc_to_choice(doc):
    choices = eval(doc["choices"])
    return choices


def doc_to_text(doc):
Lintang Sutawika's avatar
Lintang Sutawika committed
10
    output = """You are a highly knowledgeable and intelligent artificial intelligence
11
                model answers multiple-choice questions about {subject}
Lintang Sutawika's avatar
Lintang Sutawika committed
12

13
14
15
16
17
18
19
                Question: {question}

                Choices:
                        A: {choice1}
                        B: {choice2}
                        C: {choice3}
                        D: {choice4}
Lintang Sutawika's avatar
Lintang Sutawika committed
20

21
                Answer:  """
Lintang Sutawika's avatar
Lintang Sutawika committed
22

23
    choices = eval(doc["choices"])
Lintang Sutawika's avatar
Lintang Sutawika committed
24
25
26
27
28
29
30
31
    text = output.format(
        subject=doc["subject"],
        question=doc["question"],
        choice1=choices[0],
        choice2=choices[1],
        choice3=choices[2],
        choice4=choices[3],
    )
32
33
34
35
36
37
38
39
    return text


def weighted_f1_score(items):
    unzipped_list = list(zip(*items))
    golds = unzipped_list[0]
    preds = unzipped_list[1]
    fscore = f1_score(golds, preds, average="weighted")
Lintang Sutawika's avatar
Lintang Sutawika committed
40
    return fscore