File size: 792 Bytes
7c93e9d |
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 csv
import json
csv_file = 'Read_Comperhension50k.csv'
jsonl_file = 'Xtuner_Read_Comperhension50k.jsonl'
# 生成JSONL文件
messages = []
with open(csv_file, 'r', encoding='utf-8') as file:
reader = csv.reader(file)
next(reader) # 跳过标题行
for row in reader:
if len(row) >= 3:
insturction = row[0]
input= row[1]
output = row[2]
conversation = [
{
"system": insturction,
"input": input,
"output": output
}
]
messages.append({"conversation": conversation})
# 保存为JSONL文件
with open(jsonl_file, 'w', encoding='utf-8') as file:
for message in messages:
file.write(json.dumps(message, ensure_ascii=False) + '\n')
|