Upload with huggingface_hub
Browse files- README.md +65 -0
- data.zip +3 -0
- dummy_data.json +0 -0
- preprocess.py +358 -0
- shuffled_dial_ids.json +0 -0
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Dataset Card for SGD-X v5
|
2 |
+
|
3 |
+
- **Repository:** https://github.com/google-research-datasets/dstc8-schema-guided-dialogue/tree/master/sgd_x
|
4 |
+
- **Paper:** https://arxiv.org/pdf/2110.06800.pdf
|
5 |
+
- **Leaderboard:** None
|
6 |
+
- **Who transforms the dataset:** Qi Zhu(zhuq96 at gmail dot com)
|
7 |
+
|
8 |
+
### Dataset Summary
|
9 |
+
|
10 |
+
The **Schema-Guided Dialogue (SGD)** dataset consists of over 20k annotated multi-domain, task-oriented conversations between a human and a virtual assistant. These conversations involve interactions with services and APIs spanning 20 domains, such as banks, events, media, calendar, travel, and weather. For most of these domains, the dataset contains multiple different APIs, many of which have overlapping functionalities but different interfaces, which reflects common real-world scenarios. The wide range of available annotations can be used for intent prediction, slot filling, dialogue state tracking, policy imitation learning, language generation, and user simulation learning, among other tasks for developing large-scale virtual assistants. Additionally, the dataset contains unseen domains and services in the evaluation set to quantify the performance in zero-shot or few-shot settings.
|
11 |
+
|
12 |
+
The **SGD-X** dataset consists of 5 linguistic variants of every schema in the original SGD dataset. Linguistic variants were written by hundreds of paid crowd-workers. In the SGD-X directory, v1 represents the variant closest to the original schemas and v5 the farthest in terms of linguistic distance. To evaluate model performance on SGD-X schemas, dialogues must be converted using the script generate_sgdx_dialogues.py.
|
13 |
+
|
14 |
+
- **How to get the transformed data from original data:**
|
15 |
+
- Download [dstc8-schema-guided-dialogue-master.zip](https://github.com/google-research-datasets/dstc8-schema-guided-dialogue/archive/refs/heads/master.zip).
|
16 |
+
- Modified `sgd_x/generate_sgdx_dialogues.py` as https://github.com/google-research-datasets/dstc8-schema-guided-dialogue/issues/57
|
17 |
+
- Run `python -m sgd_x.generate_sgdx_dialogues` under `dstc8-schema-guided-dialogue-master` dir which need tensorflow installed.
|
18 |
+
- Run `python preprocess.py` in the current directory.
|
19 |
+
- **Main changes of the transformation:**
|
20 |
+
- Lower case original `act` as `intent`.
|
21 |
+
- Add `count` slot for each domain, non-categorical, find span by text matching.
|
22 |
+
- Categorize `dialogue acts` according to the `intent`.
|
23 |
+
- Concatenate multiple values using `|`.
|
24 |
+
- Retain `active_intent`, `requested_slots`, `service_call`.
|
25 |
+
- **Annotations:**
|
26 |
+
- dialogue acts, state, db_results, service_call, active_intent, requested_slots.
|
27 |
+
|
28 |
+
### Supported Tasks and Leaderboards
|
29 |
+
|
30 |
+
NLU, DST, Policy, NLG, E2E
|
31 |
+
|
32 |
+
### Languages
|
33 |
+
|
34 |
+
English
|
35 |
+
|
36 |
+
### Data Splits
|
37 |
+
|
38 |
+
| split | dialogues | utterances | avg_utt | avg_tokens | avg_domains | cat slot match(state) | cat slot match(goal) | cat slot match(dialogue act) | non-cat slot span(dialogue act) |
|
39 |
+
|------------|-------------|--------------|-----------|--------------|---------------|-------------------------|------------------------|--------------------------------|-----------------------------------|
|
40 |
+
| train | 16142 | 329964 | 20.44 | 9.75 | 1.84 | 100 | - | 100 | 100 |
|
41 |
+
| validation | 2482 | 48726 | 19.63 | 9.66 | 1.84 | 100 | - | 100 | 100 |
|
42 |
+
| test | 4201 | 84594 | 20.14 | 10.4 | 2.02 | 100 | - | 100 | 100 |
|
43 |
+
| all | 22825 | 463284 | 20.3 | 9.86 | 1.87 | 100 | - | 100 | 100 |
|
44 |
+
|
45 |
+
45 domains: ['Banks_15', 'Buses_15', 'Buses_25', 'Calendar_15', 'Events_15', 'Events_25', 'Flights_15', 'Flights_25', 'Homes_15', 'Hotels_15', 'Hotels_25', 'Hotels_35', 'Media_15', 'Movies_15', 'Music_15', 'Music_25', 'RentalCars_15', 'RentalCars_25', 'Restaurants_15', 'RideSharing_15', 'RideSharing_25', 'Services_15', 'Services_25', 'Services_35', 'Travel_15', 'Weather_15', 'Alarm_15', 'Banks_25', 'Flights_35', 'Hotels_45', 'Media_25', 'Movies_25', 'Restaurants_25', 'Services_45', 'Buses_35', 'Events_35', 'Flights_45', 'Homes_25', 'Media_35', 'Messaging_15', 'Movies_35', 'Music_35', 'Payment_15', 'RentalCars_35', 'Trains_15']
|
46 |
+
- **cat slot match**: how many values of categorical slots are in the possible values of ontology in percentage.
|
47 |
+
- **non-cat slot span**: how many values of non-categorical slots have span annotation in percentage.
|
48 |
+
|
49 |
+
### Citation
|
50 |
+
|
51 |
+
```
|
52 |
+
@inproceedings{lee2022sgd,
|
53 |
+
title={SGD-X: A Benchmark for Robust Generalization in Schema-Guided Dialogue Systems},
|
54 |
+
author={Lee, Harrison and Gupta, Raghav and Rastogi, Abhinav and Cao, Yuan and Zhang, Bin and Wu, Yonghui},
|
55 |
+
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
|
56 |
+
volume={36},
|
57 |
+
number={10},
|
58 |
+
pages={10938--10946},
|
59 |
+
year={2022}
|
60 |
+
}
|
61 |
+
```
|
62 |
+
|
63 |
+
### Licensing Information
|
64 |
+
|
65 |
+
[**CC BY-SA 4.0**](https://creativecommons.org/licenses/by-sa/4.0/)
|
data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f65a8db5e0eecf4b2d7b1ca8c2190222e14266bda202720cdae4d09e4ca7bbfc
|
3 |
+
size 38061299
|
dummy_data.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
preprocess.py
ADDED
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from zipfile import ZipFile, ZIP_DEFLATED
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
from pprint import pprint
|
5 |
+
from copy import deepcopy
|
6 |
+
from collections import Counter
|
7 |
+
from tqdm import tqdm
|
8 |
+
from shutil import rmtree
|
9 |
+
import re
|
10 |
+
|
11 |
+
digit2word = {
|
12 |
+
'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five',
|
13 |
+
'6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10': 'ten'
|
14 |
+
}
|
15 |
+
|
16 |
+
match = {
|
17 |
+
'0': 0,
|
18 |
+
'1': 0,
|
19 |
+
'>1': 0,
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
def pharse_in_sen(phrase, sen):
|
24 |
+
'''
|
25 |
+
match value in the sentence
|
26 |
+
:param phrase: str
|
27 |
+
:param sen: str
|
28 |
+
:return: start, end if matched, else None, None
|
29 |
+
'''
|
30 |
+
assert isinstance(phrase, str)
|
31 |
+
pw = '(^|[\s,\.:\?!-])(?P<v>{})([\s,\.:\?!-]|$)'
|
32 |
+
pn = '(^|[\s\?!-]|\D[,\.:])(?P<v>{})($|[\s\?!-]|[,\.:]\D|[,\.:]$)'
|
33 |
+
if phrase.isdigit():
|
34 |
+
pattern = pn
|
35 |
+
else:
|
36 |
+
pattern = pw
|
37 |
+
p = re.compile(pattern.format(re.escape(phrase)), re.I)
|
38 |
+
m = re.search(p, sen)
|
39 |
+
if m:
|
40 |
+
num = len(re.findall(p, sen))
|
41 |
+
if num > 1:
|
42 |
+
match['>1'] += 1
|
43 |
+
else:
|
44 |
+
match['1'] += 1
|
45 |
+
return m.span('v'), num
|
46 |
+
if phrase.isdigit() and phrase in digit2word:
|
47 |
+
phrase = digit2word[phrase]
|
48 |
+
p = re.compile(pw.format(re.escape(phrase)), re.I)
|
49 |
+
m = re.search(p, sen)
|
50 |
+
if m:
|
51 |
+
num = len(re.findall(p, sen))
|
52 |
+
if num > 1:
|
53 |
+
match['>1'] += 1
|
54 |
+
else:
|
55 |
+
match['1'] += 1
|
56 |
+
return m.span('v'), num
|
57 |
+
match['0'] += 1
|
58 |
+
return (None, None), 0
|
59 |
+
|
60 |
+
|
61 |
+
def sys_intent():
|
62 |
+
"""from original data README.md"""
|
63 |
+
return {
|
64 |
+
"inform": {"description": "Inform the value for a slot to the user."},
|
65 |
+
"request": {"description": "Request the value of a slot from the user."},
|
66 |
+
"confirm": {"description": "Confirm the value of a slot before making a transactional service call."},
|
67 |
+
"offer": {"description": "Offer a certain value for a slot to the user."},
|
68 |
+
"notify_success": {"description": "Inform the user that their request was successful."},
|
69 |
+
"notify_failure": {"description": "Inform the user that their request failed."},
|
70 |
+
"inform_count": {"description": "Inform the number of items found that satisfy the user's request."},
|
71 |
+
"offer_intent": {"description": "Offer a new intent to the user."},
|
72 |
+
"req_more": {"description": "Asking the user if they need anything else."},
|
73 |
+
"goodbye": {"description": "End the dialogue."},
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
def usr_intent():
|
78 |
+
"""from original data README.md"""
|
79 |
+
return {
|
80 |
+
"inform_intent": {"description": "Express the desire to perform a certain task to the system."},
|
81 |
+
"negate_intent": {"description": "Negate the intent which has been offered by the system."},
|
82 |
+
"affirm_intent": {"description": "Agree to the intent which has been offered by the system."},
|
83 |
+
"inform": {"description": "Inform the value of a slot to the system."},
|
84 |
+
"request": {"description": "Request the value of a slot from the system."},
|
85 |
+
"affirm": {"description": "Agree to the system's proposition. "},
|
86 |
+
"negate": {"description": "Deny the system's proposal."},
|
87 |
+
"select": {"description": "Select a result being offered by the system."},
|
88 |
+
"request_alts": {"description": "Ask for more results besides the ones offered by the system."},
|
89 |
+
"thank_you": {"description": "Thank the system."},
|
90 |
+
"goodbye": {"description": "End the dialogue."},
|
91 |
+
}
|
92 |
+
|
93 |
+
|
94 |
+
def get_intent():
|
95 |
+
"""merge sys & usr intent"""
|
96 |
+
return {
|
97 |
+
"inform": {"description": "Inform the value for a slot."},
|
98 |
+
"request": {"description": "Request the value of a slot."},
|
99 |
+
"confirm": {"description": "Confirm the value of a slot before making a transactional service call."},
|
100 |
+
"offer": {"description": "Offer a certain value for a slot to the user."},
|
101 |
+
"notify_success": {"description": "Inform the user that their request was successful."},
|
102 |
+
"notify_failure": {"description": "Inform the user that their request failed."},
|
103 |
+
"inform_count": {"description": "Inform the number of items found that satisfy the user's request."},
|
104 |
+
"offer_intent": {"description": "Offer a new intent to the user."},
|
105 |
+
"req_more": {"description": "Asking the user if they need anything else."},
|
106 |
+
"goodbye": {"description": "End the dialogue."},
|
107 |
+
"inform_intent": {"description": "Express the desire to perform a certain task to the system."},
|
108 |
+
"negate_intent": {"description": "Negate the intent which has been offered by the system."},
|
109 |
+
"affirm_intent": {"description": "Agree to the intent which has been offered by the system."},
|
110 |
+
"affirm": {"description": "Agree to the system's proposition. "},
|
111 |
+
"negate": {"description": "Deny the system's proposal."},
|
112 |
+
"select": {"description": "Select a result being offered by the system."},
|
113 |
+
"request_alts": {"description": "Ask for more results besides the ones offered by the system."},
|
114 |
+
"thank_you": {"description": "Thank the system."},
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
def preprocess():
|
119 |
+
original_data_dir = 'dstc8-schema-guided-dialogue-master/sgd_x/data/v5'
|
120 |
+
dataset_name = 'sgd5'
|
121 |
+
new_data_dir = 'data'
|
122 |
+
|
123 |
+
if not os.path.exists(original_data_dir):
|
124 |
+
raise FileNotFoundError(f'cannot find original data {original_data_dir}, should manually download dstc8-schema-guided-dialogue-master.zip from https://github.com/google-research-datasets/dstc8-schema-guided-dialogue and run `python3 -m sgd_x.generate_sgdx_dialogues`')
|
125 |
+
|
126 |
+
os.makedirs(new_data_dir, exist_ok=True)
|
127 |
+
|
128 |
+
dialogues = []
|
129 |
+
ontology = {'domains': {},
|
130 |
+
'intents': get_intent(),
|
131 |
+
'state': {},
|
132 |
+
'dialogue_acts': {
|
133 |
+
"categorical": {},
|
134 |
+
"non-categorical": {},
|
135 |
+
"binary": {}
|
136 |
+
}}
|
137 |
+
splits = ['train', 'validation', 'test']
|
138 |
+
for data_split in splits:
|
139 |
+
data_dir = os.path.join(original_data_dir, data_split if data_split != 'validation' else 'dev')
|
140 |
+
# schema => ontology
|
141 |
+
with open(os.path.join(data_dir, 'schema.json')) as f:
|
142 |
+
data = json.load(f)
|
143 |
+
for schema in data:
|
144 |
+
domain = schema['service_name']
|
145 |
+
ontology['domains'].setdefault(domain, {})
|
146 |
+
ontology['domains'][domain]['description'] = schema['description']
|
147 |
+
ontology['domains'][domain].setdefault('slots', {})
|
148 |
+
ontology['domains'][domain]['active_intents'] = schema['intents']
|
149 |
+
ontology['state'].setdefault(domain, {})
|
150 |
+
for slot in schema['slots']:
|
151 |
+
ontology['domains'][domain]['slots'][slot['name']] = {
|
152 |
+
"description": slot['description'],
|
153 |
+
"is_categorical": slot['is_categorical'],
|
154 |
+
"possible_values": slot['possible_values']
|
155 |
+
}
|
156 |
+
ontology['state'][domain][slot['name']] = ''
|
157 |
+
# add 'count' slot
|
158 |
+
ontology['domains'][domain]['slots']['count'] = {
|
159 |
+
"description": "the number of items found that satisfy the user's request.",
|
160 |
+
"is_categorical": False,
|
161 |
+
"possible_values": []
|
162 |
+
}
|
163 |
+
|
164 |
+
# dialog
|
165 |
+
cnt = 0
|
166 |
+
for root, dirs, files in os.walk(data_dir):
|
167 |
+
fs = sorted([x for x in files if 'dialogues' in x])
|
168 |
+
for f in tqdm(fs, desc='processing schema-guided-{}'.format(data_split)):
|
169 |
+
data = json.load(open(os.path.join(data_dir, f)))
|
170 |
+
for d in data:
|
171 |
+
dialogue = {
|
172 |
+
"dataset": dataset_name,
|
173 |
+
"data_split": data_split,
|
174 |
+
"dialogue_id": f'{dataset_name}-{data_split}-{cnt}',
|
175 |
+
"original_id": d['dialogue_id'],
|
176 |
+
"domains": d['services'],
|
177 |
+
"goal": { # no goal
|
178 |
+
'description': '',
|
179 |
+
'inform': {},
|
180 |
+
'request': {}
|
181 |
+
},
|
182 |
+
"turns": []
|
183 |
+
}
|
184 |
+
cnt += 1
|
185 |
+
prev_state = {}
|
186 |
+
for domain in dialogue['domains']:
|
187 |
+
prev_state.setdefault(domain, deepcopy(ontology['state'][domain]))
|
188 |
+
|
189 |
+
for utt_idx, t in enumerate(d['turns']):
|
190 |
+
speaker = t['speaker'].lower()
|
191 |
+
turn = {
|
192 |
+
'speaker': speaker,
|
193 |
+
'utterance': t['utterance'],
|
194 |
+
'utt_idx': utt_idx,
|
195 |
+
'dialogue_acts': {
|
196 |
+
'binary': [],
|
197 |
+
'categorical': [],
|
198 |
+
'non-categorical': [],
|
199 |
+
},
|
200 |
+
}
|
201 |
+
for frame in t['frames']:
|
202 |
+
domain = frame['service']
|
203 |
+
for action in frame['actions']:
|
204 |
+
intent = action['act'].lower() # lowercase intent
|
205 |
+
assert intent in ontology['intents'], [intent]
|
206 |
+
slot = action['slot']
|
207 |
+
value_list = action['values']
|
208 |
+
if action['act'] in ['REQ_MORE', 'AFFIRM', 'NEGATE', 'THANK_YOU', 'GOODBYE']:
|
209 |
+
# Slot and values are always empty
|
210 |
+
assert slot == "" and len(value_list) == 0
|
211 |
+
turn['dialogue_acts']['binary'].append({
|
212 |
+
"intent": intent,
|
213 |
+
"domain": '',
|
214 |
+
"slot": ''
|
215 |
+
})
|
216 |
+
elif action['act'] in ['NOTIFY_SUCCESS', 'NOTIFY_FAILURE', 'REQUEST_ALTS', 'AFFIRM_INTENT', 'NEGATE_INTENT']:
|
217 |
+
# Slot and values are always empty
|
218 |
+
assert slot == "" and len(value_list) == 0
|
219 |
+
turn['dialogue_acts']['binary'].append({
|
220 |
+
"intent": intent,
|
221 |
+
"domain": domain,
|
222 |
+
"slot": ''
|
223 |
+
})
|
224 |
+
elif action['act'] in ['OFFER_INTENT', 'INFORM_INTENT']:
|
225 |
+
# slot containing the intent being offered.
|
226 |
+
assert slot == 'intent' and len(value_list) == 1, print(slot, action, d['dialogue_id'], utt_idx)
|
227 |
+
turn['dialogue_acts']['binary'].append({
|
228 |
+
"intent": intent,
|
229 |
+
"domain": domain,
|
230 |
+
"slot": value_list[0]
|
231 |
+
})
|
232 |
+
elif action['act'] in ['REQUEST'] and len(value_list) == 0:
|
233 |
+
# always contains a slot, but values are optional.
|
234 |
+
assert slot in ontology['domains'][domain]['slots'], f'{domain}-{slot}'
|
235 |
+
turn['dialogue_acts']['binary'].append({
|
236 |
+
"intent": intent,
|
237 |
+
"domain": domain,
|
238 |
+
"slot": slot
|
239 |
+
})
|
240 |
+
elif action['act'] in ['SELECT'] and len(value_list) == 0:
|
241 |
+
# (slot=='' and len(value_list) == 0) or (slot!='' and len(value_list) > 0)
|
242 |
+
assert slot == '', f'{domain}-{slot}-{action}'
|
243 |
+
turn['dialogue_acts']['binary'].append({
|
244 |
+
"intent": intent,
|
245 |
+
"domain": domain,
|
246 |
+
"slot": slot
|
247 |
+
})
|
248 |
+
elif action['act'] in ['INFORM_COUNT']:
|
249 |
+
# always has "count" as the slot, and a single element in values for the number of results obtained by the system.
|
250 |
+
assert slot == 'count' and len(value_list) == 1
|
251 |
+
value = value_list[0]
|
252 |
+
|
253 |
+
turn['dialogue_acts']['non-categorical'].append({
|
254 |
+
"intent": intent,
|
255 |
+
"domain": domain,
|
256 |
+
"slot": slot,
|
257 |
+
"value": value,
|
258 |
+
})
|
259 |
+
|
260 |
+
# find char span
|
261 |
+
(start, end), num = pharse_in_sen(value, t['utterance'])
|
262 |
+
assert num > 0, f'{value}-{t["utterance"]}' # {1:20086, 2:341, 3:19}
|
263 |
+
assert value.lower() == t['utterance'][start:end].lower() \
|
264 |
+
or digit2word[value].lower() == t['utterance'][start:end].lower()
|
265 |
+
# first match is always the choice
|
266 |
+
turn['dialogue_acts']['non-categorical'][-1].update({
|
267 |
+
"value": t['utterance'][start:end], "start": start, "end": end
|
268 |
+
})
|
269 |
+
else:
|
270 |
+
# have slot & value
|
271 |
+
assert domain in ontology['domains'], print(ontology['domains'])
|
272 |
+
assert slot in ontology['domains'][domain]['slots'], print(slot, action, d['dialogue_id'], utt_idx)
|
273 |
+
if ontology['domains'][domain]['slots'][slot]['is_categorical']:
|
274 |
+
possible_values = [value.lower() for value in ontology['domains'][domain]['slots'][slot]['possible_values']]
|
275 |
+
for value in value_list:
|
276 |
+
if value.lower() not in possible_values and value != 'dontcare':
|
277 |
+
ontology['domains'][domain]['slots'][slot]['possible_values'].append(value)
|
278 |
+
print(f'add value to ontology\t{domain}-{slot}-{value}', possible_values)
|
279 |
+
turn['dialogue_acts']['categorical'].append({
|
280 |
+
"intent": intent,
|
281 |
+
"domain": domain,
|
282 |
+
"slot": slot,
|
283 |
+
"value": value,
|
284 |
+
})
|
285 |
+
else:
|
286 |
+
# span info in frame['slots']
|
287 |
+
for value in value_list:
|
288 |
+
for slot_info in frame['slots']:
|
289 |
+
start = slot_info['start']
|
290 |
+
end = slot_info['exclusive_end']
|
291 |
+
if slot_info['slot'] == slot and t['utterance'][start:end].lower() == value.lower():
|
292 |
+
assert t['utterance'][start:end] == value, f'{action}-{slot_info}-{t["utterance"][start:end]}'
|
293 |
+
turn['dialogue_acts']['non-categorical'].append({
|
294 |
+
"intent": intent,
|
295 |
+
"domain": domain,
|
296 |
+
"slot": slot,
|
297 |
+
"value": value,
|
298 |
+
"start": start,
|
299 |
+
"end": end
|
300 |
+
})
|
301 |
+
break
|
302 |
+
else:
|
303 |
+
assert value == 'dontcare', f'{action}-{slot_info}'
|
304 |
+
|
305 |
+
if speaker == 'user':
|
306 |
+
state = deepcopy(prev_state)
|
307 |
+
active_intent = {}
|
308 |
+
requested_slots = {}
|
309 |
+
for frame in t['frames']:
|
310 |
+
domain = frame['service']
|
311 |
+
active_intent[domain] = frame['state']['active_intent']
|
312 |
+
requested_slots[domain] = frame['state']['requested_slots']
|
313 |
+
for slot in state[domain]:
|
314 |
+
if slot in frame['state']['slot_values']:
|
315 |
+
value_list = frame['state']['slot_values'][slot]
|
316 |
+
state[domain][slot] = value_list[0]
|
317 |
+
for value in value_list[1:]:
|
318 |
+
state[domain][slot] += '|' + value
|
319 |
+
else:
|
320 |
+
state[domain][slot] = ''
|
321 |
+
prev_state = state
|
322 |
+
turn['state'] = state
|
323 |
+
turn['active_intent'] = active_intent
|
324 |
+
turn['requested_slots'] = requested_slots
|
325 |
+
else:
|
326 |
+
# service_call and service_results
|
327 |
+
turn['service_call'] = {}
|
328 |
+
turn['db_results'] = {}
|
329 |
+
for frame in t['frames']:
|
330 |
+
if 'service_call' not in frame:
|
331 |
+
continue
|
332 |
+
domain = frame['service']
|
333 |
+
turn['service_call'][domain] = frame['service_call']
|
334 |
+
turn['db_results'][domain] = frame['service_results']
|
335 |
+
|
336 |
+
# add to dialogue_acts dictionary in the ontology
|
337 |
+
for da_type in turn['dialogue_acts']:
|
338 |
+
das = turn['dialogue_acts'][da_type]
|
339 |
+
for da in das:
|
340 |
+
ontology["dialogue_acts"][da_type].setdefault((da['intent'], da['domain'], da['slot']), {})
|
341 |
+
ontology["dialogue_acts"][da_type][(da['intent'], da['domain'], da['slot'])][speaker] = True
|
342 |
+
dialogue['turns'].append(turn)
|
343 |
+
dialogues.append(dialogue)
|
344 |
+
|
345 |
+
for da_type in ontology['dialogue_acts']:
|
346 |
+
ontology["dialogue_acts"][da_type] = sorted([str({'user': speakers.get('user', False), 'system': speakers.get('system', False), 'intent':da[0],'domain':da[1], 'slot':da[2]}) for da, speakers in ontology["dialogue_acts"][da_type].items()])
|
347 |
+
json.dump(dialogues[:10], open(f'dummy_data.json', 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
348 |
+
json.dump(ontology, open(f'{new_data_dir}/ontology.json', 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
349 |
+
json.dump(dialogues, open(f'{new_data_dir}/dialogues.json', 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
|
350 |
+
with ZipFile('data.zip', 'w', ZIP_DEFLATED) as zf:
|
351 |
+
for filename in os.listdir(new_data_dir):
|
352 |
+
zf.write(f'{new_data_dir}/{filename}')
|
353 |
+
# rmtree(original_data_dir)
|
354 |
+
rmtree(new_data_dir)
|
355 |
+
return dialogues, ontology
|
356 |
+
|
357 |
+
if __name__ == '__main__':
|
358 |
+
preprocess()
|
shuffled_dial_ids.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|