utils.py 691 Bytes
Newer Older
h-albert-lee's avatar
h-albert-lee committed
1
2
import datasets

h-albert-lee's avatar
h-albert-lee committed
3

h-albert-lee's avatar
h-albert-lee committed
4
5
def process_docs(dataset: datasets.Dataset) -> datasets.Dataset:
    def _process_doc(doc):
h-albert-lee's avatar
h-albert-lee committed
6
7
8
9
10
11
12
        instruction = (
            f"다음을 읽고 정답으로 알맞은 것을 고르시요.\n"
            f"### Question: {doc['question']}\n"
            f"### Options:\n"
            f"(1) {doc['option#1']}\n(2) {doc['option#2']}\n(3) {doc['option#3']}\n(4) {doc['option#4']}\n"
            f"### Answer: 주어진 문제의 정답은"
        )
h-albert-lee's avatar
h-albert-lee committed
13
14
15
        out_doc = {
            "question": instruction,
            "choices": ["(1)", "(2)", "(3)", "(4)"],
h-albert-lee's avatar
h-albert-lee committed
16
            "gold": int(doc["answer"]) - 1,
h-albert-lee's avatar
h-albert-lee committed
17
18
19
20
        }
        return out_doc

    return dataset.map(_process_doc)