Datasets:

Languages:
Vietnamese
ArXiv:
License:
File size: 10,304 Bytes
74d5856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
from pathlib import Path
from typing import Dict, List, Tuple

import datasets

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

_CITATION = """\
@article{dao2021intent,
      title={Intent Detection and Slot Filling for Vietnamese},
      author={Mai Hoang Dao and Thinh Hung Truong and Dat Quoc Nguyen},
      year={2021},
      eprint={2104.02021},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
"""

_DATASETNAME = "phoatis"

_DESCRIPTION = """\
This is first public intent detection and slot filling dataset for Vietnamese. The data contains 5871 English utterances from ATIS that are manually translated by professional translators into Vietnamese.
"""

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

_LICENSE = Licenses.UNKNOWN.value

_URLS = {
    _DATASETNAME: {
        "syllable": {
            "syllable_train": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/train/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/train/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/train/label",
            ],
            "syllable_dev": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/dev/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/dev/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/dev/label",
            ],
            "syllable_test": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/test/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/test/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/test/label",
            ],
        },
        "word": {
            "word_train": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/train/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/train/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/train/label",
            ],
            "word_dev": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/dev/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/dev/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/dev/label",
            ],
            "word_test": [
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/test/seq.in",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/test/seq.out",
                "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/word-level/test/label",
            ],
        },
    }
}

_LOCAL = False
_LANGUAGES = ["vie"]

_SUPPORTED_TASKS = [Tasks.INTENT_CLASSIFICATION, Tasks.SLOT_FILLING]

_SOURCE_VERSION = "1.0.0"

_SEACROWD_VERSION = "2024.06.20"


def config_constructor_intent_cls(schema: str, version: str, phoatis_subset: str = "syllable") -> SEACrowdConfig:
    assert phoatis_subset == "syllable" or phoatis_subset == "word"

    return SEACrowdConfig(
        name="phoatis_intent_cls_{phoatis_subset}_{schema}".format(phoatis_subset=phoatis_subset.lower(), schema=schema),
        version=version,
        description="PhoATIS Intent Classification: {subset} {schema} schema".format(subset=phoatis_subset, schema=schema),
        schema=schema,
        subset_id=phoatis_subset,
    )


def config_constructor_slot_filling(schema: str, version: str, phoatis_subset: str = "syllable") -> SEACrowdConfig:
    assert phoatis_subset == "syllable" or phoatis_subset == "word"

    return SEACrowdConfig(
        name="phoatis_slot_filling_{phoatis_subset}_{schema}".format(phoatis_subset=phoatis_subset.lower(), schema=schema),
        version=version,
        description="PhoATIS Slot Filling: {subset} {schema} schema".format(subset=phoatis_subset, schema=schema),
        schema=schema,
        subset_id=phoatis_subset,
    )


class PhoATIS(datasets.GeneratorBasedBuilder):
    """This is first public intent detection and slot filling dataset for Vietnamese. The data contains 5871 English utterances from ATIS that are manually translated by professional translators into Vietnamese."""

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

    # BUILDER_CONFIGS = [config_constructor_intent_cls("source", _SOURCE_VERSION, subset) for subset in ["syllable", "word"]]
    BUILDER_CONFIGS = []
    BUILDER_CONFIGS.extend([config_constructor_intent_cls("seacrowd_text", _SEACROWD_VERSION, subset) for subset in ["syllable", "word"]])
    # BUILDER_CONFIGS.extend([config_constructor_slot_filling("source", _SOURCE_VERSION, subset) for subset in ["syllable", "word"]])
    BUILDER_CONFIGS.extend([config_constructor_slot_filling("seacrowd_seq_label", _SEACROWD_VERSION, subset) for subset in ["syllable", "word"]])

    BUILDER_CONFIGS.extend(
        [  # Default config
            SEACrowdConfig(
                name="phoatis_source",
                version=SOURCE_VERSION,
                description="PhoATIS source schema (Syllable version)",
                schema="source",
                subset_id="syllable",
            ),
            SEACrowdConfig(
                name="phoatis_intent_cls_seacrowd_text",
                version=SEACROWD_VERSION,
                description="PhoATIS Intent Classification SEACrowd schema (Syllable version)",
                schema="seacrowd_text",
                subset_id="syllable",
            ),
            SEACrowdConfig(
                name="phoatis_slot_filling_seacrowd_seq_label",
                version=SEACROWD_VERSION,
                description="PhoATIS Slot Filling SEACrowd schema (Syllable version)",
                schema="seacrowd_seq_label",
                subset_id="syllable",
            ),
        ]
    )

    DEFAULT_CONFIG_NAME = "phoatis_source"

    def _info(self) -> datasets.DatasetInfo:

        if self.config.schema == "source":
            features = datasets.Features(
                {
                    "id": datasets.Value("string"),
                    "text": datasets.Value("string"),
                    "intent_label": datasets.Value("string"),
                    "slot_label": datasets.Sequence(datasets.Value("string")),
                }
            )

        elif self.config.schema == "seacrowd_text":
            with open("./seacrowd/sea_datasets/phoatis/intent_label.txt", "r+", encoding="utf8") as fw:
                intent_label = fw.read()
                intent_label = intent_label.split("\n")
            features = schemas.text_features(intent_label)

        elif self.config.schema == "seacrowd_seq_label":
            with open("./seacrowd/sea_datasets/phoatis/slot_label.txt", "r+", encoding="utf8") as fw:
                slot_label = fw.read()
                slot_label = slot_label.split("\n")
            features = schemas.seq_label_features(slot_label)

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

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        schema = self.config.subset_id
        urls = _URLS[_DATASETNAME][schema]
        data_dir = dl_manager.download_and_extract(urls)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": data_dir[f"{schema}_train"],
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": data_dir[f"{schema}_test"],
                    "split": "test",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "filepath": data_dir[f"{schema}_dev"],
                    "split": "dev",
                },
            ),
        ]

    def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
        with open(filepath[0], "r+", encoding="utf8") as fw:
            data_input = fw.read()
            data_input = data_input.split("\n")
        with open(filepath[1], "r+", encoding="utf8") as fw:
            data_slot = fw.read()
            data_slot = data_slot.split("\n")
        with open(filepath[2], "r+", encoding="utf8") as fw:
            data_intent = fw.read()
            data_intent = data_intent.split("\n")

        if self.config.schema == "source":
            for idx, text in enumerate(data_input):
                example = {}
                example["id"] = str(idx)
                example["text"] = text
                example["intent_label"] = data_intent[idx]
                example["slot_label"] = data_slot[idx].split()
                yield example["id"], example

        elif self.config.schema == "seacrowd_text":
            for idx, text in enumerate(data_input):
                example = {}
                example["id"] = str(idx)
                example["text"] = text
                example["label"] = data_intent[idx]
                yield example["id"], example

        elif self.config.schema == "seacrowd_seq_label":
            for idx, text in enumerate(data_input):
                example = {}
                example["id"] = str(idx)
                example["tokens"] = text.split()
                example["labels"] = data_slot[idx].split()
                yield example["id"], example