File size: 759 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
from utils import write_jsonl_file, read_csv_file, parse


def reformat(args, file):
    path = args.input_dir + "/" + file + ".csv"
    data = read_csv_file(path)
    turns = []
    for i in range(len(data)):
        t = {
            "turn": "single",
            "locale": "en",
            "dialog": [
                {
                    "roles": ["USER"],
                    "utterance": data["text"][i],
                    "active_intents": [data["category"][i]],
                }
            ],
        }
        turns.append(t)

    write_jsonl_file(turns, args.output_dir + "/" + file + ".jsonl")


def preprocess(args):
    reformat(args, "train")
    reformat(args, "test")


if __name__ == "__main__":
    args = parse()
    preprocess(args)