1b-sft-dataset / to_alpaca.py
andro124543's picture
Initial upload: 5,235-sample ShareGPT SFT dataset
4b6e0b8 verified
Raw
History Blame Contribute Delete
832 Bytes
import json, sys
def convert(src, dst):
with open(src, encoding="utf-8") as f, open(dst, "w", encoding="utf-8") as g:
for line in f:
rec = json.loads(line)
conv = rec["conversations"]
human = [c["value"] for c in conv if c["from"] == "human"]
gpt = [c["value"] for c in conv if c["from"] == "gpt"]
if not human or not gpt:
continue
out = {"instruction": human[0],
"input": "\n\n".join(human[1:]) if len(human) > 1 else "",
"output": "\n\n".join(gpt)}
g.write(json.dumps(out, ensure_ascii=False) + "\n")
if __name__ == "__main__":
for split in ("train", "val", "test"):
convert(f"data/{split}.jsonl", f"data/{split}_alpaca.jsonl")
print("done")