| import argparse | |
| import jsonlines | |
| import json | |
| import re | |
| from tqdm import tqdm | |
| import re | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| "--in-file", type=str, default="ultrachat_uncensored_100k.jsonl" | |
| ) | |
| parser.add_argument( | |
| "--out-file", type=str, default="ultrachat_uncensored_sharegpt_100k.jsonl" | |
| ) | |
| args = parser.parse_args() | |
| in_file = args.in_file | |
| out_file = args.out_file | |
| with jsonlines.open(in_file) as reader: | |
| f = open(out_file, "w", encoding="utf-8") | |
| for conv in tqdm(reader): | |
| conversations = [] | |
| for i, v in enumerate(conv["data"]): | |
| conversations.append( | |
| {"from": "human" if i % 2 == 0 else "gpt", "value": v} | |
| ) | |
| json.dump( | |
| { | |
| "id": conv["id"], | |
| "conversations": conversations, | |
| }, | |
| f, | |
| ensure_ascii=False, | |
| ) | |
| f.write("\n") | |