holylovenia commited on
Commit
d3ba772
1 Parent(s): ee0b4ad

Upload indocamrest.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. indocamrest.py +163 -0
indocamrest.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from seacrowd.utils import schemas
8
+ from seacrowd.utils.configs import SEACrowdConfig
9
+ from seacrowd.utils.constants import Tasks, Licenses
10
+
11
+ _CITATION = """\
12
+ @article{kautsar2023indotod,
13
+ author={Kautsar, Muhammad Dehan Al and Nurdini, Rahmah Khoirussyifa' and Cahyawijaya, Samuel and Winata, Genta Indra and Purwarianti, Ayu},
14
+ title={IndoToD: A Multi-Domain Indonesian Benchmark For End-to-End Task-Oriented Dialogue Systems},
15
+ journal={arXiv preprint arXiv:2311.00958},
16
+ year={2023},
17
+ }
18
+ """
19
+
20
+ _LANGUAGES = ["ind"]
21
+ _LOCAL = False
22
+
23
+ _DATASETNAME = "indocamrest"
24
+
25
+ _DESCRIPTION = """\
26
+ IndoCamRest is a synthetic task-oriented dialogue system dataset that translated from Cambridge Restaurant 676 (CamRest) dataset (Wen et al., 2016) into the new Indonesian parallel dataset using the translation pipeline method including the delexicalization, translation, and delexicalization.
27
+ The dataset consists of 676 dialogues in the restaurant reservation domain, with a user and an agent talking to each other to search the restaurant near the user.
28
+ It also consists of slots and dialogue acts from the user and the agent.
29
+ """
30
+
31
+ _HOMEPAGE = "https://github.com/dehanalkautsar/IndoToD/tree/main/IndoCamRest"
32
+
33
+ _LICENSE = Licenses.CC_BY_SA_4_0.value
34
+
35
+ _URLS = {
36
+ _DATASETNAME: "https://raw.githubusercontent.com/dehanalkautsar/IndoToD/main/IndoCamRest/IndoCamRest676.json",
37
+ }
38
+
39
+ _SUPPORTED_TASKS = [Tasks.E2E_TASK_ORIENTED_DIALOGUE]
40
+
41
+ _SOURCE_VERSION = "1.0.0"
42
+
43
+ _SEACROWD_VERSION = "2024.06.20"
44
+
45
+
46
+ class IndoCamRest(datasets.GeneratorBasedBuilder):
47
+ """IndoToD: A Multi-Domain Indonesian Benchmark For End-to-End Task-Oriented Dialogue Systems"""
48
+
49
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
50
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
51
+
52
+ BUILDER_CONFIGS = [
53
+ SEACrowdConfig(
54
+ name="indocamrest_source",
55
+ version=SOURCE_VERSION,
56
+ description="IndoToD: IndoCamRest source schema",
57
+ schema="source",
58
+ subset_id="indocamrest",
59
+ ),
60
+ SEACrowdConfig(
61
+ name="indocamrest_seacrowd_tod",
62
+ version=SEACROWD_VERSION,
63
+ description="IndoToD: IndoCamRest SEACrowd End-to-end Task Oriented Dialogue schema",
64
+ schema="seacrowd_tod",
65
+ subset_id="indocamrest",
66
+ ),
67
+ ]
68
+
69
+ DEFAULT_CONFIG_NAME = "indocamrest_source"
70
+
71
+ def _info(self) -> datasets.DatasetInfo:
72
+ if self.config.schema == "source":
73
+ features = datasets.Features(
74
+ {
75
+ "index": datasets.Value("string"),
76
+ "dialogue_id": datasets.Value("int32"),
77
+ "finished": datasets.Value("string"),
78
+ "goal": {"constraints": [[datasets.Value("string")]], "request-slots": [datasets.Value("string")], "text": datasets.Value("string")},
79
+ "dial": [
80
+ {
81
+ "turn": datasets.Value("int32"),
82
+ "usr": {
83
+ "transcript": datasets.Value("string"),
84
+ "delex_transcript": datasets.Value("string"),
85
+ "slu": [{"act": datasets.Value("string"), "slots": [[datasets.Value("string")]]}],
86
+ },
87
+ "sys": {"sent": datasets.Value("string"), "delex_sent": datasets.Value("string"), "DA": [datasets.Value("string")]},
88
+ }
89
+ ],
90
+ }
91
+ )
92
+ elif self.config.schema == "seacrowd_tod":
93
+ features = schemas.tod_features
94
+ else:
95
+ raise NotImplementedError(f"Schema {self.config.schema} has not been implemented")
96
+
97
+ return datasets.DatasetInfo(
98
+ description=_DESCRIPTION,
99
+ features=features,
100
+ homepage=_HOMEPAGE,
101
+ license=_LICENSE,
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
106
+ urls = _URLS[_DATASETNAME]
107
+ data_dir = dl_manager.download_and_extract(urls)
108
+
109
+ return [
110
+ datasets.SplitGenerator(
111
+ name=datasets.Split.TRAIN,
112
+ gen_kwargs={
113
+ "filepath": data_dir,
114
+ "split": "train",
115
+ },
116
+ ),
117
+ ]
118
+
119
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
120
+ with open(filepath, "r+") as fw:
121
+ data = json.loads(fw.read())
122
+
123
+ if self.config.schema == "source":
124
+ for idx, example in enumerate(data):
125
+ example["index"] = str(idx)
126
+ yield str(idx), example
127
+
128
+ elif self.config.schema == "seacrowd_tod":
129
+ for idx, tod_dialogue in enumerate(data):
130
+ example = {}
131
+ example["dialogue_idx"] = idx
132
+
133
+ dialogue = []
134
+ for i in range(len(tod_dialogue["dial"]) + 1):
135
+ dial = {}
136
+ dial["turn_idx"] = i
137
+
138
+ # system_utterance properties
139
+ if i == 0:
140
+ # case if turn_idx == 0
141
+ dial["system_utterance"] = ""
142
+ dial["system_acts"] = []
143
+ else:
144
+ dial["system_utterance"] = tod_dialogue["dial"][i - 1]["sys"]["sent"]
145
+ # some system_acts is either to string or list of strings,
146
+ # converting all to list of strings
147
+ dial["system_acts"] = [[act] if isinstance(act, str) else act for act in tod_dialogue["dial"][i - 1]["sys"]["DA"]]
148
+
149
+ # user_utterance properties
150
+ dial["turn_label"] = []
151
+ dial["belief_state"] = []
152
+ if i == len(tod_dialogue["dial"]):
153
+ # case if turn_idx > len(dialogue) --> add dummy user_utterance
154
+ dial["user_utterance"] = ""
155
+ else:
156
+ dial["user_utterance"] = tod_dialogue["dial"][i]["usr"]["transcript"]
157
+ for j in range(len(tod_dialogue["dial"][i]["usr"]["slu"])):
158
+ dial["belief_state"].append({"slots": tod_dialogue["dial"][i]["usr"]["slu"][j]["slots"], "act": tod_dialogue["dial"][i]["usr"]["slu"][j]["act"]})
159
+
160
+ # append to dialogue
161
+ dialogue.append(dial)
162
+ example["dialogue"] = dialogue
163
+ yield str(idx), example