utils.py 742 Bytes
Newer Older
1
from lm_eval.utils import weighted_f1_score
2
3
4
5
6
7
8
9


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


def doc_to_text(doc):
10
11
12
13
14
15
16
17
18
19
    output = """As an expert in {subject}, choose the most accurate answer to the question below.
Your goal is to select the correct option 'A', 'B', 'C', or 'D' by understanding the nuances of the topic.

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

21
    choices = eval(doc["choices"])
Lintang Sutawika's avatar
Lintang Sutawika committed
22
23
24
25
26
27
28
29
    text = output.format(
        subject=doc["subject"],
        question=doc["question"],
        choice1=choices[0],
        choice2=choices[1],
        choice3=choices[2],
        choice4=choices[3],
    )
30
    return text