File size: 1,570 Bytes
a6326c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from utils import read_jsonl_file, write_jsonl_file, parse, choices


def preprocess(args, split):
    infile = os.path.join(args.input_dir, f"{split}_rand_split.jsonl")
    outfile = os.path.join(args.output_dir, f"{split}.jsonl")

    data = read_jsonl_file(infile)

    processed_data = []
    for example in data:
        dial = {
            "turn": "single",
            "locale": "en",
            "dialog": [],
            "knowledge": {
                "type": "dict",
                "value": {"question concept": example["question"]["question_concept"]},
            },
        }

        dial["dialog"].append(
            {"roles": ["USER"], "utterance": example["question"]["stem"], "roles_to_select": [example["answerKey"]]}
        )

        for choice in example["question"]["choices"]:
            dial["knowledge"]["value"][choice["label"]] = choice["text"]

        # answer = example["answerKey"]
        # label = -1
        # for idx, choice in enumerate(example["question"]["choices"]):
        #     dial["dialog"].append(
        #         {"roles": [f"{choices[idx]} choice"], "utterance": choice["text"]}
        #     )

        #     if choice["label"] == answer:
        #         assert label == -1
        #         label = idx

        # assert label >= 0
        # dial["dialog"][-1]["roles_to_select"] = [f"{choices[label]} choice"]

        processed_data.append(dial)

    write_jsonl_file(processed_data, outfile)


if __name__ == "__main__":
    args = parse()
    preprocess(args, "train")
    preprocess(args, "dev")