File size: 1,169 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
import os
from utils import read_jsonl_file, write_jsonl_file, parse

'''
This is script is used to process the whole file of MKQA
Every two sentences (QA objects) in a line share the same language
'''

def preprocess(args):
    path = os.path.join(args.input_dir, "mkqa.jsonl")
    data = read_jsonl_file(path)
    '''
    add add train/eval/test instruction and language chosen
    '''
    locales = list(data[0]["answers"].keys())
    pack = []
    
    for line in data:
        for locale in locales:
            t = {
                "turn": "multi",
                "locale": locale,
                "dialog": []
            }

            que = {
                "role": "question",
                "utterance": line["queries"][locale]
            }
            ans = {
                "role": "answer",
                "utterance": line["answers"][locale][0]["text"]
            }
            
            t["dialog"].append(que)
            t["dialog"].append(ans)
        
            pack.append(t)
    
    write_jsonl_file(pack, os.path.join(args.output_dir, "mkqa_preprocessed.jsonl"))


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