Datasets:
Tasks:
Translation
Modalities:
Text
Formats:
parquet
Languages:
code
Size:
10K - 100K
ArXiv:
Tags:
code-to-code
License:
Convert dataset to Parquet (#4)
Browse files- Convert dataset to Parquet (f18c1083190b63c04aa75a523272a99a94784863)
- Delete loading script (946dd8dff11a705b83836687d2051d8429c23844)
- Delete loading script auxiliary file (c16948ddc82f70bbe3ca778dc91382d71b334cd7)
- Delete loading script auxiliary file (f9b0bc0e4d8417416690684915dcdfe3627729ab)
Files changed (7)
- README.md+14-5
- code_x_glue_cc_code_to_code_trans.pyDeleted-101
- common.pyDeleted-75
- data/test-00000-of-00001.parquetAdded+3
- data/train-00000-of-00001.parquetAdded+3
- data/validation-00000-of-00001.parquetAdded+3
- generated_definitions.pyDeleted-12
28 unmodified lines2930313233343536373839404142434428 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 4372657num_examples: 10300- name: validationnum_bytes: 226415num_examples: 500- name: testnum_bytes: 418595num_examples: 1000download_size: 4876035dataset_size: 5017667---# Dataset Card for "code_x_glue_cc_code_to_code_trans"28 unmodified lines2930313233343536373839404142434445464748495051525328 unmodified linesdtype: stringsplits:- name: trainnum_bytes: 4372641num_examples: 10300- name: validationnum_bytes: 226407num_examples: 500- name: testnum_bytes: 418587num_examples: 1000download_size: 2064764dataset_size: 5017635configs:- config_name: defaultdata_files:- split: trainpath: data/train-*- split: validationpath: data/validation-*- split: testpath: data/test-*---# Dataset Card for "code_x_glue_cc_code_to_code_trans"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101from typing import List
import datasets
from .common import TrainValidTestChildfrom .generated_definitions import DEFINITIONS
_DESCRIPTION = """The dataset is collected from several public repos, including Lucene(http://lucene.apache.org/), POI(http://poi.apache.org/), JGit(https://github.com/eclipse/jgit/) and Antlr(https://github.com/antlr/). We collect both the Java and C# versions of the codes and find the parallel functions. After removing duplicates and functions with the empty body, we split the whole dataset into training, validation and test sets."""_CITATION = """@article{DBLP:journals/corr/abs-2102-04664, author = {Shuai Lu and Daya Guo and Shuo Ren and Junjie Huang and Alexey Svyatkovskiy and Ambrosio Blanco and Colin B. Clement and Dawn Drain and Daxin Jiang and Duyu Tang and Ge Li and Lidong Zhou and Linjun Shou and Long Zhou and Michele Tufano and Ming Gong and Ming Zhou and Nan Duan and Neel Sundaresan and Shao Kun Deng and Shengyu Fu and Shujie Liu}, title = {CodeXGLUE: {A} Machine Learning Benchmark Dataset for Code Understanding and Generation}, journal = {CoRR}, volume = {abs/2102.04664}, year = {2021}}"""
class CodeXGlueCcCodeToCodeTransImpl(TrainValidTestChild): _DESCRIPTION = _DESCRIPTION _CITATION = _CITATION
_FEATURES = { "id": datasets.Value("int32"), # Index of the sample "java": datasets.Value("string"), # The java version of the code "cs": datasets.Value("string"), # The C# version of the code }
def generate_urls(self, split_name): for key in "cs", "java": yield key, f"{split_name}.java-cs.txt.{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 = { "CodeXGlueCcCodeToCodeTrans": CodeXGlueCcCodeToCodeTransImpl,}
class CodeXGlueCcCodeToCodeTrans(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, }123version https://git-lfs.github.com/spec/v1oid sha256:6f85e7a4685883fd9d95c0a1cb743e8ca2f17553b59a4f7b8967e515e7488b94size 169864123version https://git-lfs.github.com/spec/v1oid sha256:670d745b939f8f065e207558306d10200ad07e2de02e1b533070ad3b1957cb56size 1804099123version https://git-lfs.github.com/spec/v1oid sha256:7074b5b5e913273e03153931f39fdfcfbacd9db9aa85d4dc0f7af4b77c50e311size 90801123456789101112DEFINITIONS = { "default": { "class_name": "CodeXGlueCcCodeToCodeTrans", "dataset_type": "Code-Code", "description": "CodeXGLUE code-to-code-trans dataset, available at https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/code-to-code-trans", "dir_name": "code-to-code-trans", "name": "default", "project_url": "https://github.com/madlag/CodeXGLUE/tree/main/Code-Code/code-to-code-trans", "raw_url": "https://raw.githubusercontent.com/madlag/CodeXGLUE/main/Code-Code/code-to-code-trans/data", "sizes": {"test": 1000, "train": 10300, "validation": 500}, }}README.md+14-5
code_x_glue_cc_code_to_code_trans.pyDeleted-101
common.pyDeleted-75
data/test-00000-of-00001.parquetAdded+3
data/train-00000-of-00001.parquetAdded+3
data/validation-00000-of-00001.parquetAdded+3
generated_definitions.pyDeleted-12