File size: 962 Bytes
1497fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import argparse


if __name__ == "__main__":
    parser = argparse.ArgumentParser("convertor for json dataformat")
    parser.add_argument("src", type=str)
    parser.add_argument("tgt", type=str)
    args = parser.parse_args()

    with open(args.src, "r", encoding="utf-8") as source_json:
        target_file = open(args.tgt, "w", encoding="utf-8")
        count = 0
         
        for line in source_json:
            if len(line.strip()) == 0:
                continue
            info = json.loads(line.strip())
            # speech, other = info["inputs"].split(" ", max_split=1)
            update_json = {
                "instruction": info["inputs"],
                "output": info["targets"],
                "input": "",
            }
            target_file.write(json.dumps(update_json))
            target_file.write("\n")
            count += 1
            if count % 1000 == 0:
                print("process {}".format(count))