Datasets:

Languages:
Indonesian
ArXiv:
holylovenia commited on
Commit
dc2f917
1 Parent(s): e032ad8

Upload cod.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. cod.py +158 -0
cod.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from nusacrowd.utils.configs import NusantaraConfig
8
+ from nusacrowd.utils.constants import Tasks
9
+
10
+ _CITATION = """\
11
+ @article{majewska2022cross,
12
+ title={Cross-lingual dialogue dataset creation via outline-based generation},
13
+ author={Majewska, Olga and Razumovskaia, Evgeniia and Ponti, Edoardo Maria and Vuli{\'c}, Ivan and Korhonen, Anna},
14
+ journal={arXiv preprint arXiv:2201.13405},
15
+ year={2022}
16
+ }
17
+ """
18
+
19
+ _LANGUAGES = ["ind"]
20
+ _LOCAL = False
21
+
22
+ _DATASETNAME = "cod"
23
+
24
+ _DESCRIPTION = """\
25
+ Cross-lingual Outline-based Dialogue (COD) is a dataset comprised of manually generated, localized, and cross-lingually aligned Task-Oriented-Dialogue (TOD) data that served as the source of dialogue prompts.
26
+ COD enables natural language understanding, dialogue state tracking, and end-to-end dialogue modeling and evaluation.
27
+ Majewska et al. (2022) create COD using a novel outline-based annotation pipeline for multilingual TOD by Majewska et al. (2022).
28
+ English Schema-Guided Dialogue (SGD; Shah et al., 2018; Rastogi et al., 2020) dataset is automatically sampled and mapped into outlines. The outlines are then paraphrased and adapted to the local target domain by human subjects.
29
+ """
30
+
31
+ _HOMEPAGE = "https://github.com/cambridgeltl/COD"
32
+
33
+ _LICENSE = "Unknown"
34
+
35
+ _URLS = {
36
+ _DATASETNAME: {
37
+ "validation": "https://raw.githubusercontent.com/cambridgeltl/COD/main/id_dev.json",
38
+ "test": "https://raw.githubusercontent.com/cambridgeltl/COD/main/id_test.json",
39
+ },
40
+ }
41
+
42
+ _SUPPORTED_TASKS = [Tasks.DIALOGUE_SYSTEM]
43
+
44
+ _SOURCE_VERSION = "1.0.0"
45
+
46
+ _NUSANTARA_VERSION = "1.0.0"
47
+
48
+
49
+ class NewDataset(datasets.GeneratorBasedBuilder):
50
+ """Cross-lingual Outline-based Dialogue (COD) is a dataset comprises manually generated, localised, and cross-lingually aligned Task-Oriented-Dialogue (TOD) data which served as the source of dialogue prompts."""
51
+
52
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
53
+ NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
54
+
55
+ BUILDER_CONFIGS = [
56
+ NusantaraConfig(
57
+ name="cod_source",
58
+ version=SOURCE_VERSION,
59
+ description="Cross-lingual Outline-based Dialogue (COD) source schema",
60
+ schema="source",
61
+ subset_id="cod",
62
+ ),
63
+ ]
64
+
65
+ DEFAULT_CONFIG_NAME = "cod_source"
66
+
67
+ def _info(self) -> datasets.DatasetInfo:
68
+
69
+ if self.config.schema == "source":
70
+ features = datasets.Features(
71
+ {
72
+ "index": datasets.Value("string"),
73
+ "dialogue_id": datasets.Value("string"),
74
+ "services": [datasets.Value("string")],
75
+ "turns": [
76
+ {
77
+ "speaker": datasets.Value("string"),
78
+ "utterance": datasets.Value("string"),
79
+ "frames": [
80
+ {
81
+ "actions": [
82
+ {
83
+ "act": datasets.Value("string"),
84
+ "slot": datasets.Value("string"),
85
+ "values": [datasets.Value("string")],
86
+ }
87
+ ],
88
+ "service": datasets.Value("string"),
89
+ "slots": [
90
+ {
91
+ "exclusive_end": datasets.Value("int32"),
92
+ "slot": datasets.Value("string"),
93
+ "start": datasets.Value("int32"),
94
+ }
95
+ ],
96
+ "state": {
97
+ "active_intent": datasets.Value("string"),
98
+ "requested_slots": [datasets.Value("string")],
99
+ "slot_values": [
100
+ {"slot": datasets.Value("string"), "values": [datasets.Value("string")]},
101
+ ],
102
+ },
103
+ }
104
+ ],
105
+ }
106
+ ],
107
+ }
108
+ )
109
+ else:
110
+ raise NotImplementedError()
111
+
112
+ return datasets.DatasetInfo(
113
+ description=_DESCRIPTION,
114
+ features=features,
115
+ homepage=_HOMEPAGE,
116
+ license=_LICENSE,
117
+ citation=_CITATION,
118
+ )
119
+
120
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
121
+ urls = _URLS[_DATASETNAME]
122
+ data_dir = dl_manager.download_and_extract(urls)
123
+
124
+ return [
125
+ datasets.SplitGenerator(
126
+ name=datasets.Split.TEST,
127
+ gen_kwargs={
128
+ "filepath": data_dir["test"],
129
+ "split": "test",
130
+ },
131
+ ),
132
+ datasets.SplitGenerator(
133
+ name=datasets.Split.VALIDATION,
134
+ gen_kwargs={
135
+ "filepath": data_dir["validation"],
136
+ "split": "dev",
137
+ },
138
+ ),
139
+ ]
140
+
141
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
142
+
143
+ with open(filepath, "r+") as fw:
144
+ data = json.loads(fw.read())
145
+
146
+ if self.config.schema == "source":
147
+ for idx, example in enumerate(data):
148
+ example["index"] = str(idx)
149
+ for turn in example["turns"]:
150
+ for frame in turn["frames"]:
151
+ if "state" not in frame:
152
+ continue
153
+ ls_slot_values = []
154
+ for slot in frame["state"]["slot_values"]:
155
+ ls_slot_values.append({"slot": slot, "values": frame["state"]["slot_values"][slot]})
156
+ frame["state"]["slot_values"] = ls_slot_values
157
+
158
+ yield str(idx), example