utils.py 946 Bytes
Newer Older
Israel Abebe Azime's avatar
Israel Abebe Azime committed
1
2
from sklearn.metrics import f1_score

JessicaOjo's avatar
JessicaOjo committed
3

Israel Abebe Azime's avatar
Israel Abebe Azime committed
4
5
6
7
def doc_to_choice(doc):
    choices = eval(doc["choices"])
    return choices

JessicaOjo's avatar
JessicaOjo committed
8

Israel Abebe Azime's avatar
Israel Abebe Azime committed
9
10
11
12
13
14
15
16
17
18
19
20
21
def doc_to_text(doc):
    output = """You are a highly knowledgeable and intelligent artificial intelligence 
                model answers multiple-choice questions about '{subject}'
                
                Question: '''{question}'''

                Choices:
                        A: ''{choice1}'''
                        B: ''{choice2}'''
                        C: ''{choice3}'''
                        D: ''{choice4}'''
                       
                Answer:  """
Israel Abebe Azime's avatar
Israel Abebe Azime committed
22
    
Israel Abebe Azime's avatar
Israel Abebe Azime committed
23
24
25
26
27
28
29
30
    choices = eval(doc["choices"])
    text = output.format(subject=doc['subject'],
                         question=doc['question'],
                         choice1=choices[0],
                         choice2=choices[1],
                         choice3=choices[2],
                         choice4=choices[3])
    return text