Datasets:

Languages:
Vietnamese
ArXiv:
License:
File size: 6,898 Bytes
73d21db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from pathlib import Path
from typing import Dict, List, Tuple

import datasets
import pandas as pd

from seacrowd.utils import schemas
from seacrowd.utils.configs import SEACrowdConfig
from seacrowd.utils.constants import Licenses, Tasks

_CITATION = """\
@inproceedings{nguyen2020vitext2sql,
    title      = {{A Pilot Study of Text-to-SQL Semantic Parsing for Vietnamese}},
    author     = {Anh Tuan Nguyen and Mai Hoang Dao and Dat Quoc Nguyen},
    booktitle  = {Findings of the Association for Computational Linguistics: EMNLP 2020},
    year       = {2020},
    pages      = {4079--4085}
}
"""

_DATASETNAME = "vitext2sql"

_DESCRIPTION = """\
This is the first public large-scale Text-to-SQL semantic parsing dataset for Vietnamese.
The dataset is created by manually translating the Spider dataset into Vietnamese.
"""

_HOMEPAGE = "https://github.com/VinAIResearch/ViText2SQL"

_LICENSE = f"""{Licenses.OTHERS.value} |
By downloading the ViText2SQL dataset, USER agrees:
1. to use ViText2SQL for research or educational purposes only.
2. to not distribute ViText2SQL or part of ViText2SQL in any original or modified form.
3. and to cite our EMNLP-2020 Findings paper above whenever ViText2SQL is employed to help produce published results.
Copyright (c) 2020 VinAI Research
THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE
DATA.
"""

_SOURCE_VERSION = "1.0.0"

_URLS = {
    "word-level": {
        "train": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/train.json",
        "test": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/test.json",
        "validation": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/word-level/dev.json",
    },
    "syllable-level": {
        "train": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/train.json",
        "test": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/test.json",
        "validation": "https://raw.githubusercontent.com/VinAIResearch/ViText2SQL/master/data/syllable-level/dev.json",
    },
}

_LOCAL = False
_LANGUAGES = ["vie"]
_SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]

_SEACROWD_VERSION = "2024.06.20"


class ViText2SQLDataset(datasets.GeneratorBasedBuilder):
    """Vitext2sql dataset is a Text-to-SQL semantic parsing dataset for Vietnamese."""

    SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
    SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)

    BUILDER_CONFIGS = [
        SEACrowdConfig(
            name=f"{_DATASETNAME}_source",
            version=SOURCE_VERSION,
            description="Vitext2sql word level source schema",
            schema="source",
            subset_id="vitext2sql",
        ),
        SEACrowdConfig(
            name=f"{_DATASETNAME}_source_syllable",
            version=SOURCE_VERSION,
            description="Vitext2sql syllable level source schema",
            schema="source",
            subset_id="vitext2sql",
        ),
        SEACrowdConfig(
            name=f"{_DATASETNAME}_seacrowd_t2t",
            version=SEACROWD_VERSION,
            description="Vitext2sql SEACrowd schema for word-level",
            schema="seacrowd_t2t",
            subset_id="vitext2sql",
        ),
        SEACrowdConfig(
            name=f"{_DATASETNAME}_seacrowd_syllable_t2t",
            version=SEACROWD_VERSION,
            description="Vitext2sql SEACrowd schema for syllable-level",
            schema="seacrowd_t2t",
            subset_id="vitext2sql",
        ),
    ]

    DEFAULT_CONFIG_NAME = "vitext2sql_source"

    def _info(self) -> datasets.DatasetInfo:
        if self.config.schema == "source":
            # The sql column is an unstructured JSON,
            # in the meantime just treat it as large string.
            features = datasets.Features(
                {
                    "db_id": datasets.Value("string"),
                    "query": datasets.Value("string"),
                    "query_toks": [datasets.Value("string")],
                    "query_toks_no_value": [datasets.Value("string")],
                    "question": datasets.Value("string"),
                    "question_toks": [datasets.Value("string")],
                    "sql": datasets.Value("large_string"),
                }
            )
        elif self.config.schema == "seacrowd_t2t":
            features = schemas.text2text_features

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        if "syllable" in self.config.name:
            level_urls = _URLS["syllable-level"]
        else:
            level_urls = _URLS["word-level"]

        data_files = dl_manager.download_and_extract(level_urls)
        split_generators = [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": data_files["test"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": data_files["train"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "filepath": data_files["validation"],
                },
            ),
        ]

        return split_generators

    def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
        df = pd.read_json(filepath)
        if self.config.schema == "source":
            for i, row in df.iterrows():
                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"])}
                yield i, entry
        elif self.config.schema == "seacrowd_t2t":
            for i, row in df.iterrows():
                entry = {
                    "id": str(i),
                    "text_1": row["question"],
                    "text_2": row["query"],
                    "text_1_name": "question",
                    "text_2_name": "sql_query",
                }
                yield i, entry