Datasets:
File size: 4,441 Bytes
fe88bd9 284abdc fe88bd9 40a1887 fe88bd9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# 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 = """\
@article{zhou2022doccoder,
title={DocCoder: Generating Code by Retrieving and Reading Docs},
author={Zhou, Shuyan and Alon, Uri and Xu, Frank F and JIang, Zhengbao and Neubig, Graham},
journal={arXiv preprint arXiv:2207.05987},
year={2022}
}
"""
_DESCRIPTION = """This is the re-split of CoNaLa dataset. For each code snippet in the dev and test set, at least one function is held out from the training set. This split aims at testing a code generation model's capacity in generating unseen functions.
We further make sure that examples from the same StackOverflow post (same question_id before -) are in the same split."""
_HOMEPAGE = "https://github.com/shuyanzhou/docprompting"
_URLs = {
"docs": "conala-docs.jsonl",
"data": {"train": "conala-train.jsonl", "validation": "conala-dev.jsonl", "test": "conala-test.jsonl" },
}
class DocPromptingConala(datasets.GeneratorBasedBuilder):
"""The resplit of CoNaLa Code dataset."""
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="data",
version=datasets.Version("1.1.0"),
description=_DESCRIPTION,
),
datasets.BuilderConfig(name="docs", version=datasets.Version("1.1.0"), description=_DESCRIPTION),
]
DEFAULT_CONFIG_NAME = "data"
def _info(self):
if self.config.name == "data":
features=datasets.Features({"question_id": datasets.Value("string"),
"nl": datasets.Value("string"),
"cmd": datasets.Value("string"),
"oracle_man": datasets.Sequence(feature=datasets.Value("string")),
"canonical_cmd": datasets.Value("string"),
"cmd_name": datasets.Value("string"),
})
else:
features=datasets.Features({"doc_id": datasets.Value("string"),
"doc_content": 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 == "data":
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"},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": data_dir["validation"], "split": "validation"},
),
]
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 |