Datasets:
Tasks:
Question Answering
Modalities:
Text
Sub-tasks:
extractive-qa
Languages:
code
Size:
100K - 1M
License:
Refactor data load script with recent updates
Browse files- codequeries.py +53 -26
codequeries.py
CHANGED
@@ -13,12 +13,10 @@
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License.
|
15 |
|
16 |
-
"""The CodeQueries benchmark."""
|
17 |
|
18 |
|
19 |
import json
|
20 |
-
import os
|
21 |
-
|
22 |
import datasets
|
23 |
|
24 |
logger = datasets.logging.get_logger(__name__)
|
@@ -58,6 +56,8 @@ class CodequeriesConfig(datasets.BuilderConfig):
|
|
58 |
features: `list[string]`, list of the features that will appear in the
|
59 |
feature dict. Should not include "label".
|
60 |
citation: `string`, citation for the data set.
|
|
|
|
|
61 |
**kwargs: keyword arguments forwarded to super.
|
62 |
"""
|
63 |
# Version history:
|
@@ -76,8 +76,9 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
76 |
CodequeriesConfig(
|
77 |
name="ideal",
|
78 |
description=_IDEAL_DESCRIPTION,
|
79 |
-
features=["query_name", "
|
80 |
-
"
|
|
|
81 |
"subtokenized_input_sequence", "label_sequence"],
|
82 |
citation=_CODEQUERIES_CITATION,
|
83 |
data_url={
|
@@ -85,43 +86,47 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
85 |
"dev": "ideal_val.json",
|
86 |
"test": "ideal_test.json"
|
87 |
},
|
88 |
-
url="",
|
89 |
),
|
90 |
CodequeriesConfig(
|
91 |
name="prefix",
|
92 |
description=_PREFIX_DESCRIPTION,
|
93 |
-
features=["query_name", "
|
94 |
-
"
|
|
|
95 |
"subtokenized_input_sequence", "label_sequence"],
|
96 |
citation=_CODEQUERIES_CITATION,
|
97 |
data_url={
|
98 |
"test": "prefix_test.json"
|
99 |
},
|
100 |
-
url="",
|
101 |
),
|
102 |
CodequeriesConfig(
|
103 |
name="file_ideal",
|
104 |
description=_FILE_IDEAL_DESCRIPTION,
|
105 |
-
features=["query_name", "
|
106 |
-
"
|
|
|
107 |
"subtokenized_input_sequence", "label_sequence"],
|
108 |
citation=_CODEQUERIES_CITATION,
|
109 |
data_url={
|
110 |
"test": "file_ideal_test.json"
|
111 |
},
|
112 |
-
url="",
|
113 |
),
|
114 |
CodequeriesConfig(
|
115 |
name="twostep",
|
116 |
description=_TWOSTEP_DESCRIPTION,
|
117 |
-
features=["query_name", "
|
118 |
-
"
|
119 |
-
"
|
|
|
|
|
120 |
citation=_CODEQUERIES_CITATION,
|
121 |
data_url={
|
122 |
"test": ["twostep_relevance/" + "twostep_relevance_test_" + str(i) + ".json" for i in range(0,10)]
|
123 |
},
|
124 |
-
url="",
|
125 |
),
|
126 |
]
|
127 |
|
@@ -130,11 +135,13 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
130 |
def _info(self):
|
131 |
features = {}
|
132 |
features["query_name"] = datasets.Value("string")
|
|
|
133 |
features["context_blocks"] = [
|
134 |
{
|
135 |
"content": datasets.Value("string"),
|
136 |
"metadata": datasets.Value("string"),
|
137 |
-
"header": datasets.Value("string")
|
|
|
138 |
}
|
139 |
]
|
140 |
features["answer_spans"] = [
|
@@ -155,11 +162,11 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
155 |
'end_column': datasets.Value("int32")
|
156 |
}
|
157 |
]
|
158 |
-
features["
|
159 |
-
features["
|
160 |
features["subtokenized_input_sequence"] = datasets.features.Sequence(datasets.Value("string"))
|
161 |
-
features["label_sequence"] = datasets.features.Sequence(datasets.Value("
|
162 |
-
features["relevance_label"] = datasets.Value("
|
163 |
|
164 |
return datasets.DatasetInfo(
|
165 |
description=self.config.description,
|
@@ -170,7 +177,7 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
170 |
|
171 |
def _split_generators(self, dl_manager):
|
172 |
dl_dir = dl_manager.download_and_extract(self.config.data_url)
|
173 |
-
|
174 |
if self.config.name in ["prefix", "file_ideal", "twostep"]:
|
175 |
return [
|
176 |
datasets.SplitGenerator(
|
@@ -209,7 +216,7 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
209 |
def _generate_examples(self, filepath, split):
|
210 |
if self.config.name in ["prefix", "file_ideal", "twostep"]:
|
211 |
assert split == datasets.Split.TEST
|
212 |
-
logger.info("
|
213 |
|
214 |
if self.config.name == "twostep":
|
215 |
key = 0
|
@@ -221,15 +228,35 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
221 |
instance_key = str(key) + "_" + row["query_name"] + "_" + row["code_file_path"]
|
222 |
yield instance_key, {
|
223 |
"query_name": row["query_name"],
|
|
|
224 |
"context_blocks": row["context_blocks"],
|
225 |
"answer_spans": row["answer_spans"],
|
226 |
"supporting_fact_spans": row["supporting_fact_spans"],
|
227 |
-
"code_file_path": row["code_file_path"],
|
228 |
"example_type": row["example_type"],
|
|
|
229 |
"subtokenized_input_sequence": row["subtokenized_input_sequence"],
|
|
|
230 |
"relevance_label": row["relevance_label"],
|
231 |
}
|
232 |
key += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
else:
|
234 |
with open(filepath, encoding="utf-8") as f:
|
235 |
key = 0
|
@@ -239,13 +266,13 @@ class Codequeries(datasets.GeneratorBasedBuilder):
|
|
239 |
instance_key = str(key) + "_" + row["query_name"] + "_" + row["code_file_path"]
|
240 |
yield instance_key, {
|
241 |
"query_name": row["query_name"],
|
|
|
242 |
"context_blocks": row["context_blocks"],
|
243 |
"answer_spans": row["answer_spans"],
|
244 |
"supporting_fact_spans": row["supporting_fact_spans"],
|
245 |
-
"code_file_path": row["code_file_path"],
|
246 |
"example_type": row["example_type"],
|
|
|
247 |
"subtokenized_input_sequence": row["subtokenized_input_sequence"],
|
248 |
"label_sequence": row["label_sequence"],
|
249 |
}
|
250 |
key += 1
|
251 |
-
|
|
|
13 |
# See the License for the specific language governing permissions and
|
14 |
# limitations under the License.
|
15 |
|
16 |
+
"""CodeQueries: The CodeQueries benchmark dataset."""
|
17 |
|
18 |
|
19 |
import json
|
|
|
|
|
20 |
import datasets
|
21 |
|
22 |
logger = datasets.logging.get_logger(__name__)
|
|
|
56 |
features: `list[string]`, list of the features that will appear in the
|
57 |
feature dict. Should not include "label".
|
58 |
citation: `string`, citation for the data set.
|
59 |
+
data_url: `string`, relative data path in repo
|
60 |
+
url: `string`, link to dataset info page
|
61 |
**kwargs: keyword arguments forwarded to super.
|
62 |
"""
|
63 |
# Version history:
|
|
|
76 |
CodequeriesConfig(
|
77 |
name="ideal",
|
78 |
description=_IDEAL_DESCRIPTION,
|
79 |
+
features=["query_name", "code_file_path", "context_blocks",
|
80 |
+
"answer_spans", "supporting_fact_spans",
|
81 |
+
"example_type", "single_hop",
|
82 |
"subtokenized_input_sequence", "label_sequence"],
|
83 |
citation=_CODEQUERIES_CITATION,
|
84 |
data_url={
|
|
|
86 |
"dev": "ideal_val.json",
|
87 |
"test": "ideal_test.json"
|
88 |
},
|
89 |
+
url="https://huggingface.co/datasets/thepurpleowl/codequeries",
|
90 |
),
|
91 |
CodequeriesConfig(
|
92 |
name="prefix",
|
93 |
description=_PREFIX_DESCRIPTION,
|
94 |
+
features=["query_name", "code_file_path",
|
95 |
+
"answer_spans", "supporting_fact_spans",
|
96 |
+
"example_type", "single_hop",
|
97 |
"subtokenized_input_sequence", "label_sequence"],
|
98 |
citation=_CODEQUERIES_CITATION,
|
99 |
data_url={
|
100 |
"test": "prefix_test.json"
|
101 |
},
|
102 |
+
url="https://huggingface.co/datasets/thepurpleowl/codequeries",
|
103 |
),
|
104 |
CodequeriesConfig(
|
105 |
name="file_ideal",
|
106 |
description=_FILE_IDEAL_DESCRIPTION,
|
107 |
+
features=["query_name", "code_file_path", "context_blocks",
|
108 |
+
"answer_spans", "supporting_fact_spans",
|
109 |
+
"example_type", "single_hop",
|
110 |
"subtokenized_input_sequence", "label_sequence"],
|
111 |
citation=_CODEQUERIES_CITATION,
|
112 |
data_url={
|
113 |
"test": "file_ideal_test.json"
|
114 |
},
|
115 |
+
url="https://huggingface.co/datasets/thepurpleowl/codequeries",
|
116 |
),
|
117 |
CodequeriesConfig(
|
118 |
name="twostep",
|
119 |
description=_TWOSTEP_DESCRIPTION,
|
120 |
+
features=["query_name", "code_file_path", "context_blocks",
|
121 |
+
"answer_spans", "supporting_fact_spans",
|
122 |
+
"example_type", "single_hop",
|
123 |
+
"subtokenized_input_sequence", "label_sequence",
|
124 |
+
"relevance_label"],
|
125 |
citation=_CODEQUERIES_CITATION,
|
126 |
data_url={
|
127 |
"test": ["twostep_relevance/" + "twostep_relevance_test_" + str(i) + ".json" for i in range(0,10)]
|
128 |
},
|
129 |
+
url="https://huggingface.co/datasets/thepurpleowl/codequeries",
|
130 |
),
|
131 |
]
|
132 |
|
|
|
135 |
def _info(self):
|
136 |
features = {}
|
137 |
features["query_name"] = datasets.Value("string")
|
138 |
+
features["code_file_path"] = datasets.Value("string")
|
139 |
features["context_blocks"] = [
|
140 |
{
|
141 |
"content": datasets.Value("string"),
|
142 |
"metadata": datasets.Value("string"),
|
143 |
+
"header": datasets.Value("string"),
|
144 |
+
"index": datasets.Value("int32")
|
145 |
}
|
146 |
]
|
147 |
features["answer_spans"] = [
|
|
|
162 |
'end_column': datasets.Value("int32")
|
163 |
}
|
164 |
]
|
165 |
+
features["example_type"] = datasets.Value("int8")
|
166 |
+
features["single_hop"] = datasets.Value("bool")
|
167 |
features["subtokenized_input_sequence"] = datasets.features.Sequence(datasets.Value("string"))
|
168 |
+
features["label_sequence"] = datasets.features.Sequence(datasets.Value("int8"))
|
169 |
+
features["relevance_label"] = datasets.Value("int8")
|
170 |
|
171 |
return datasets.DatasetInfo(
|
172 |
description=self.config.description,
|
|
|
177 |
|
178 |
def _split_generators(self, dl_manager):
|
179 |
dl_dir = dl_manager.download_and_extract(self.config.data_url)
|
180 |
+
|
181 |
if self.config.name in ["prefix", "file_ideal", "twostep"]:
|
182 |
return [
|
183 |
datasets.SplitGenerator(
|
|
|
216 |
def _generate_examples(self, filepath, split):
|
217 |
if self.config.name in ["prefix", "file_ideal", "twostep"]:
|
218 |
assert split == datasets.Split.TEST
|
219 |
+
logger.info("Generating examples from = %s", filepath)
|
220 |
|
221 |
if self.config.name == "twostep":
|
222 |
key = 0
|
|
|
228 |
instance_key = str(key) + "_" + row["query_name"] + "_" + row["code_file_path"]
|
229 |
yield instance_key, {
|
230 |
"query_name": row["query_name"],
|
231 |
+
"code_file_path": row["code_file_path"],
|
232 |
"context_blocks": row["context_blocks"],
|
233 |
"answer_spans": row["answer_spans"],
|
234 |
"supporting_fact_spans": row["supporting_fact_spans"],
|
|
|
235 |
"example_type": row["example_type"],
|
236 |
+
"single_hop": row["single_hop"],
|
237 |
"subtokenized_input_sequence": row["subtokenized_input_sequence"],
|
238 |
+
"label_sequence": row["label_sequence"],
|
239 |
"relevance_label": row["relevance_label"],
|
240 |
}
|
241 |
key += 1
|
242 |
+
elif self.config.name == "prefix":
|
243 |
+
with open(filepath, encoding="utf-8") as f:
|
244 |
+
key = 0
|
245 |
+
for line in f:
|
246 |
+
row = json.loads(line)
|
247 |
+
|
248 |
+
instance_key = str(key) + "_" + row["query_name"] + "_" + row["code_file_path"]
|
249 |
+
yield instance_key, {
|
250 |
+
"query_name": row["query_name"],
|
251 |
+
"code_file_path": row["code_file_path"],
|
252 |
+
"answer_spans": row["answer_spans"],
|
253 |
+
"supporting_fact_spans": row["supporting_fact_spans"],
|
254 |
+
"example_type": row["example_type"],
|
255 |
+
"single_hop": row["single_hop"],
|
256 |
+
"subtokenized_input_sequence": row["subtokenized_input_sequence"],
|
257 |
+
"label_sequence": row["label_sequence"],
|
258 |
+
}
|
259 |
+
key += 1
|
260 |
else:
|
261 |
with open(filepath, encoding="utf-8") as f:
|
262 |
key = 0
|
|
|
266 |
instance_key = str(key) + "_" + row["query_name"] + "_" + row["code_file_path"]
|
267 |
yield instance_key, {
|
268 |
"query_name": row["query_name"],
|
269 |
+
"code_file_path": row["code_file_path"],
|
270 |
"context_blocks": row["context_blocks"],
|
271 |
"answer_spans": row["answer_spans"],
|
272 |
"supporting_fact_spans": row["supporting_fact_spans"],
|
|
|
273 |
"example_type": row["example_type"],
|
274 |
+
"single_hop": row["single_hop"],
|
275 |
"subtokenized_input_sequence": row["subtokenized_input_sequence"],
|
276 |
"label_sequence": row["label_sequence"],
|
277 |
}
|
278 |
key += 1
|
|