| |
| """TODO: Add a description here.""" |
|
|
|
|
| import csv |
| import json |
| import os |
| import re |
|
|
| import datasets |
| from datasets import Value |
|
|
|
|
| _CITATION = """\ |
| @article{recode_wang2022, |
| title = {ReCode: Robustness Evaluation of Code Generation Models}, |
| author = {Wang, Shiqi and |
| Zheng, Li and |
| Qian, Haifeng and |
| Yang, Chenghao and |
| Wang, Zijian and |
| Kumar, Varun and |
| Shang, Mingyue and |
| Tan, Samson and |
| Ray, Baishakhi and |
| Bhatia, Parminder and |
| Nallapati, Ramesh and |
| Ramanathan, Murali Krishna and |
| Roth, Dan and |
| Xiang, Bing}, |
| doi = {10.48550/arXiv.2212.10264}, |
| url = {https://arxiv.org/abs/2212.10264}, |
| keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL)}, |
| publisher = {arXiv}, |
| year = {2022}, |
| copyright = {Creative Commons Attribution 4.0 International} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| Perturbed version of HumanEval from: ReCode: Robustness Evaluation of Code Generation Models |
| """ |
|
|
| _HOMEPAGE = "https://github.com/amazon-science/recode" |
|
|
| |
| _LICENSE = "" |
|
|
| |
| |
| |
| _URLS = { |
| "nlaugmenter": "nlaugmenter.tar.gz", |
| "format": "format.tar.gz", |
| "natgen": "natgen.tar.gz", |
| "func_name": "func_name.tar.gz" |
| } |
|
|
|
|
| class PerturbedHumaneval(datasets.GeneratorBasedBuilder): |
| """TODO: Short description of my dataset.""" |
|
|
| VERSION = datasets.Version("1.1.0") |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig(name="format", version=VERSION, description="Perturbations to the format of partial completions"), |
| datasets.BuilderConfig(name="natgen", version=VERSION, description="NatGen perturbations on partial completions"), |
| datasets.BuilderConfig(name="func_name", version=VERSION, description="Perturbations on function names"), |
| datasets.BuilderConfig(name="nlaugmenter", version=VERSION, description="Perturbations on docstrings with NL-Augmenter"), |
| ] |
|
|
| |
|
|
| def _info(self): |
| if self.config.name in ["format", "natgen"]: |
| features = datasets.Features( |
| { |
| 'task_id': Value(dtype='string'), |
| 'prompt': Value(dtype='string'), |
| 'entry_point': Value(dtype='string'), 'canonical_solution': Value(dtype='string'), 'test': Value(dtype='string'), 'seed': Value(dtype="int32"), 'perturbation_name': Value(dtype='string'), 'partial': Value(dtype='string') |
| } |
| ) |
| elif self.config.name in ["func_name", "nlaugmenter"]: |
| features = datasets.Features( |
| { |
| 'task_id': Value(dtype='string'), 'prompt': Value(dtype='string'), 'entry_point': Value(dtype='string'), 'canonical_solution': Value(dtype='string'), 'test': Value(dtype='string'), 'seed': Value(dtype="int32"), 'perturbation_name': Value(dtype='string') |
| } |
| ) |
| else: |
| raise ValueError(f"Invalid configuration name {self.config.name}") |
| return datasets.DatasetInfo( |
| |
| description=_DESCRIPTION, |
| |
| features=features, |
| |
| |
| |
| |
| homepage=_HOMEPAGE, |
| |
| license=_LICENSE, |
| |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| |
| |
| |
| urls = _URLS[self.config.name] |
| |
| files = dl_manager.download_and_extract(urls) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| |
| gen_kwargs={ |
| "downloaded_files": dl_manager.iter_files(files), |
| |
| }, |
| ), |
| ] |
|
|
| |
| def _generate_examples(self, downloaded_files): |
| |
| |
| id_ = 0 |
| |
| |
| for file in downloaded_files: |
| |
| m = re.match(r'humaneval_([A-Za-z_\d]+)_s(\d+)\.jsonl', os.path.basename(file)) |
| assert m is not None, f"Unrecognized file-name: {file}" |
| perturbation_name = m.group(1) |
| seed = int(m.group(2)) |
| with open(file, encoding="utf-8") as f: |
| for row in f: |
| data = json.loads(row) |
| example = { |
| 'task_id': data['task_id'], |
| 'prompt': data['prompt'], |
| 'entry_point': data['entry_point'], |
| 'canonical_solution': data['canonical_solution'], |
| 'test': data['test'], |
| 'seed': seed, |
| 'perturbation_name': perturbation_name, |
| } |
| if self.config.name in ["format", "natgen"]: |
| example['partial'] = data["partial"] |
| |
| yield id_, example |
| id_ += 1 |
|
|