File size: 861 Bytes
6dc0c9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Take the intersection of two conversation files.

Usage: python3 -m fastchat.data.merge --input input.json --conv-id conv_id_file.json --out intersect.json
"""

import argparse
import json


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--input", type=str, required=True)
    parser.add_argument("--conv-id", type=str, required=True)
    parser.add_argument("--out-file", type=str, default="intersect.json")
    args = parser.parse_args()

    conv_id_objs = json.load(open(args.conv_id, "r"))
    conv_ids = set(x["conversation_id"] for x in conv_id_objs)

    objs = json.load(open(args.input, "r"))
    after_objs = [x for x in objs if x["conversation_id"] in conv_ids]

    print(f"#in: {len(objs)}, #out: {len(after_objs)}")
    json.dump(after_objs, open(args.out_file, "w"), indent=2, ensure_ascii=False)