Download WorkshopsEval.py from tankaplans/WorkshopsEval: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/datasets/tankaplans/WorkshopsEval/resolve/main/WorkshopsEval.py
- Command line
-
hf download hf://datasets/tankaplans/WorkshopsEval/WorkshopsEval.py
-
curl -L -o WorkshopsEval.py https://huggingface.co/datasets/tankaplans/WorkshopsEval/resolve/main/WorkshopsEval.py
2.32 kB
| import os | |
| import datasets | |
| import pandas as pd | |
| _CITATION = """ | |
| """ | |
| _DESCRIPTION = """ | |
| """ | |
| _HOMEPAGE = """ | |
| """ | |
| _LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License" | |
| # 使用zip压缩存储 | |
| _URL = r"https://huggingface.co/datasets/tankaplans/WorkshopsEval/resolve/main/data.zip" | |
| # 必须预设 | |
| # 新上传文件请按照这个格式进行存储和更新 | |
| task_list = [ | |
| 'buddha_fact_questions_and_answers', | |
| 'buddha_open_questions', | |
| 'buddha_user_questions', | |
| 'what_to_watch_fact_qa', | |
| 'what_to_watch_solab_questions' | |
| ] | |
| class WorkshopsEvalConfig(datasets.BuilderConfig): | |
| def __init__(self, **kwargs): | |
| super().__init__(version=datasets.Version("1.0.0"), **kwargs) | |
| class WorkshopsEval(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| WorkshopsEvalConfig( | |
| name=task_name, | |
| ) | |
| for task_name in task_list | |
| ] | |
| # 数据的基本格式 | |
| def _info(self): | |
| features = datasets.Features( | |
| { | |
| "question": datasets.Value("string"), | |
| "answer": datasets.Value("string"), | |
| "analysis":datasets.Value("string"), | |
| } | |
| ) | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=features, | |
| homepage=_HOMEPAGE, | |
| license=_LICENSE, | |
| citation=_CITATION, | |
| ) | |
| # 怎么读取数据 | |
| def _split_generators(self, dl_manager): | |
| data_dir = dl_manager.download_and_extract(_URL) # 下载目录 | |
| task_name = self.config.name | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split("dev"), | |
| gen_kwargs={ | |
| "filepath": os.path.join( | |
| data_dir, "data", f'{task_name}.json' | |
| ) | |
| }, | |
| ), | |
| ] | |
| # 自定义怎么控制数据个形式 | |
| def _generate_examples(self, filepath): | |
| df = pd.read_json(filepath,encoding="utf-8") | |
| for i, instance in enumerate(df.to_dict(orient="records")): | |
| if "answer" not in instance.keys(): | |
| instance["answer"]="" | |
| if "analysis" not in instance.keys(): | |
| instance["analysis"]="" | |
| yield i, instance |