| import os |
| import glob |
| import json |
|
|
| import datasets |
|
|
| _VERSION = datasets.Version("1.0.0", "") |
|
|
| _URL = "" |
|
|
| _CITATION = """\ |
| There is no citation information |
| """ |
|
|
| _DESCRIPTION = """\ |
| simple code knowledge eval dataset loading script |
| """ |
|
|
| TRAIN_FILE = "train.json" |
| VALIDATION_FILE = "validation.json" |
| TEST_FILE = "test.json" |
|
|
|
|
| def generator(fpath): |
| with open(fpath, "r") as f: |
| in_json = json.load(f) |
| for item in in_json: |
| yield { |
| "content": item["content"], |
| "label": str(item["score"]), |
| "lang": item["lang"], |
| "repo_name": item["repo_name"], |
| "repo_path": item["repo_path"], |
| "repo_licenses": item["repo_licenses"], |
| } |
| |
| class CodeKnowledgeEvalDataset(datasets.GeneratorBasedBuilder): |
| """Code Knowledge Evaluation Dataset""" |
|
|
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig( |
| name="default", |
| version=_VERSION, |
| description="Code Knowledge Evaluation Dataset", |
| ) |
| ] |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| "content": datasets.Value("string"), |
| "label": datasets.ClassLabel(num_classes=6, names=['0', '1', '2', '3', '4', '5']), |
| "lang": datasets.Value("string"), |
| "repo_name": datasets.Value("string"), |
| "repo_path": datasets.Value("string"), |
| "repo_licenses": datasets.Sequence(feature=datasets.Value("string")), |
| } |
| ), |
| supervised_keys=None, |
| homepage=_URL, |
| citation=_CITATION, |
| |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
|
| path_kv = { |
| datasets.Split.TRAIN: TRAIN_FILE, |
| datasets.Split.VALIDATION: VALIDATION_FILE, |
| datasets.Split.TEST: TEST_FILE, |
| } |
| |
|
|
| return [ |
| datasets.SplitGenerator(name=k, gen_kwargs={'fpath': v}) for k, v in path_kv.items() |
| ] |
|
|
| def _generate_examples(self, fpath): |
| """Yields examples.""" |
| for idx, item in enumerate(generator(fpath)): |
| yield idx, item |
|
|