Download Dataset/transmethod/xtunerformat.py from KashiwaByte/DISC-Assignment: direct link, hf CLI and curl.
- Browser
- Download file 792 Bytes
-
https://huggingface.co/datasets/KashiwaByte/DISC-Assignment/resolve/main/Dataset/transmethod/xtunerformat.py
- Command line
-
hf download hf://datasets/KashiwaByte/DISC-Assignment/Dataset/transmethod/xtunerformat.py
-
curl -L -o xtunerformat.py https://huggingface.co/datasets/KashiwaByte/DISC-Assignment/resolve/main/Dataset/transmethod/xtunerformat.py
792 Bytes
| 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') | |