Datasets:
Download conala.py from neulab/conala: direct link, hf CLI and curl.
- Browser
- Download file 4.3 kB
-
https://huggingface.co/datasets/neulab/conala/resolve/refs%2Fpr%2F1/conala.py
- Command line
-
hf download hf://datasets/neulab/conala@refs/pr/1/conala.py
-
curl -L -o conala.py https://huggingface.co/datasets/neulab/conala/resolve/refs%2Fpr%2F1/conala.py
4.3 kB
| # coding=utf-8 | |
| # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """CoNaLa dataset.""" | |
| import json | |
| import datasets | |
| _CITATION = """\ | |
| @inproceedings{yin2018learning, | |
| title={Learning to mine aligned code and natural language pairs from stack overflow}, | |
| author={Yin, Pengcheng and Deng, Bowen and Chen, Edgar and Vasilescu, Bogdan and Neubig, Graham}, | |
| booktitle={2018 IEEE/ACM 15th international conference on mining software repositories (MSR)}, | |
| pages={476--486}, | |
| year={2018}, | |
| organization={IEEE} | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| CoNaLa is a dataset of code and natural language pairs crawled from Stack Overflow, for more details please refer to this paper: https://arxiv.org/pdf/1805.08949.pdf or the dataset page https://conala-corpus.github.io/. | |
| """ | |
| _HOMEPAGE = "https://conala-corpus.github.io/" | |
| _URLs = { | |
| "mined": "data/conala-mined.json", | |
| "curated": {"train": "data/conala-paired-train.json", "test": "data/conala-paired-test.json" }, | |
| } | |
| class Conala(datasets.GeneratorBasedBuilder): | |
| """CoNaLa Code dataset.""" | |
| VERSION = datasets.Version("1.1.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name="curated", | |
| version=datasets.Version("1.1.0"), | |
| description=_DESCRIPTION, | |
| ), | |
| datasets.BuilderConfig(name="mined", version=datasets.Version("1.1.0"), description=_DESCRIPTION), | |
| ] | |
| DEFAULT_CONFIG_NAME = "curated" | |
| def _info(self): | |
| if self.config.name == "curated": | |
| features=datasets.Features({"question_id": datasets.Value("int64"), | |
| "intent": datasets.Value("string"), | |
| "rewritten_intent": datasets.Value("string"), | |
| "snippet": datasets.Value("string"), | |
| }) | |
| else: | |
| features=datasets.Features({"question_id": datasets.Value("int64"), | |
| "parent_answer_post_id": datasets.Value("int64"), | |
| "prob": datasets.Value("float64"), | |
| "snippet": datasets.Value("string"), | |
| "intent": datasets.Value("string"), | |
| "id": datasets.Value("string"), | |
| }) | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=features, | |
| supervised_keys=None, | |
| citation=_CITATION, | |
| homepage=_HOMEPAGE) | |
| def _split_generators(self, dl_manager): | |
| """Returns SplitGenerators.""" | |
| config_urls = _URLs[self.config.name] | |
| data_dir = dl_manager.download_and_extract(config_urls) | |
| if self.config.name == "curated": | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={"filepath": data_dir["train"], "split": "train"}, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TEST, | |
| gen_kwargs={"filepath": data_dir["test"], "split": "test"}, | |
| ), | |
| ] | |
| else: | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={"filepath": data_dir, "split": "train"}, | |
| ), | |
| ] | |
| def _generate_examples(self, filepath, split): | |
| key = 0 | |
| for line in open(filepath, encoding="utf-8"): | |
| line = json.loads(line) | |
| yield key, line | |
| key += 1 |