utils.py 641 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
PROMPT = "هادا سؤال متعدد الخيارات (مع الجواب ديالو) على {}\n\n{}\n{}\nالجواب:"


alpha = ["A.", "B.", "C.", "D.", "E."]


def doc_to_text(doc):
    subject = doc["subject_darija"]
    question = (
        doc["question"]
        if doc["context"] == ""
        else f"{doc['context']}\n\n{doc['question']}"
    )

    options = []
    for i, opt in enumerate(doc["choices"]):
        options.append(f"{alpha[i]} {opt}")

    doc_text = PROMPT.format(subject, question, "\n".join(options))

    return doc_text


def doc_to_choice(doc):
25
    return [alpha[i][0] for i in range(len(doc["choices"]))]