Download simpleqa_gen_data/format_data.py from SunSec/ds_zhiyuan: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/SunSec/ds_zhiyuan/resolve/main/simpleqa_gen_data/format_data.py
- Command line
-
hf download hf://datasets/SunSec/ds_zhiyuan/simpleqa_gen_data/format_data.py
-
curl -L -o format_data.py https://huggingface.co/datasets/SunSec/ds_zhiyuan/resolve/main/simpleqa_gen_data/format_data.py
1.34 kB
| import json | |
| import pandas as pd | |
| import ast | |
| def load_json(file_path): | |
| with open(file_path, "r", encoding="utf-8") as file: | |
| data = json.load(file) | |
| print(f"load from {file_path}, {len(data)}") | |
| return data | |
| # file_path = "/share/project/sunshuang/simpleqa_gen_data/data/simple_qa_test_set.json" | |
| file_path = "/share/project/sunshuang/simpleqa_gen_data/data/simple_qa_test_set.csv" | |
| data = pd.read_csv(file_path) | |
| # data = load_json(file_path) | |
| format_data = [] | |
| for id, item in enumerate(data.to_dict(orient="records")): | |
| item["metadata"] = ast.literal_eval(item["metadata"]) | |
| print(type(item["metadata"])) | |
| # format_item = { | |
| # "id": id, | |
| # "Question": item["problem"], | |
| # "answer": [item["answer"]], | |
| # "urls": item["metadata"]["urls"] | |
| # } | |
| format_item = { | |
| "id": id, | |
| "Question": item["problem"], | |
| "answer": [item["answer"]], | |
| "metadata": item["metadata"] | |
| } | |
| format_data.append(format_item) | |
| with open("/share/project/sunshuang/simpleqa_gen_data/data/simple_qa_test_set_format_with_metadata.json", "w", encoding="utf-8") as file: | |
| json.dump(format_data, file, ensure_ascii=False, indent=4) | |
| print(f"save to /share/project/sunshuang/simpleqa_gen_data/data/simple_qa_test_set_format_with_metadata.json, {len(format_data)}") |