|
import json |
|
import datasets |
|
|
|
_REPO_NAME = "TeDriCS/tedrics-data" |
|
|
|
_DESCRIPTION = "" |
|
|
|
_HOMEPAGE = "" |
|
|
|
_CITATION = """\ |
|
@misc{, |
|
title={ }, |
|
author={}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
_LICENSE = 'CC BY-SA' |
|
|
|
_SUBSETS = ["tasks", "testcases", "codefunctions"] |
|
|
|
_DATA_URLS = { |
|
"tasks": { |
|
"train": "tedrics_data_tasks.json" |
|
}, |
|
"testcases": { |
|
"train": "tedrics_data_testcases.json", |
|
"validation": "tedrics_data_testcases_val.json" |
|
}, |
|
"codefunctions": { |
|
"train": "tedrics_data_codefunctions.json", |
|
"validation": "tedrics_data_codefunctions_val.json" |
|
} |
|
} |
|
|
|
class TeDriCSData(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name=f"{subset}", |
|
version=datasets.Version("1.1.0"), |
|
description=_DESCRIPTION, |
|
) |
|
for subset in _SUBSETS |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "tasks" |
|
|
|
def _info(self): |
|
if self.config.name == "tasks": |
|
features = datasets.Features( |
|
{ |
|
"task_id": datasets.Value("int32"), |
|
"mbpp_task_id": datasets.Value("int32"), |
|
"source": datasets.Value("string"), |
|
"licence": datasets.Value("string"), |
|
"task": datasets.Value("string"), |
|
} |
|
) |
|
|
|
if self.config.name == "testcases": |
|
features = datasets.Features( |
|
{ |
|
"task_id": datasets.Value("int32"), |
|
"mbpp_task_id": datasets.Value("int32"), |
|
"task": datasets.Value("string"), |
|
"test_cases": datasets.Sequence( |
|
{ |
|
"test_case_id": datasets.Value("int32"), |
|
"cot": datasets.Value("string"), |
|
"input": datasets.Value("string"), |
|
"output": datasets.Value("string") |
|
} |
|
) |
|
} |
|
) |
|
|
|
if self.config.name == "codefunctions": |
|
features = datasets.Features( |
|
{ |
|
"task_id": datasets.Value("int32"), |
|
"mbpp_task_id": datasets.Value("int32"), |
|
"description": datasets.Value("string"), |
|
"cot": datasets.Value("string"), |
|
"imports": datasets.Value("string"), |
|
"function_head": datasets.Value("string"), |
|
"function_body": datasets.Value("string") |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = _DATA_URLS[self.config.name] |
|
data = dl_manager.download_and_extract(urls) |
|
|
|
splits = [] |
|
|
|
if self.config.name == "tasks": |
|
splits = [datasets.Split.TRAIN] |
|
|
|
if self.config.name == "testcases" or self.config.name == "codefunctions": |
|
splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION] |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"filepath": data[split], |
|
}, |
|
) |
|
for split in splits |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, encoding="utf-8") as file: |
|
data = json.load(file) |
|
id_ = 0 |
|
for sample in data: |
|
yield id_, sample |
|
id_ += 1 |
|
|
|
|
|
from datasets import load_dataset |
|
|
|
def main(): |
|
|
|
dataset = load_dataset('C:\\Users\\klaud\\TeDriCSProj\\tedrics-data\\tedrics_data.py') |
|
print(dataset["train"]) |
|
print(dataset["train"][0]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|