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)) | |