Datasets:
Languages:
English
Size:
1M<n<10M
ArXiv:
Tags:
task-oriented-dialog
task-oriented-dialogues
dialog-flow
dialog-modeling
dialogue-flow
dialogue-modeling
License:
sergioburdisso
commited on
Commit
•
3f27e03
1
Parent(s):
063eb32
Add initial loading script
Browse files- dialog2flow-dataset.py +196 -0
dialog2flow-dataset.py
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Copyright (c) 2024, Idiap Research Institute.
|
3 |
+
All rights reserved.
|
4 |
+
SPDX-License-Identifier: MIT License
|
5 |
+
For full license text, see the LICENSE file in the repo root
|
6 |
+
"""
|
7 |
+
|
8 |
+
#!/usr/bin/env python3
|
9 |
+
import os
|
10 |
+
import json
|
11 |
+
import datasets
|
12 |
+
from datasets import (GeneratorBasedBuilder,
|
13 |
+
BuilderConfig,
|
14 |
+
SplitGenerator,
|
15 |
+
DatasetInfo,
|
16 |
+
Features,
|
17 |
+
Value,
|
18 |
+
Version)
|
19 |
+
|
20 |
+
logger = datasets.logging.get_logger(__name__)
|
21 |
+
datasets.logging.disable_progress_bar()
|
22 |
+
|
23 |
+
_VERSION = Version("1.0.0")
|
24 |
+
_CITATION = """
|
25 |
+
@inproceedings{burdisso-etal-2024-dialog2flow,
|
26 |
+
title = "Dialog2Flow: Pre-training Soft-Contrastive Action-Driven Sentence Embeddings for Automatic Dialog Flow Extraction",
|
27 |
+
author = "Burdisso, Sergio and
|
28 |
+
Madikeri, Srikanth and
|
29 |
+
Motlicek, Petr",
|
30 |
+
booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing",
|
31 |
+
month = nov,
|
32 |
+
year = "2024",
|
33 |
+
address = "Miami",
|
34 |
+
publisher = "Association for Computational Linguistics",
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
DATASETS_PRETRAIN = ["dialog-acts", "slots", "dialog-actions"]
|
39 |
+
DATASETS_DS = {
|
40 |
+
'ABCD': ['test', 'train', 'val'],
|
41 |
+
'BiTOD': ['test', 'train', 'val'],
|
42 |
+
'DSTC2-Clean': ['test', 'train', 'val'],
|
43 |
+
'Disambiguation': ['test', 'train', 'val'],
|
44 |
+
'FRAMES': ['test', 'train'],
|
45 |
+
'HDSA-Dialog': ['test', 'train', 'val'],
|
46 |
+
'GECOR': ['train'],
|
47 |
+
'KETOD': ['test', 'train', 'val'],
|
48 |
+
'MS-DC': ['train'],
|
49 |
+
'MULTIWOZ2_2': ['test', 'train', 'val'],
|
50 |
+
'MulDoGO': ['test', 'train', 'val'],
|
51 |
+
'MultiWOZ_2.1': ['test', 'train', 'val'],
|
52 |
+
'SGD': ['test', 'train', 'val'],
|
53 |
+
'SimJointMovie': ['test', 'train', 'val'],
|
54 |
+
'SimJointRestaurant': ['test', 'train', 'val'],
|
55 |
+
'Taskmaster1': ['test', 'train', 'val'],
|
56 |
+
'Taskmaster2': ['train'],
|
57 |
+
'Taskmaster3': ['test', 'train', 'val'],
|
58 |
+
'WOZ2_0': ['test', 'train', 'val'],
|
59 |
+
# 'SimJointGEN': ['test', 'train', 'val'],
|
60 |
+
}
|
61 |
+
DATASETS = list(DATASETS_DS.keys()) + DATASETS_PRETRAIN
|
62 |
+
SPLIT2NAME = {
|
63 |
+
"train": datasets.Split.TRAIN,
|
64 |
+
"val": datasets.Split.VALIDATION,
|
65 |
+
"test": datasets.Split.TEST,
|
66 |
+
}
|
67 |
+
|
68 |
+
_URL = "https://huggingface.co/datasets/sergioburdisso/dialog2flow-dataset/tree/main/"
|
69 |
+
|
70 |
+
|
71 |
+
class Dialog2FlowConfig(BuilderConfig):
|
72 |
+
"""BuilderConfig for Dialog2Flow."""
|
73 |
+
|
74 |
+
def __init__(self, name, citation, url, **kwargs):
|
75 |
+
"""BuilderConfig for Dialog2Flow.
|
76 |
+
|
77 |
+
Args:
|
78 |
+
extra_features: `list[string]`, list of the features that will appear in the
|
79 |
+
feature dict. Should not include "label".
|
80 |
+
data_url: `string`, url to download the zip file from.
|
81 |
+
citation: `string`, citation for the data set.
|
82 |
+
url: `string`, url for information about the data set.
|
83 |
+
label_classes: `list[string]`, the list of classes for the label if the
|
84 |
+
label is present as a string. Non-string labels will be cast to either
|
85 |
+
'False' or 'True'.
|
86 |
+
**kwargs: keyword arguments forwarded to super.
|
87 |
+
"""
|
88 |
+
super(Dialog2FlowConfig, self).__init__(version=_VERSION, **kwargs)
|
89 |
+
self.name = name
|
90 |
+
self.citation = citation
|
91 |
+
self.url = url
|
92 |
+
|
93 |
+
|
94 |
+
class Dialog2FlowBuilder(GeneratorBasedBuilder):
|
95 |
+
BUILDER_CONFIG_CLASS = Dialog2FlowConfig
|
96 |
+
BUILDER_CONFIGS = []
|
97 |
+
for dataset in DATASETS:
|
98 |
+
BUILDER_CONFIGS.append(
|
99 |
+
Dialog2FlowConfig(
|
100 |
+
name=dataset,
|
101 |
+
description="",
|
102 |
+
citation=_CITATION,
|
103 |
+
url="https://github.com/idiap/dialog2flow",
|
104 |
+
))
|
105 |
+
|
106 |
+
DEFAULT_CONFIG_NAME = "dialog-actions"
|
107 |
+
|
108 |
+
def _info(self):
|
109 |
+
if self.config.name in DATASETS_PRETRAIN:
|
110 |
+
features = {"utterance": Value("string"), "label": Value("string")}
|
111 |
+
else:
|
112 |
+
features = datasets.features.Sequence(
|
113 |
+
{
|
114 |
+
"speaker": Value("string"),
|
115 |
+
"text": Value("string"),
|
116 |
+
"domains": [
|
117 |
+
Value("string")
|
118 |
+
],
|
119 |
+
"labels": {
|
120 |
+
"dialog_acts": {
|
121 |
+
"acts" : [Value("string")],
|
122 |
+
"main_acts" : [Value("string")],
|
123 |
+
"original_acts" : [Value("string")],
|
124 |
+
},
|
125 |
+
"slots": [Value("string")],
|
126 |
+
"intents": [Value("string")]
|
127 |
+
}
|
128 |
+
}
|
129 |
+
)
|
130 |
+
return DatasetInfo(
|
131 |
+
description="",
|
132 |
+
features=Features(features),
|
133 |
+
homepage=self.config.url,
|
134 |
+
citation=_CITATION,
|
135 |
+
)
|
136 |
+
|
137 |
+
def _split_generators(self, dl_manager):
|
138 |
+
if self.config.name in DATASETS_PRETRAIN:
|
139 |
+
# TODO
|
140 |
+
file_path = dl_manager.download({
|
141 |
+
"train": "train.csv", # full
|
142 |
+
"val": "eval.csv", # few shot subset
|
143 |
+
"test": "test.csv", # SpokenWOZ
|
144 |
+
})
|
145 |
+
splits = [
|
146 |
+
SplitGenerator(
|
147 |
+
name=datasets.Split.TRAIN,
|
148 |
+
gen_kwargs={
|
149 |
+
"file_path": file_path["train"],
|
150 |
+
"split": datasets.Split.TRAIN,
|
151 |
+
},
|
152 |
+
),
|
153 |
+
SplitGenerator(
|
154 |
+
name=datasets.Split.VALIDATION,
|
155 |
+
gen_kwargs={
|
156 |
+
"file_path": file_path["val"],
|
157 |
+
"split": datasets.Split.VALIDATION,
|
158 |
+
},
|
159 |
+
),
|
160 |
+
SplitGenerator(
|
161 |
+
name=datasets.Split.TEST,
|
162 |
+
gen_kwargs={
|
163 |
+
"file_path": file_path["test"],
|
164 |
+
"split": datasets.Split.TEST,
|
165 |
+
},
|
166 |
+
)
|
167 |
+
]
|
168 |
+
else:
|
169 |
+
splits = []
|
170 |
+
file_path = dl_manager.download({
|
171 |
+
"train": os.path.join(self.config.name, "data.json")
|
172 |
+
})
|
173 |
+
split_names = DATASETS_DS[self.config.name]
|
174 |
+
for split_name in split_names:
|
175 |
+
splits.append(
|
176 |
+
SplitGenerator(
|
177 |
+
name=SPLIT2NAME[split_name],
|
178 |
+
gen_kwargs={
|
179 |
+
"file_path": file_path["train"],
|
180 |
+
"split": SPLIT2NAME[split_name],
|
181 |
+
},
|
182 |
+
)
|
183 |
+
)
|
184 |
+
return splits
|
185 |
+
|
186 |
+
def _load_json(self, file_path):
|
187 |
+
with open(file_path, encoding="utf-8") as f:
|
188 |
+
data = json.loads(f.read())
|
189 |
+
return data
|
190 |
+
|
191 |
+
def _generate_examples(self, file_path, split):
|
192 |
+
data = self._load_json(file_path)
|
193 |
+
data = ((dial_id, dial) for dial_id, dial in data["dialogs"].items() if split in dial_id)
|
194 |
+
logger.info(f"generating {len(data)} examples from = {split}")
|
195 |
+
for dial_id, dial in data.items():
|
196 |
+
yield dial_id, dial
|