Convert dataset to Parquet
#5
by albertvillanova HF Staff - opened
Files changed (10)
- README.md+27-10
- code_x_glue_cc_code_refinement.pyDeleted-93
- common.pyDeleted-75
- generated_definitions.pyDeleted-24
- medium/test-00000-of-00001.parquetAdded+3
- medium/train-00000-of-00001.parquetAdded+3
- medium/validation-00000-of-00001.parquetAdded+3
- small/test-00000-of-00001.parquetAdded+3
- small/train-00000-of-00001.parquetAdded+3
- small/validation-00000-of-00001.parquetAdded+3
29 unmodified lines303132333435363738394041424344454 unmodified lines5051525354555657585960616263646529 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 32614834num_examples: 52364- name: validationnum_bytes: 4086741num_examples: 6546- name: testnum_bytes: 4063673num_examples: 6545download_size: 39979724dataset_size: 40765248- config_name: smallfeatures:- name: id4 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 13006719num_examples: 46680- name: validationnum_bytes: 1629250num_examples: 5835- name: testnum_bytes: 1619708num_examples: 5835download_size: 15555421dataset_size: 16255677---# Dataset Card for "code_x_glue_cc_code_refinement"29 unmodified lines303132333435363738394041424344454 unmodified lines50515253545556575859606162636465666768697071727374757677787980818229 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 32614786num_examples: 52364- name: validationnum_bytes: 4086733num_examples: 6546- name: testnum_bytes: 4063665num_examples: 6545download_size: 14929559dataset_size: 40765184- config_name: smallfeatures:- name: id4 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 13006679num_examples: 46680- name: validationnum_bytes: 1629242num_examples: 5835- name: testnum_bytes: 1619700num_examples: 5835download_size: 5894462dataset_size: 16255621configs:- config_name: mediumdata_files:- split: trainpath: medium/train-*- split: validationpath: medium/validation-*- split: testpath: medium/test-*- config_name: smalldata_files:- split: trainpath: small/train-*- split: validationpath: small/validation-*- split: testpath: small/test-*---# Dataset Card for "code_x_glue_cc_code_refinement"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293from typing import List
import datasets
from .common import TrainValidTestChildfrom .generated_definitions import DEFINITIONS
_DESCRIPTION = """We use the dataset released by this paper(https://arxiv.org/pdf/1812.08693.pdf). The source side is a Java function with bugs and the target side is the refined one. All the function and variable names are normalized. Their dataset contains two subsets ( i.e.small and medium) based on the function length."""_CITATION = """@article{10.1145/3340544,author = {Tufano, Michele and Watson, Cody and Bavota, Gabriele and Penta, Massimiliano Di and White, Martin and Poshyvanyk, Denys},title = {An Empirical Study on Learning Bug-Fixing Patches in the Wild via Neural Machine Translation},year = {2019},issue_date = {October 2019},publisher = {Association for Computing Machinery},address = {New York, NY, USA},volume = {28},number = {4},issn = {1049-331X},url = {https://doi-org.proxy.wm.edu/10.1145/3340544},doi = {10.1145/3340544},abstract = {Millions of open source projects with numerous bug fixes are available in code repositories. This proliferation of software development histories can be leveraged to learn how to fix common programming bugs. To explore such a potential, we perform an empirical study to assess the feasibility of using Neural Machine Translation techniques for learning bug-fixing patches for real defects. First, we mine millions of bug-fixes from the change histories of projects hosted on GitHub in order to extract meaningful examples of such bug-fixes. Next, we abstract the buggy and corresponding fixed code, and use them to train an Encoder-Decoder model able to translate buggy code into its fixed version. In our empirical investigation, we found that such a model is able to fix thousands of unique buggy methods in the wild. Overall, this model is capable of predicting fixed patches generated by developers in 9--50% of the cases, depending on the number of candidate patches we allow it to generate. Also, the model is able to emulate a variety of different Abstract Syntax Tree operations and generate candidate patches in a split second.},journal = {ACM Trans. Softw. Eng. Methodol.},month = sep,articleno = {19},numpages = {29},keywords = {bug-fixes, Neural machine translation}}"""
class CodeXGlueCcCodeRefinementImpl(TrainValidTestChild): _DESCRIPTION = _DESCRIPTION _CITATION = _CITATION
_FEATURES = { "id": datasets.Value("int32"), # Index of the sample "buggy": datasets.Value("string"), # The buggy version of the code "fixed": datasets.Value("string"), # The correct version of the code }
_SUPERVISED_KEYS = ["fixed"]
def generate_urls(self, split_name): size = self.info["parameters"]["size"] for key in "buggy", "fixed": yield key, f"{size}/{split_name}.buggy-fixed.{key}"
def _generate_examples(self, split_name, file_paths): """This function returns the examples in the raw (text) form.""" # Open each file (one for java, and one for c#) files = {k: open(file_paths[k], encoding="utf-8") for k in file_paths}
id_ = 0 while True: # Read a single line from each file entries = {k: files[k].readline() for k in file_paths}
empty = self.check_empty(entries) if empty: # We are done: end of files return
entries["id"] = id_ yield id_, entries id_ += 1
CLASS_MAPPING = { "CodeXGlueCcCodeRefinement": CodeXGlueCcCodeRefinementImpl,}
class CodeXGlueCcCodeRefinement(datasets.GeneratorBasedBuilder): BUILDER_CONFIG_CLASS = datasets.BuilderConfig BUILDER_CONFIGS = [ datasets.BuilderConfig(name=name, description=info["description"]) for name, info in DEFINITIONS.items() ]
def _info(self): name = self.config.name info = DEFINITIONS[name] if info["class_name"] in CLASS_MAPPING: self.child = CLASS_MAPPING[info["class_name"]](info) else: raise RuntimeError(f"Unknown python class for dataset configuration {name}") ret = self.child._info() return ret
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: return self.child._split_generators(dl_manager=dl_manager)
def _generate_examples(self, split_name, file_paths): return self.child._generate_examples(split_name, file_paths)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475from typing import List
import datasets
# Citation, taken from https://github.com/microsoft/CodeXGLUE_DEFAULT_CITATION = """@article{CodeXGLUE, title={CodeXGLUE: A Benchmark Dataset and Open Challenge for Code Intelligence}, year={2020},}"""
class Child: _DESCRIPTION = None _FEATURES = None _CITATION = None SPLITS = {"train": datasets.Split.TRAIN} _SUPERVISED_KEYS = None
def __init__(self, info): self.info = info
def homepage(self): return self.info["project_url"]
def _info(self): # This is the description that will appear on the datasets page. return datasets.DatasetInfo( description=self.info["description"] + "\n\n" + self._DESCRIPTION, features=datasets.Features(self._FEATURES), homepage=self.homepage(), citation=self._CITATION or _DEFAULT_CITATION, supervised_keys=self._SUPERVISED_KEYS, )
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: SPLITS = self.SPLITS _URL = self.info["raw_url"] urls_to_download = {} for split in SPLITS: if split not in urls_to_download: urls_to_download[split] = {}
for key, url in self.generate_urls(split): if not url.startswith("http"): url = _URL + "/" + url urls_to_download[split][key] = url
downloaded_files = {} for k, v in urls_to_download.items(): downloaded_files[k] = dl_manager.download(v)
return [ datasets.SplitGenerator( name=SPLITS[k], gen_kwargs={"split_name": k, "file_paths": downloaded_files[k]}, ) for k in SPLITS ]
def check_empty(self, entries): all_empty = all([v == "" for v in entries.values()]) all_non_empty = all([v != "" for v in entries.values()])
if not all_non_empty and not all_empty: raise RuntimeError("Parallel data files should have the same number of lines.")
return all_empty
class TrainValidTestChild(Child): SPLITS = { "train": datasets.Split.TRAIN, "valid": datasets.Split.VALIDATION, "test": datasets.Split.TEST, }123456789101112131415161718192021222324DEFINITIONS = { "medium": { "class_name": "CodeXGlueCcCodeRefinement", "dataset_type": "Code-Code", "description": "CodeXGLUE code-refinement dataset, available at https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/code-refinement", "dir_name": "code-refinement", "name": "medium", "parameters": {"size": "medium"}, "project_url": "https://github.com/madlag/CodeXGLUE/tree/main/Code-Code/code-refinement", "raw_url": "https://raw.githubusercontent.com/madlag/CodeXGLUE/main/Code-Code/code-refinement/data", "sizes": {"test": 6545, "train": 52364, "validation": 6546}, }, "small": { "class_name": "CodeXGlueCcCodeRefinement", "dataset_type": "Code-Code", "description": "CodeXGLUE code-refinement dataset, available at https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/code-refinement", "dir_name": "code-refinement", "name": "small", "parameters": {"size": "small"}, "project_url": "https://github.com/madlag/CodeXGLUE/tree/main/Code-Code/code-refinement", "raw_url": "https://raw.githubusercontent.com/madlag/CodeXGLUE/main/Code-Code/code-refinement/data", "sizes": {"test": 5835, "train": 46680, "validation": 5835}, },}123version https://git-lfs.github.com/spec/v1oid sha256:776766b34878a999193dae39f0462ed1dc5aec3b7d219d3488db4c0127eca858size 1488083123version https://git-lfs.github.com/spec/v1oid sha256:955496550f8603dd920aa2a09d1e4a14d878bda9f35f2f3575bae68b9d9493f0size 11943277123version https://git-lfs.github.com/spec/v1oid sha256:9eb660729a7a43df19c714726933a517d0497cefa99cb95328bc964658eaa44csize 1498199123version https://git-lfs.github.com/spec/v1oid sha256:be9b78909122cc07a9b31b55c999fe8b8346b1bd775e726b0cbb044f9d1ebc90size 588578123version https://git-lfs.github.com/spec/v1oid sha256:6e0ddaf02afd36f2827d0f6edcf94b3b6b5908206cbf63fc6ac99ee4a6332472size 4715251123version https://git-lfs.github.com/spec/v1oid sha256:b623a6544959b1767eb3082064b3b3896e26f0770dfd2270d14d4e62da0246a5size 590633README.md+27-10
code_x_glue_cc_code_refinement.pyDeleted-93
common.pyDeleted-75
generated_definitions.pyDeleted-24
medium/test-00000-of-00001.parquetAdded+3
medium/train-00000-of-00001.parquetAdded+3
medium/validation-00000-of-00001.parquetAdded+3
small/test-00000-of-00001.parquetAdded+3
small/train-00000-of-00001.parquetAdded+3
small/validation-00000-of-00001.parquetAdded+3