Datasets:

Languages:
Vietnamese
ArXiv:
License:
holylovenia commited on
Commit
73d21db
·
verified ·
1 Parent(s): e490d3c

Upload vitext2sql.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. vitext2sql.py +177 -0
vitext2sql.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import Dict, List, Tuple
3
+
4
+ import datasets
5
+ import pandas as pd
6
+
7
+ from seacrowd.utils import schemas
8
+ from seacrowd.utils.configs import SEACrowdConfig
9
+ from seacrowd.utils.constants import Licenses, Tasks
10
+
11
+ _CITATION = """\
12
+ @inproceedings{nguyen2020vitext2sql,
13
+ title = {{A Pilot Study of Text-to-SQL Semantic Parsing for Vietnamese}},
14
+ author = {Anh Tuan Nguyen and Mai Hoang Dao and Dat Quoc Nguyen},
15
+ booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2020},
16
+ year = {2020},
17
+ pages = {4079--4085}
18
+ }
19
+ """
20
+
21
+ _DATASETNAME = "vitext2sql"
22
+
23
+ _DESCRIPTION = """\
24
+ This is the first public large-scale Text-to-SQL semantic parsing dataset for Vietnamese.
25
+ The dataset is created by manually translating the Spider dataset into Vietnamese.
26
+ """
27
+
28
+ _HOMEPAGE = "https://github.com/VinAIResearch/ViText2SQL"
29
+
30
+ _LICENSE = f"""{Licenses.OTHERS.value} |
31
+ By downloading the ViText2SQL dataset, USER agrees:
32
+ 1. to use ViText2SQL for research or educational purposes only.
33
+ 2. to not distribute ViText2SQL or part of ViText2SQL in any original or modified form.
34
+ 3. and to cite our EMNLP-2020 Findings paper above whenever ViText2SQL is employed to help produce published results.
35
+ Copyright (c) 2020 VinAI Research
36
+ THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
+ OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE
42
+ DATA.
43
+ """
44
+
45
+ _SOURCE_VERSION = "1.0.0"
46
+
47
+ _URLS = {
48
+ "word-level": {
49
+ "train": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/train.json",
50
+ "test": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/test.json",
51
+ "validation": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/dev.json",
52
+ },
53
+ "syllable-level": {
54
+ "train": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/train.json",
55
+ "test": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/test.json",
56
+ "validation": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/dev.json",
57
+ },
58
+ }
59
+
60
+ _LOCAL = False
61
+ _LANGUAGES = ["vie"]
62
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
63
+
64
+ _SEACROWD_VERSION = "2024.06.20"
65
+
66
+
67
+ class ViText2SQLDataset(datasets.GeneratorBasedBuilder):
68
+ """Vitext2sql dataset is a Text-to-SQL semantic parsing dataset for Vietnamese."""
69
+
70
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
71
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
72
+
73
+ BUILDER_CONFIGS = [
74
+ SEACrowdConfig(
75
+ name=f"{_DATASETNAME}_source",
76
+ version=SOURCE_VERSION,
77
+ description="Vitext2sql word level source schema",
78
+ schema="source",
79
+ subset_id="vitext2sql",
80
+ ),
81
+ SEACrowdConfig(
82
+ name=f"{_DATASETNAME}_source_syllable",
83
+ version=SOURCE_VERSION,
84
+ description="Vitext2sql syllable level source schema",
85
+ schema="source",
86
+ subset_id="vitext2sql",
87
+ ),
88
+ SEACrowdConfig(
89
+ name=f"{_DATASETNAME}_seacrowd_t2t",
90
+ version=SEACROWD_VERSION,
91
+ description="Vitext2sql SEACrowd schema for word-level",
92
+ schema="seacrowd_t2t",
93
+ subset_id="vitext2sql",
94
+ ),
95
+ SEACrowdConfig(
96
+ name=f"{_DATASETNAME}_seacrowd_syllable_t2t",
97
+ version=SEACROWD_VERSION,
98
+ description="Vitext2sql SEACrowd schema for syllable-level",
99
+ schema="seacrowd_t2t",
100
+ subset_id="vitext2sql",
101
+ ),
102
+ ]
103
+
104
+ DEFAULT_CONFIG_NAME = "vitext2sql_source"
105
+
106
+ def _info(self) -> datasets.DatasetInfo:
107
+ if self.config.schema == "source":
108
+ # The sql column is an unstructured JSON,
109
+ # in the meantime just treat it as large string.
110
+ features = datasets.Features(
111
+ {
112
+ "db_id": datasets.Value("string"),
113
+ "query": datasets.Value("string"),
114
+ "query_toks": [datasets.Value("string")],
115
+ "query_toks_no_value": [datasets.Value("string")],
116
+ "question": datasets.Value("string"),
117
+ "question_toks": [datasets.Value("string")],
118
+ "sql": datasets.Value("large_string"),
119
+ }
120
+ )
121
+ elif self.config.schema == "seacrowd_t2t":
122
+ features = schemas.text2text_features
123
+
124
+ return datasets.DatasetInfo(
125
+ description=_DESCRIPTION,
126
+ features=features,
127
+ homepage=_HOMEPAGE,
128
+ license=_LICENSE,
129
+ citation=_CITATION,
130
+ )
131
+
132
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
133
+ if "syllable" in self.config.name:
134
+ level_urls = _URLS["syllable-level"]
135
+ else:
136
+ level_urls = _URLS["word-level"]
137
+
138
+ data_files = dl_manager.download_and_extract(level_urls)
139
+ split_generators = [
140
+ datasets.SplitGenerator(
141
+ name=datasets.Split.TEST,
142
+ gen_kwargs={
143
+ "filepath": data_files["test"],
144
+ },
145
+ ),
146
+ datasets.SplitGenerator(
147
+ name=datasets.Split.TRAIN,
148
+ gen_kwargs={
149
+ "filepath": data_files["train"],
150
+ },
151
+ ),
152
+ datasets.SplitGenerator(
153
+ name=datasets.Split.VALIDATION,
154
+ gen_kwargs={
155
+ "filepath": data_files["validation"],
156
+ },
157
+ ),
158
+ ]
159
+
160
+ return split_generators
161
+
162
+ def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
163
+ df = pd.read_json(filepath)
164
+ if self.config.schema == "source":
165
+ for i, row in df.iterrows():
166
+ entry = {"db_id": row["db_id"], "query": row["query"], "query_toks": row["query_toks"], "query_toks_no_value": row["query_toks_no_value"], "question": row["question"], "question_toks": row["question_toks"], "sql": str(row["sql"])}
167
+ yield i, entry
168
+ elif self.config.schema == "seacrowd_t2t":
169
+ for i, row in df.iterrows():
170
+ entry = {
171
+ "id": str(i),
172
+ "text_1": row["question"],
173
+ "text_2": row["query"],
174
+ "text_1_name": "question",
175
+ "text_2_name": "sql_query",
176
+ }
177
+ yield i, entry