Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
code
Size:
100K - 1M
ArXiv:
License:
add dataset script
Browse files- xlcost-text-to-code.py +221 -0
xlcost-text-to-code.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""APPS dataset."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
import datasets
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
_CITATION = """\
|
| 23 |
+
@misc{zhu2022xlcost,
|
| 24 |
+
title = {XLCoST: A Benchmark Dataset for Cross-lingual Code Intelligence},
|
| 25 |
+
url = {https://arxiv.org/abs/2206.08474},
|
| 26 |
+
author = {Zhu, Ming and Jain, Aneesh and Suresh, Karthik and Ravindran, Roshan and Tipirneni, Sindhu and Reddy, Chandan K.},
|
| 27 |
+
year = {2022},
|
| 28 |
+
eprint={2206.08474},
|
| 29 |
+
archivePrefix={arXiv}
|
| 30 |
+
}
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
_DESCRIPTION = """\
|
| 34 |
+
XLCoST is a machine learning benchmark dataset that contains fine-grained parallel data in 7 commonly used programming languages (C++, Java, Python, C#, Javascript, PHP, C), and natural language (English)."""
|
| 35 |
+
|
| 36 |
+
_HOMEPAGE = "https://github.com/reddy-lab-code-research/XLCoST"
|
| 37 |
+
_URLS = {
|
| 38 |
+
"train": "train.json",
|
| 39 |
+
"test": "test.json",
|
| 40 |
+
"valid": "valid.json",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def new_url(name):
|
| 44 |
+
urls = {"train": f"data/{name}/{_URLS['train']}",
|
| 45 |
+
"test": f"data/{name}/{_URLS['test']}",
|
| 46 |
+
"valid": f"data/{name}/{_URLS['valid']}"}
|
| 47 |
+
return urls
|
| 48 |
+
|
| 49 |
+
class XlcostConfig(datasets.BuilderConfig):
|
| 50 |
+
"""BuilderConfig for SuperGLUE."""
|
| 51 |
+
|
| 52 |
+
def __init__(self, name, description, features, **kwargs):
|
| 53 |
+
#super().__init__(name, description, features, version=datasets.Version("2.1.0"), **kwargs,) #=datasets.Version("2.1.0")
|
| 54 |
+
super(XlcostConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
|
| 55 |
+
self.name = name
|
| 56 |
+
self.description = description
|
| 57 |
+
self.features = features
|
| 58 |
+
|
| 59 |
+
def split_generator(dl_manager, name):
|
| 60 |
+
downloaded_files = new_url(name)
|
| 61 |
+
downloaded_files = dl_manager.download(new_url(name))
|
| 62 |
+
return [
|
| 63 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 64 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 65 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
class Xlcost(datasets.GeneratorBasedBuilder):
|
| 69 |
+
"""The SuperGLUE benchmark."""
|
| 70 |
+
VERSION = datasets.Version("2.1.0")
|
| 71 |
+
BUILDER_CONFIGS = [
|
| 72 |
+
XlcostConfig(
|
| 73 |
+
name="Python-snippet-level",
|
| 74 |
+
#version=VERSION,
|
| 75 |
+
description="snippet level text and code pairs for Python",
|
| 76 |
+
features=["text", "code"]
|
| 77 |
+
),
|
| 78 |
+
XlcostConfig(
|
| 79 |
+
name="Python-program-level",
|
| 80 |
+
#version=VERSION,
|
| 81 |
+
description="program level text and code pairs for Python",
|
| 82 |
+
features=["text", "code"]
|
| 83 |
+
),
|
| 84 |
+
|
| 85 |
+
XlcostConfig(
|
| 86 |
+
name="C-snippet-level",
|
| 87 |
+
#version=VERSION,
|
| 88 |
+
description="snippet level text and code pairs for C",
|
| 89 |
+
features=["text", "code"]
|
| 90 |
+
),
|
| 91 |
+
XlcostConfig(
|
| 92 |
+
name="C-program-level",
|
| 93 |
+
#version=VERSION,
|
| 94 |
+
description="program level text and code pairs for C",
|
| 95 |
+
features=["text", "code"]
|
| 96 |
+
),
|
| 97 |
+
|
| 98 |
+
XlcostConfig(
|
| 99 |
+
name="Java-snippet-level",
|
| 100 |
+
#version=VERSION,
|
| 101 |
+
description="snippet level text and code pairs for Java",
|
| 102 |
+
features=["text", "code"]
|
| 103 |
+
),
|
| 104 |
+
XlcostConfig(
|
| 105 |
+
name="Java-program-level",
|
| 106 |
+
#version=VERSION,
|
| 107 |
+
description="program level text and code pairs for Java",
|
| 108 |
+
features=["text", "code"]
|
| 109 |
+
),
|
| 110 |
+
|
| 111 |
+
XlcostConfig(
|
| 112 |
+
name="Javascript-snippet-level",
|
| 113 |
+
#version=VERSION,
|
| 114 |
+
description="snippet level text and code pairs for PHP",
|
| 115 |
+
features=["text", "code"]
|
| 116 |
+
),
|
| 117 |
+
XlcostConfig(
|
| 118 |
+
name="Javascript-program-level",
|
| 119 |
+
#version=VERSION,
|
| 120 |
+
description="program level text and code pairs for PHP",
|
| 121 |
+
features=["text", "code"]
|
| 122 |
+
),
|
| 123 |
+
|
| 124 |
+
XlcostConfig(
|
| 125 |
+
name="Csharp-snippet-level",
|
| 126 |
+
#version=VERSION,
|
| 127 |
+
description="snippet level text and code pairs for C#",
|
| 128 |
+
features=["text", "code"]
|
| 129 |
+
),
|
| 130 |
+
XlcostConfig(
|
| 131 |
+
name="Csharp-program-level",
|
| 132 |
+
#version=VERSION,
|
| 133 |
+
description="program level text and code pairs for C#",
|
| 134 |
+
features=["text", "code"]
|
| 135 |
+
),
|
| 136 |
+
|
| 137 |
+
XlcostConfig(
|
| 138 |
+
name="C++-snippet-level",
|
| 139 |
+
#version=VERSION,
|
| 140 |
+
description="snippet level text and code pairs for C#",
|
| 141 |
+
features=["text", "code"]
|
| 142 |
+
),
|
| 143 |
+
XlcostConfig(
|
| 144 |
+
name="C++-program-level",
|
| 145 |
+
#version=VERSION,
|
| 146 |
+
description="program level text and code pairs for C#",
|
| 147 |
+
features=["text", "code"]
|
| 148 |
+
),
|
| 149 |
+
|
| 150 |
+
XlcostConfig(
|
| 151 |
+
name="PHP-snippet-level",
|
| 152 |
+
#version=VERSION,
|
| 153 |
+
description="snippet level text and code pairs for PHP",
|
| 154 |
+
features=["text", "code"]
|
| 155 |
+
),
|
| 156 |
+
XlcostConfig(
|
| 157 |
+
name="PHP-program-level",
|
| 158 |
+
#version=VERSION,
|
| 159 |
+
description="program level text and code pairs for PHP",
|
| 160 |
+
features=["text", "code"]
|
| 161 |
+
),
|
| 162 |
+
]
|
| 163 |
+
DEFAULT_CONFIG_NAME = "C-snippet-level"
|
| 164 |
+
|
| 165 |
+
def _info(self):
|
| 166 |
+
return datasets.DatasetInfo(
|
| 167 |
+
description=_DESCRIPTION,
|
| 168 |
+
features=datasets.Features({"text": datasets.Value("string"),
|
| 169 |
+
"code": datasets.Value("string")}),
|
| 170 |
+
homepage=_HOMEPAGE,
|
| 171 |
+
citation=_CITATION,
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
def _split_generators(self, dl_manager):
|
| 175 |
+
if self.config.name == "Python-snippet-level":
|
| 176 |
+
return split_generator(dl_manager, self.config.name)
|
| 177 |
+
|
| 178 |
+
elif self.config.name == "Python-program-level":
|
| 179 |
+
return split_generator(dl_manager, self.config.name)
|
| 180 |
+
|
| 181 |
+
elif self.config.name == "C-snippet-level":
|
| 182 |
+
return split_generator(dl_manager, self.config.name)
|
| 183 |
+
|
| 184 |
+
elif self.config.name == "C-program-level":
|
| 185 |
+
return split_generator(dl_manager, self.config.name)
|
| 186 |
+
|
| 187 |
+
elif self.config.name == "Java-snippet-level":
|
| 188 |
+
return split_generator(dl_manager, self.config.name)
|
| 189 |
+
|
| 190 |
+
elif self.config.name == "Java-program-level":
|
| 191 |
+
return split_generator(dl_manager, self.config.name)
|
| 192 |
+
|
| 193 |
+
elif self.config.name == "Javascript-snippet-level":
|
| 194 |
+
return split_generator(dl_manager, self.config.name)
|
| 195 |
+
|
| 196 |
+
elif self.config.name == "Javascript-program-level":
|
| 197 |
+
return split_generator(dl_manager, self.config.name)
|
| 198 |
+
|
| 199 |
+
elif self.config.name == "Csharp-snippet-level":
|
| 200 |
+
return split_generator(dl_manager, self.config.name)
|
| 201 |
+
|
| 202 |
+
elif self.config.name == "Csharp-program-level":
|
| 203 |
+
return split_generator(dl_manager, self.config.name)
|
| 204 |
+
|
| 205 |
+
elif self.config.name == "PHP-snippet-level":
|
| 206 |
+
return split_generator(dl_manager, self.config.name)
|
| 207 |
+
|
| 208 |
+
elif self.config.name == "PHP-program-level":
|
| 209 |
+
return split_generator(dl_manager, self.config.name)
|
| 210 |
+
|
| 211 |
+
def _generate_examples(self, filepath):
|
| 212 |
+
key = 0
|
| 213 |
+
with open(filepath) as f:
|
| 214 |
+
for line in f:
|
| 215 |
+
row = json.loads(line)
|
| 216 |
+
key += 1
|
| 217 |
+
yield key, {
|
| 218 |
+
"text": row["text"],
|
| 219 |
+
"code": row["code"],
|
| 220 |
+
}
|
| 221 |
+
key += 1
|