| from datasets import Dataset, DatasetDict, GeneratorBasedBuilder, Split, SplitGenerator, Value, Features, load_dataset | |
| class LongBenchPro(GeneratorBasedBuilder): | |
| VERSION = "1.0.0" | |
| def _info(self): | |
| return DatasetInfo( | |
| description="LongBench Pro dataset", | |
| features=Features({ | |
| "id": Value("string"), | |
| "context": Value("string"), | |
| "language": Value("string", choices=["English", "Chinese"]), | |
| "token_length": Value("string", choices=["8k", "16k", "32k", "64k", "128k", "256k"]), | |
| "primary_task": Value("string"), | |
| "secondary_task": Value("string"), | |
| "contextual_requirement": Value("string", choices=["Full", "Partial"]), | |
| "question_nonthinking": Value("string"), | |
| "question_thinking": Value("string"), | |
| "answer": Value("list"), | |
| "difficulty": Value("string", choices=["Easy", "Moderate", "Hard", "Extreme"]), | |
| }), | |
| supervised_keys=None, | |
| homepage="https://huggingface.co/datasets/caskcsg/LongBench_Pro", | |
| ) | |
| def _split_generators(self, dl_manager): | |
| data_path = dl_manager.download_and_extract("longbench_pro.json") | |
| return [ | |
| SplitGenerator( | |
| name=Split.TRAIN, | |
| gen_kwargs={"filepath": data_path} | |
| ) | |
| ] | |
| def _generate_examples(self, filepath): | |
| import json | |
| with open(filepath, encoding="utf-8") as f: | |
| data = json.load(f) | |
| for i, item in enumerate(data): | |
| yield i, item |