Download csv2json.py from thr3a/kaibun-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/datasets/thr3a/kaibun-dataset/resolve/main/csv2json.py
- Command line
-
hf download hf://datasets/thr3a/kaibun-dataset/csv2json.py
-
curl -L -o csv2json.py https://huggingface.co/datasets/thr3a/kaibun-dataset/resolve/main/csv2json.py
1.7 kB
| import csv | |
| import json | |
| RULE_PROMPT = """ | |
| ไปฅไธใฎๆกไปถใซๅพใใๆฅๆฌ่ชใฎ12ๆๅญไปฅๅ ใฎๅๆใไฝๆใใฆใใ ใใใ | |
| ใๆกไปถใ | |
| ใปๅๆใจใฏใๅใใ่ชญใใงใๅพใใใ่ชญใใงใๅใๆ็ซ ใจใชใใใฎใงใใ | |
| ไพใใฐใใขใชๆฑใใใชใขใใฏใฒใใใชใซ็ดใใจใใใใ ใใ ใใใใจใชใๅใใ่ชญใใงใๅพใใใ่ชญใใงใๅใๆ็ซ ใซใชใใฎใงๅๆใจใใใพใใ | |
| ใปๅ็ญใฏๅฟ ใ12ๆๅญไปฅๅ ใซใใฆใใ ใใใ | |
| ใปใๆฐ่็ดใใใใใใใใชใฉใ1ๅ่ชใ ใใงๆ็ซใใ้ใ่จ่ใฏๅฏพ่ฑกๅคใงใใๅฟ ใ่คๆฐใฎ่ชใ็ตใฟๅใใใๆๅณใ้ใๆ็ซ ใจใใฆไฝๆใใฆใใ ใใใ | |
| ใปใ้กใฎๅ่ชใไฝฟ็จใใๅๆใไฝๆใใฆใใ ใใใ ไพใใฐใใขใชใใใ้กใฎๅ่ชใชใใใขใชๆฑใใใชใขใใฏOKใงใใ | |
| ไปฅไธใฎใซใผใซใซๅบใฅใใฆใ็ฌๅต็ใชๅๆใใๆๆกใใ ใใใ | |
| ใใ้กใฎๅ่ชใ | |
| """ | |
| def create_kaibun_json(csv_file, json_file): | |
| data = [] | |
| with open(csv_file, 'r', encoding='utf-8') as file: | |
| reader = csv.reader(file) | |
| next(reader) # ใใใใผ่กใในใญใใ | |
| for row in reader: | |
| odai = row[0] | |
| original_text = row[1] | |
| reading = row[2] | |
| json_data = { | |
| "prompt": [ | |
| {"role": "user", "content": RULE_PROMPT + odai}, | |
| ], | |
| "answer": f"{original_text}({reading})" | |
| } | |
| data.append(json_data) | |
| with open(json_file, 'w', encoding='utf-8') as file: | |
| json.dump(data, file, ensure_ascii=False) | |
| create_kaibun_json('input.csv', 'data/train.json') | |