-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcover_alpaca2jsonl.py
31 lines (23 loc) · 966 Bytes
/
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
import argparse
import json
from tqdm import tqdm
def format_example(example: dict) -> dict:
context = f"Question: {example['instruction'].strip()}\n\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/test.json")
parser.add_argument("--save_path", type=str, default="data/test.jsonl")
args = parser.parse_args()
with open(args.data_path,encoding='UTF-8') 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),indent=4, ensure_ascii=False) + '\n')
f.write(json.dumps(format_example(example)) + '\n')
if __name__ == "__main__":
main()