"megatron/legacy/model/biencoder_model.py" did not exist on "22a3d81ab9ed767718fe940422595b31f27dd20c"
utils.py 644 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
25
PROMPT = "ده سؤال متعدد الاختيار (مع إجابته) على {}\n\n{}\n{}\n الجواب:"


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


def doc_to_text(doc):
    subject = doc["egy_subject"]  # subject_egyptian
    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):
    return [alpha[i][0] for i in range(len(doc["choices"]))]