File size: 1,005 Bytes
6ef31de |
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 |
"""
Sample some conversations from a file.
Usage: python3 -m fastchat.data.sample --in sharegpt.json --out sampled.json
"""
import argparse
import json
from typing import Dict, Sequence, Optional
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--in-file", type=str, required=True)
parser.add_argument("--out-file", type=str, default="sampled.json")
parser.add_argument("--begin", type=int, default=0)
parser.add_argument("--end", type=int, default=100)
parser.add_argument("--max-length", type=int, default=128)
args = parser.parse_args()
content = json.load(open(args.in_file, "r"))
new_content = []
for i in range(args.begin, args.end):
sample = content[i]
concat = ""
for s in sample["conversations"]:
concat += s["value"]
if len(concat) > args.max_length:
continue
new_content.append(sample)
json.dump(new_content, open(args.out_file, "w"), indent=2)
|