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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""Spider: A Large-Scale Human-Labeled Dataset for Text-to-SQL Tasks"""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
import textwrap
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
logger = datasets.logging.get_logger(__name__)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_CITATION = """\
|
| 29 |
+
@article{yu2018spider,
|
| 30 |
+
title={Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task},
|
| 31 |
+
author={Yu, Tao and Zhang, Rui and Yang, Kai and Yasunaga, Michihiro and Wang, Dongxu and Li, Zifan and Ma, James and Li, Irene and Yao, Qingning and Roman, Shanelle and others},
|
| 32 |
+
journal={arXiv preprint arXiv:1809.08887},
|
| 33 |
+
year={2018}
|
| 34 |
+
}
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
_DESCRIPTION = """\
|
| 38 |
+
Spider is a large-scale complex and cross-domain semantic parsing and text-toSQL dataset annotated by 11 college students
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
_HOMEPAGE = "https://yale-lily.github.io/spider"
|
| 42 |
+
|
| 43 |
+
_LICENSE = "CC BY-SA 4.0"
|
| 44 |
+
|
| 45 |
+
_URL = "https://huggingface.co/datasets/spider/resolve/main/data/spider.zip"
|
| 46 |
+
|
| 47 |
+
class SpiderConfig(datasets.BuilderConfig):
|
| 48 |
+
"""BuilderConfig for Spider."""
|
| 49 |
+
|
| 50 |
+
def __init__(
|
| 51 |
+
self,
|
| 52 |
+
name,
|
| 53 |
+
description,
|
| 54 |
+
train_path,
|
| 55 |
+
dev_path,
|
| 56 |
+
**kwargs
|
| 57 |
+
):
|
| 58 |
+
super(SpiderConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
| 59 |
+
self.features =
|
| 60 |
+
self.name = name
|
| 61 |
+
self.description = description
|
| 62 |
+
self.train_path = train_path
|
| 63 |
+
self.dev_path = dev_path
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class Spider(datasets.GeneratorBasedBuilder):
|
| 67 |
+
BUILDER_CONFIGS = [
|
| 68 |
+
SpiderConfig(
|
| 69 |
+
name="AppE",
|
| 70 |
+
description=textwrap.dedent(
|
| 71 |
+
"""\
|
| 72 |
+
An Appalachian English variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 73 |
+
),
|
| 74 |
+
train_path="train_spider_AppE.json",
|
| 75 |
+
dev_path="dev_AppE.json",
|
| 76 |
+
),
|
| 77 |
+
SpiderConfig(
|
| 78 |
+
name="ChcE",
|
| 79 |
+
description=textwrap.dedent(
|
| 80 |
+
"""\
|
| 81 |
+
A Chicano English variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 82 |
+
),
|
| 83 |
+
train_path="train_spider_ChcE.json",
|
| 84 |
+
dev_path="dev_ChcE.json",
|
| 85 |
+
),
|
| 86 |
+
SpiderConfig(
|
| 87 |
+
name="CollSgE",
|
| 88 |
+
description=textwrap.dedent(
|
| 89 |
+
"""\
|
| 90 |
+
A Singapore English (Singlish) variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 91 |
+
),
|
| 92 |
+
train_path="train_spider_CollSgE.json",
|
| 93 |
+
dev_path="dev_CollSgE.json",
|
| 94 |
+
),
|
| 95 |
+
SpiderConfig(
|
| 96 |
+
name="IndE",
|
| 97 |
+
description=textwrap.dedent(
|
| 98 |
+
"""\
|
| 99 |
+
An Indian English variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 100 |
+
),
|
| 101 |
+
train_path="train_spider_IndE.json",
|
| 102 |
+
dev_path="dev_IndE.json",
|
| 103 |
+
),
|
| 104 |
+
SpiderConfig(
|
| 105 |
+
name="UAAVE",
|
| 106 |
+
description=textwrap.dedent(
|
| 107 |
+
"""\
|
| 108 |
+
An Urban African American English variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 109 |
+
),
|
| 110 |
+
train_path="train_spider_UAAVE.json",
|
| 111 |
+
dev_path="dev_UAAVE.json",
|
| 112 |
+
),
|
| 113 |
+
SpiderConfig(
|
| 114 |
+
name="MULTI",
|
| 115 |
+
description=textwrap.dedent(
|
| 116 |
+
"""\
|
| 117 |
+
A mixed-dialectal variant of a large-scale complex and cross-domain semantic parsing and text-to-SQL dataset annotated by 11 college students"""
|
| 118 |
+
),
|
| 119 |
+
train_path="train_spider_MULTI.json",
|
| 120 |
+
dev_path="dev_MULTI.json",
|
| 121 |
+
),
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
def _info(self):
|
| 125 |
+
features = datasets.Features(
|
| 126 |
+
{
|
| 127 |
+
"db_id": datasets.Value("string"),
|
| 128 |
+
"query": datasets.Value("string"),
|
| 129 |
+
"question": datasets.Value("string"),
|
| 130 |
+
"query_toks": datasets.features.Sequence(datasets.Value("string")),
|
| 131 |
+
"query_toks_no_value": datasets.features.Sequence(datasets.Value("string")),
|
| 132 |
+
"question_toks": datasets.features.Sequence(datasets.Value("string")),
|
| 133 |
+
}
|
| 134 |
+
)
|
| 135 |
+
return datasets.DatasetInfo(
|
| 136 |
+
description=_DESCRIPTION,
|
| 137 |
+
features=features,
|
| 138 |
+
supervised_keys=None,
|
| 139 |
+
homepage=_HOMEPAGE,
|
| 140 |
+
license=_LICENSE,
|
| 141 |
+
citation=_CITATION,
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
def _split_generators(self, dl_manager):
|
| 145 |
+
downloaded_filepath = dl_manager.download_and_extract(_URL)
|
| 146 |
+
|
| 147 |
+
return [
|
| 148 |
+
datasets.SplitGenerator(
|
| 149 |
+
name=datasets.Split.TRAIN,
|
| 150 |
+
gen_kwargs={
|
| 151 |
+
"data_filepath": os.path.join(downloaded_filepath, self.config.train_path),
|
| 152 |
+
},
|
| 153 |
+
),
|
| 154 |
+
datasets.SplitGenerator(
|
| 155 |
+
name=datasets.Split.VALIDATION,
|
| 156 |
+
gen_kwargs={
|
| 157 |
+
"data_filepath": os.path.join(downloaded_filepath, self.config.dev_path),
|
| 158 |
+
},
|
| 159 |
+
)
|
| 160 |
+
]
|
| 161 |
+
|
| 162 |
+
def _generate_examples(self, data_filepath):
|
| 163 |
+
"""This function returns the examples in the raw (text) form."""
|
| 164 |
+
logger.info("generating examples from = %s", data_filepath)
|
| 165 |
+
with open(data_filepath, encoding="utf-8") as f:
|
| 166 |
+
spider = json.load(f)
|
| 167 |
+
for idx, sample in enumerate(spider):
|
| 168 |
+
yield idx, {
|
| 169 |
+
"db_id": sample["db_id"],
|
| 170 |
+
"query": sample["query"],
|
| 171 |
+
"question": sample["question"],
|
| 172 |
+
"query_toks": sample["query_toks"],
|
| 173 |
+
"query_toks_no_value": sample["query_toks_no_value"],
|
| 174 |
+
"question_toks": sample["question_toks"],
|
| 175 |
+
}
|