Commit
·
ee35848
1
Parent(s):
a8765d3
Upload css.py
Browse files
css.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""CSS: A Large-scale Cross-schema Chinese Text-to-SQL Medical Dataset"""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
import datasets
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
logger = datasets.logging.get_logger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
_CITATION = """\
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
_DESCRIPTION = "CSS is a large-scale cross-schema Chinese text-to-SQL datasets"
|
| 31 |
+
|
| 32 |
+
_URL = "https://huggingface.co/datasets/zhanghanchong/css/resolve/main/css.zip"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class CSS(datasets.GeneratorBasedBuilder):
|
| 36 |
+
VERSION = datasets.Version("1.0.0")
|
| 37 |
+
|
| 38 |
+
BUILDER_CONFIGS = [
|
| 39 |
+
datasets.BuilderConfig(
|
| 40 |
+
name="css",
|
| 41 |
+
version=VERSION,
|
| 42 |
+
description="CSS: A Large-scale Cross-schema Chinese Text-to-SQL Medical Dataset",
|
| 43 |
+
),
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def _info(self):
|
| 47 |
+
features = datasets.Features(
|
| 48 |
+
{
|
| 49 |
+
"query": datasets.Value("string"),
|
| 50 |
+
"db_id": datasets.Value("string"),
|
| 51 |
+
"question": datasets.Value("string"),
|
| 52 |
+
"question_id": datasets.Value("string")
|
| 53 |
+
}
|
| 54 |
+
)
|
| 55 |
+
return datasets.DatasetInfo(
|
| 56 |
+
description=_DESCRIPTION,
|
| 57 |
+
features=features,
|
| 58 |
+
supervised_keys=None,
|
| 59 |
+
citation=_CITATION,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
def _split_generators(self, dl_manager):
|
| 63 |
+
downloaded_filepath = dl_manager.download_and_extract(_URL)
|
| 64 |
+
|
| 65 |
+
return [
|
| 66 |
+
datasets.SplitGenerator(
|
| 67 |
+
name=datasets.NamedSplit("example/train"),
|
| 68 |
+
gen_kwargs={
|
| 69 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/example/train.json"),
|
| 70 |
+
},
|
| 71 |
+
),
|
| 72 |
+
datasets.SplitGenerator(
|
| 73 |
+
name=datasets.NamedSplit("example/dev"),
|
| 74 |
+
gen_kwargs={
|
| 75 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/example/dev.json"),
|
| 76 |
+
},
|
| 77 |
+
),
|
| 78 |
+
datasets.SplitGenerator(
|
| 79 |
+
name=datasets.NamedSplit("example/test"),
|
| 80 |
+
gen_kwargs={
|
| 81 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/example/test.json"),
|
| 82 |
+
},
|
| 83 |
+
),
|
| 84 |
+
datasets.SplitGenerator(
|
| 85 |
+
name=datasets.NamedSplit("template/train"),
|
| 86 |
+
gen_kwargs={
|
| 87 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/template/train.json"),
|
| 88 |
+
},
|
| 89 |
+
),
|
| 90 |
+
datasets.SplitGenerator(
|
| 91 |
+
name=datasets.NamedSplit("template/dev"),
|
| 92 |
+
gen_kwargs={
|
| 93 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/template/dev.json"),
|
| 94 |
+
},
|
| 95 |
+
),
|
| 96 |
+
datasets.SplitGenerator(
|
| 97 |
+
name=datasets.NamedSplit("template/test"),
|
| 98 |
+
gen_kwargs={
|
| 99 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/template/test.json"),
|
| 100 |
+
},
|
| 101 |
+
),
|
| 102 |
+
datasets.SplitGenerator(
|
| 103 |
+
name=datasets.NamedSplit("schema/train"),
|
| 104 |
+
gen_kwargs={
|
| 105 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/schema/train.json"),
|
| 106 |
+
},
|
| 107 |
+
),
|
| 108 |
+
datasets.SplitGenerator(
|
| 109 |
+
name=datasets.NamedSplit("schema/dev"),
|
| 110 |
+
gen_kwargs={
|
| 111 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/schema/dev.json"),
|
| 112 |
+
},
|
| 113 |
+
),
|
| 114 |
+
datasets.SplitGenerator(
|
| 115 |
+
name=datasets.NamedSplit("schema/test"),
|
| 116 |
+
gen_kwargs={
|
| 117 |
+
"data_filepath": os.path.join(downloaded_filepath, "css/schema/test.json"),
|
| 118 |
+
},
|
| 119 |
+
),
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
def _generate_examples(self, data_filepath):
|
| 123 |
+
"""This function returns the examples in the raw (text) form."""
|
| 124 |
+
logger.info("generating examples from = %s", data_filepath)
|
| 125 |
+
with open(data_filepath, encoding="utf-8") as f:
|
| 126 |
+
css = json.load(f)
|
| 127 |
+
for idx, sample in enumerate(css):
|
| 128 |
+
yield idx, {
|
| 129 |
+
"query": sample["query"],
|
| 130 |
+
"db_id": sample["db_id"],
|
| 131 |
+
"question": sample["question"],
|
| 132 |
+
"question_id": sample["question_id"],
|
| 133 |
+
}
|