-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcover_alpaca2jsonl.py
47 lines (36 loc) · 1.11 KB
/
cover_alpaca2jsonl.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!python
# -*- coding: utf-8 -*-
# @author: Kun
'''
Author: Kun
Date: 2023-04-19 00:59:24
LastEditTime: 2023-04-19 01:00:44
LastEditors: Kun
Description:
FilePath: /ChatGLM-LoRA-RLHF-PyTorch/cover_alpaca2jsonl.py
'''
"""
https://github.com/mymusise/ChatGLM-Tuning
"""
import argparse
import json
from tqdm import tqdm
def format_example(example: dict) -> dict:
context = f"Instruction: {example['instruction']}\n"
if example.get("input"):
context += f"Input: {example['input']}\n"
context += "Answer: "
target = example["output"]
return {"context": context, "target": target}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--data_path", type=str, default="data/alpaca_data.json")
parser.add_argument("--save_path", type=str, default="data/alpaca_data.jsonl")
args = parser.parse_args()
with open(args.data_path) as f:
examples = json.load(f)
with open(args.save_path, 'w') as f:
for example in tqdm(examples, desc="formatting.."):
f.write(json.dumps(format_example(example)) + '\n')
if __name__ == "__main__":
main()