Datasets:
Tasks:
Text Retrieval
Formats:
parquet
Sub-tasks:
document-retrieval
Size:
100K - 1M
ArXiv:
License:
Convert dataset to Parquet (#5)
Browse files- Convert dataset to Parquet (bad29ae02f4650dffac1bcaeaaad545bfbcc9ec1)
- Delete loading script auxiliary file (40b5431dbbcddea8427674bf167a4f8046c0548e)
- Delete loading script (2d22038b0cdd7a18e53ab010fbbdd345690dea60)
- Delete loading script auxiliary file (f38ee8712c776ac49d99a846c2e06490aa660484)
Files changed (8)
- README.md+14-5
- code_x_glue_tc_nl_code_search_adv.pyDeleted-206
- common.pyDeleted-75
- data/test-00000-of-00001.parquetAdded+3
- data/train-00000-of-00002.parquetAdded+3
- data/train-00001-of-00002.parquetAdded+3
- data/validation-00000-of-00001.parquetAdded+3
- generated_definitions.pyDeleted-12
60 unmodified lines6162636465666768697071727374757660 unmodified linesdtype: float32splits:- name: trainnum_bytes: 820716084num_examples: 251820- name: validationnum_bytes: 23468834num_examples: 9604- name: testnum_bytes: 47433760num_examples: 19210download_size: 966025624dataset_size: 891618678---# Dataset Card for "code_x_glue_tc_nl_code_search_adv"60 unmodified lines6162636465666768697071727374757677787980818283848560 unmodified linesdtype: float32splits:- name: trainnum_bytes: 820714108num_examples: 251820- name: validationnum_bytes: 23468758num_examples: 9604- name: testnum_bytes: 47433608num_examples: 19210download_size: 316235421dataset_size: 891616474configs:- config_name: defaultdata_files:- split: trainpath: data/train-*- split: validationpath: data/validation-*- split: testpath: data/test-*---# Dataset Card for "code_x_glue_tc_nl_code_search_adv"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206import jsonimport osimport os.pathfrom typing import List
import datasets
from .common import TrainValidTestChildfrom .generated_definitions import DEFINITIONS
_DESCRIPTION = """The dataset we use comes from CodeSearchNet and we filter the dataset as the following:- Remove examples that codes cannot be parsed into an abstract syntax tree.- Remove examples that #tokens of documents is < 3 or >256- Remove examples that documents contain special tokens (e.g. <img ...> or https:...)- Remove examples that documents are not English."""_CITATION = """@article{husain2019codesearchnet,title={Codesearchnet challenge: Evaluating the state of semantic code search},author={Husain, Hamel and Wu, Ho-Hsiang and Gazit, Tiferet and Allamanis, Miltiadis and Brockschmidt, Marc},journal={arXiv preprint arXiv:1909.09436},year={2019}}"""
class CodeXGlueCtCodeToTextBaseImpl(TrainValidTestChild): _DESCRIPTION = _DESCRIPTION _CITATION = _CITATION
# For each file, each line in the uncompressed file represents one function. _FEATURES = { "id": datasets.Value("int32"), # Index of the sample "repo": datasets.Value("string"), # repo: the owner/repo "path": datasets.Value("string"), # path: the full path to the original file "func_name": datasets.Value("string"), # func_name: the function or method name "original_string": datasets.Value("string"), # original_string: the raw string before tokenization or parsing "language": datasets.Value("string"), # language: the programming language name "code": datasets.Value("string"), # code/function: the part of the original_string that is code "code_tokens": datasets.features.Sequence( datasets.Value("string") ), # code_tokens/function_tokens: tokenized version of code "docstring": datasets.Value( "string" ), # docstring: the top-level comment or docstring, if it exists in the original string "docstring_tokens": datasets.features.Sequence( datasets.Value("string") ), # docstring_tokens: tokenized version of docstring "sha": datasets.Value("string"), # sha of the file "url": datasets.Value("string"), # url of the file }
_SUPERVISED_KEYS = ["docstring", "docstring_tokens"]
def generate_urls(self, split_name, language): yield "language", f"https://huggingface.co/datasets/code_search_net/resolve/main/data/{language}.zip" yield "dataset", "dataset.zip"
def get_data_files(self, split_name, file_paths, language): language_specific_path = file_paths["language"] final_path = os.path.join(language_specific_path, language, "final") # Make some cleanup to save space for path in os.listdir(final_path): if path.endswith(".pkl"): os.unlink(path)
data_files = [] for root, dirs, files in os.walk(final_path): for file in files: temp = os.path.join(root, file) if ".jsonl" in temp: if split_name in temp: data_files.append(temp) return data_files
def post_process(self, split_name, language, js): return js
def _generate_examples(self, split_name, file_paths, language): import gzip
data_set_path = file_paths["dataset"]
data_files = self.get_data_files(split_name, file_paths, language)
urls = {} f1_path_parts = [data_set_path, "dataset", language, f"{split_name}.txt"] if self.SINGLE_LANGUAGE: del f1_path_parts[2]
f1_path = os.path.join(*f1_path_parts) with open(f1_path, encoding="utf-8") as f1: for line in f1: line = line.strip() urls[line] = True
idx = 0 for file in data_files: if ".gz" in file: f = gzip.open(file) else: f = open(file, encoding="utf-8")
for line in f: line = line.strip() js = json.loads(line) if js["url"] in urls: js["id"] = idx js = self.post_process(split_name, language, js) if "partition" in js: del js["partition"] yield idx, js idx += 1 f.close()
class CodeXGlueTcNLCodeSearchAdvImpl(CodeXGlueCtCodeToTextBaseImpl): LANGUAGE = "python" SINGLE_LANGUAGE = True
_FEATURES = { "id": datasets.Value("int32"), # Index of the sample "repo": datasets.Value("string"), # repo: the owner/repo "path": datasets.Value("string"), # path: the full path to the original file "func_name": datasets.Value("string"), # func_name: the function or method name "original_string": datasets.Value("string"), # original_string: the raw string before tokenization or parsing "language": datasets.Value("string"), # language: the programming language "code": datasets.Value("string"), # code/function: the part of the original_string that is code "code_tokens": datasets.features.Sequence( datasets.Value("string") ), # code_tokens/function_tokens: tokenized version of code "docstring": datasets.Value( "string" ), # docstring: the top-level comment or docstring, if it exists in the original string "docstring_tokens": datasets.features.Sequence( datasets.Value("string") ), # docstring_tokens: tokenized version of docstring "sha": datasets.Value("string"), # sha of the file "url": datasets.Value("string"), # url of the file "docstring_summary": datasets.Value("string"), # Summary of the docstring "parameters": datasets.Value("string"), # parameters of the function "return_statement": datasets.Value("string"), # return statement "argument_list": datasets.Value("string"), # list of arguments of the function "identifier": datasets.Value("string"), # identifier "nwo": datasets.Value("string"), # nwo "score": datasets.Value("float"), # score for this search }
def post_process(self, split_name, language, js): for suffix in "_tokens", "": key = "function" + suffix if key in js: js["code" + suffix] = js[key] del js[key]
for key in self._FEATURES: if key not in js: if key == "score": js[key] = -1 else: js[key] = ""
return js
def generate_urls(self, split_name): for e in super().generate_urls(split_name, self.LANGUAGE): yield e
def get_data_files(self, split_name, file_paths, language): if split_name == "train": return super().get_data_files(split_name, file_paths, language) else: data_set_path = file_paths["dataset"] data_file = os.path.join(data_set_path, "dataset", "test_code.jsonl") return [data_file]
def _generate_examples(self, split_name, file_paths): for e in super()._generate_examples(split_name, file_paths, self.LANGUAGE): yield e
CLASS_MAPPING = { "CodeXGlueTcNLCodeSearchAdv": CodeXGlueTcNLCodeSearchAdvImpl,}
class CodeXGlueTcNlCodeSearchAdv(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_and_extract(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:8fb129f32c5c83d58e906ee0f8a6cba513c371719af4331bc765d14314a7187bsize 16341074123version https://git-lfs.github.com/spec/v1oid sha256:91d821e7264a24335bc1da2b3e00529b9946611289a1cb71fa3fc1263b43273csize 144265486123version https://git-lfs.github.com/spec/v1oid sha256:1c576a6e59cf967476ec09d52c2436bb0a02f1079ba4507e5aea0bee48a27a74size 147039811123version https://git-lfs.github.com/spec/v1oid sha256:83324007473ad82297b0dc1d380cc7d14e709eae1f5f3e6bdf0c52ed0278e435size 8589050123456789101112DEFINITIONS = { "default": { "class_name": "CodeXGlueTcNLCodeSearchAdv", "dataset_type": "Text-Code", "description": "CodeXGLUE NL-code-search-Adv dataset, available at https://github.com/microsoft/CodeXGLUE/tree/main/Text-Code/NL-code-search-Adv", "dir_name": "NL-code-search-Adv", "name": "default", "project_url": "https://github.com/madlag/CodeXGLUE/tree/main/Text-Code/NL-code-search-Adv", "raw_url": "https://raw.githubusercontent.com/madlag/CodeXGLUE/main/Text-Code/NL-code-search-Adv", "sizes": {"test": 19210, "train": 251820, "validation": 9604}, }}README.md+14-5
code_x_glue_tc_nl_code_search_adv.pyDeleted-206
common.pyDeleted-75
data/test-00000-of-00001.parquetAdded+3
data/train-00000-of-00002.parquetAdded+3
data/train-00001-of-00002.parquetAdded+3
data/validation-00000-of-00001.parquetAdded+3
generated_definitions.pyDeleted-12