hsienchin1993 commited on
Commit
2edd6d5
1 Parent(s): ec6dc83

Upload 2 files

Browse files
Files changed (2) hide show
  1. preprocess.py +1217 -0
  2. shuffled_dial_ids.json +1 -0
preprocess.py ADDED
@@ -0,0 +1,1217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import copy
2
+ import re
3
+ from zipfile import ZipFile, ZIP_DEFLATED
4
+ from shutil import copy2, rmtree
5
+ import json
6
+ import os
7
+ from tqdm import tqdm
8
+ from collections import Counter
9
+ from pprint import pprint
10
+ from nltk.tokenize import TreebankWordTokenizer, PunktSentenceTokenizer
11
+ import pickle
12
+
13
+ ontology = {
14
+ "domains": { # descriptions are adapted from multiwoz22, but is_categorical may be different
15
+ "attraction": {
16
+ "description": "find an attraction",
17
+ "slots": {
18
+ "area": {
19
+ "description": "area to search for attractions",
20
+ "is_categorical": True,
21
+ "possible_values": [
22
+ "centre",
23
+ "east",
24
+ "north",
25
+ "south",
26
+ "west"
27
+ ]
28
+ },
29
+ "name": {
30
+ "description": "name of the attraction",
31
+ "is_categorical": False,
32
+ "possible_values": []
33
+ },
34
+ "type": {
35
+ "description": "type of the attraction",
36
+ "is_categorical": True,
37
+ "possible_values": [
38
+ "architecture",
39
+ "boat",
40
+ "cinema",
41
+ "college",
42
+ "concerthall",
43
+ "entertainment",
44
+ "museum",
45
+ "multiple sports",
46
+ "nightclub",
47
+ "park",
48
+ "swimmingpool",
49
+ "theatre"
50
+ ]
51
+ },
52
+ "entrance fee": {
53
+ "description": "how much is the entrance fee",
54
+ "is_categorical": False,
55
+ "possible_values": []
56
+ },
57
+ "open hours": {
58
+ "description": "open hours of the attraction",
59
+ "is_categorical": False,
60
+ "possible_values": []
61
+ },
62
+ "address": {
63
+ "description": "address of the attraction",
64
+ "is_categorical": False,
65
+ "possible_values": []
66
+ },
67
+ "phone": {
68
+ "description": "phone number of the attraction",
69
+ "is_categorical": False,
70
+ "possible_values": []
71
+ },
72
+ "postcode": {
73
+ "description": "postcode of the attraction",
74
+ "is_categorical": False,
75
+ "possible_values": []
76
+ },
77
+ "choice": {
78
+ "description": "number of attractions that meet the requirement",
79
+ "is_categorical": False,
80
+ "possible_values": []
81
+ }
82
+ }
83
+ },
84
+ "hotel": {
85
+ "description": "find and book a hotel",
86
+ "slots": {
87
+ "internet": {
88
+ "description": "whether the hotel has internet",
89
+ "is_categorical": True,
90
+ "possible_values": [
91
+ "free",
92
+ "no",
93
+ "yes"
94
+ ]
95
+ },
96
+ "parking": {
97
+ "description": "whether the hotel has parking",
98
+ "is_categorical": True,
99
+ "possible_values": [
100
+ "free",
101
+ "no",
102
+ "yes"
103
+ ]
104
+ },
105
+ "area": {
106
+ "description": "area or place of the hotel",
107
+ "is_categorical": True,
108
+ "possible_values": [
109
+ "centre",
110
+ "east",
111
+ "north",
112
+ "south",
113
+ "west"
114
+ ]
115
+ },
116
+ "stars": {
117
+ "description": "star rating of the hotel",
118
+ "is_categorical": True,
119
+ "possible_values": [
120
+ "0",
121
+ "1",
122
+ "2",
123
+ "3",
124
+ "4",
125
+ "5"
126
+ ]
127
+ },
128
+ "price range": {
129
+ "description": "price budget of the hotel",
130
+ "is_categorical": True,
131
+ "possible_values": [
132
+ "expensive",
133
+ "cheap",
134
+ "moderate"
135
+ ]
136
+ },
137
+ "type": {
138
+ "description": "what is the type of the hotel",
139
+ "is_categorical": False,
140
+ "possible_values": [
141
+ "guesthouse",
142
+ "hotel"
143
+ ]
144
+ },
145
+ "name": {
146
+ "description": "name of the hotel",
147
+ "is_categorical": False,
148
+ "possible_values": []
149
+ },
150
+ "book people": {
151
+ "description": "number of people for the hotel booking",
152
+ "is_categorical": False,
153
+ "possible_values": []
154
+ },
155
+ "book stay": {
156
+ "description": "length of stay at the hotel",
157
+ "is_categorical": False,
158
+ "possible_values": []
159
+ },
160
+ "book day": {
161
+ "description": "day of the hotel booking",
162
+ "is_categorical": True,
163
+ "possible_values": [
164
+ "monday",
165
+ "tuesday",
166
+ "wednesday",
167
+ "thursday",
168
+ "friday",
169
+ "saturday",
170
+ "sunday"
171
+ ]
172
+ },
173
+ "phone": {
174
+ "description": "phone number of the hotel",
175
+ "is_categorical": False,
176
+ "possible_values": []
177
+ },
178
+ "postcode": {
179
+ "description": "postcode of the hotel",
180
+ "is_categorical": False,
181
+ "possible_values": []
182
+ },
183
+ "address": {
184
+ "description": "address of the hotel",
185
+ "is_categorical": False,
186
+ "possible_values": []
187
+ },
188
+ "ref": {
189
+ "description": "reference number of the hotel booking",
190
+ "is_categorical": False,
191
+ "possible_values": []
192
+ },
193
+ "choice": {
194
+ "description": "number of hotels that meet the requirement",
195
+ "is_categorical": False,
196
+ "possible_values": []
197
+ }
198
+ }
199
+ },
200
+ "taxi": {
201
+ "description": "rent taxi to travel",
202
+ "slots": {
203
+ "destination": {
204
+ "description": "destination of taxi",
205
+ "is_categorical": False,
206
+ "possible_values": []
207
+ },
208
+ "departure": {
209
+ "description": "departure location of taxi",
210
+ "is_categorical": False,
211
+ "possible_values": []
212
+ },
213
+ "leave at": {
214
+ "description": "leaving time of taxi",
215
+ "is_categorical": False,
216
+ "possible_values": []
217
+ },
218
+ "arrive by": {
219
+ "description": "arrival time of taxi",
220
+ "is_categorical": False,
221
+ "possible_values": []
222
+ },
223
+ "phone": {
224
+ "description": "phone number of the taxi",
225
+ "is_categorical": False,
226
+ "possible_values": []
227
+ },
228
+ "type": {
229
+ "description": "car type of the taxi",
230
+ "is_categorical": False,
231
+ "possible_values": []
232
+ }
233
+ }
234
+ },
235
+ "restaurant": {
236
+ "description": "find and book a restaurant",
237
+ "slots": {
238
+ "price range": {
239
+ "description": "price budget for the restaurant",
240
+ "is_categorical": True,
241
+ "possible_values": [
242
+ "cheap",
243
+ "expensive",
244
+ "moderate"
245
+ ]
246
+ },
247
+ "area": {
248
+ "description": "area or place of the restaurant",
249
+ "is_categorical": True,
250
+ "possible_values": [
251
+ "centre",
252
+ "east",
253
+ "north",
254
+ "south",
255
+ "west"
256
+ ]
257
+ },
258
+ "food": {
259
+ "description": "the cuisine of the restaurant",
260
+ "is_categorical": False,
261
+ "possible_values": []
262
+ },
263
+ "name": {
264
+ "description": "name of the restaurant",
265
+ "is_categorical": False,
266
+ "possible_values": []
267
+ },
268
+ "address": {
269
+ "description": "address of the restaurant",
270
+ "is_categorical": False,
271
+ "possible_values": []
272
+ },
273
+ "postcode": {
274
+ "description": "postcode of the restaurant",
275
+ "is_categorical": False,
276
+ "possible_values": []
277
+ },
278
+ "phone": {
279
+ "description": "phone number of the restaurant",
280
+ "is_categorical": False,
281
+ "possible_values": []
282
+ },
283
+ "book people": {
284
+ "description": "number of people for the restaurant booking",
285
+ "is_categorical": False,
286
+ "possible_values": []
287
+ },
288
+ "book time": {
289
+ "description": "time of the restaurant booking",
290
+ "is_categorical": False,
291
+ "possible_values": []
292
+ },
293
+ "book day": {
294
+ "description": "day of the restaurant booking",
295
+ "is_categorical": True,
296
+ "possible_values": [
297
+ "monday",
298
+ "tuesday",
299
+ "wednesday",
300
+ "thursday",
301
+ "friday",
302
+ "saturday",
303
+ "sunday"
304
+ ]
305
+ },
306
+ "ref": {
307
+ "description": "reference number of the restaurant booking",
308
+ "is_categorical": False,
309
+ "possible_values": []
310
+ },
311
+ "choice": {
312
+ "description": "number of restaurants that meet the requirement",
313
+ "is_categorical": False,
314
+ "possible_values": []
315
+ }
316
+ }
317
+ },
318
+ "train": {
319
+ "description": "find a train to travel",
320
+ "slots": {
321
+ "destination": {
322
+ "description": "destination of the train",
323
+ "is_categorical": False,
324
+ "possible_values": []
325
+ },
326
+ "arrive by": {
327
+ "description": "arrival time of the train",
328
+ "is_categorical": False,
329
+ "possible_values": []
330
+ },
331
+ "departure": {
332
+ "description": "departure location of the train",
333
+ "is_categorical": False,
334
+ "possible_values": []
335
+ },
336
+ "leave at": {
337
+ "description": "leaving time for the train",
338
+ "is_categorical": False,
339
+ "possible_values": []
340
+ },
341
+ "duration": {
342
+ "description": "duration of the travel",
343
+ "is_categorical": False,
344
+ "possible_values": []
345
+ },
346
+ "book people": {
347
+ "description": "number of people booking for train",
348
+ "is_categorical": False,
349
+ "possible_values": []
350
+ },
351
+ "day": {
352
+ "description": "day of the train",
353
+ "is_categorical": True,
354
+ "possible_values": [
355
+ "monday",
356
+ "tuesday",
357
+ "wednesday",
358
+ "thursday",
359
+ "friday",
360
+ "saturday",
361
+ "sunday"
362
+ ]
363
+ },
364
+ "ref": {
365
+ "description": "reference number of the train booking",
366
+ "is_categorical": False,
367
+ "possible_values": []
368
+ },
369
+ "price": {
370
+ "description": "price of the train ticket",
371
+ "is_categorical": False,
372
+ "possible_values": []
373
+ },
374
+ "train id": {
375
+ "description": "id of the train",
376
+ "is_categorical": False
377
+ },
378
+ "choice": {
379
+ "description": "number of trains that meet the requirement",
380
+ "is_categorical": False,
381
+ "possible_values": []
382
+ }
383
+ }
384
+ },
385
+ "police": {
386
+ "description": "find a police station for help",
387
+ "slots": {
388
+ "name": {
389
+ "description": "name of the police station",
390
+ "is_categorical": False,
391
+ "possible_values": []
392
+ },
393
+ "address": {
394
+ "description": "address of the police station",
395
+ "is_categorical": False,
396
+ "possible_values": []
397
+ },
398
+ "postcode": {
399
+ "description": "postcode of the police station",
400
+ "is_categorical": False,
401
+ "possible_values": []
402
+ },
403
+ "phone": {
404
+ "description": "phone number of the police station",
405
+ "is_categorical": False,
406
+ "possible_values": []
407
+ }
408
+ }
409
+ },
410
+ "hospital": {
411
+ "description": "find a hospital for help",
412
+ "slots": {
413
+ "department": {
414
+ "description": "specific department of the hospital",
415
+ "is_categorical": False,
416
+ "possible_values": []
417
+ },
418
+ "address": {
419
+ "description": "address of the hospital",
420
+ "is_categorical": False,
421
+ "possible_values": []
422
+ },
423
+ "phone": {
424
+ "description": "phone number of the hospital",
425
+ "is_categorical": False,
426
+ "possible_values": []
427
+ },
428
+ "postcode": {
429
+ "description": "postcode of the hospital",
430
+ "is_categorical": False,
431
+ "possible_values": []
432
+ }
433
+ }
434
+ },
435
+ "general": {
436
+ "description": "general domain without slots",
437
+ "slots": {}
438
+ }
439
+ },
440
+ "intents": {
441
+ "inform": {
442
+ "description": "inform the value of a slot"
443
+ },
444
+ "request": {
445
+ "description": "ask for the value of a slot"
446
+ },
447
+ "nobook": {
448
+ "description": "inform the user that the booking is failed"
449
+ },
450
+ "reqmore": {
451
+ "description": "ask the user for more instructions"
452
+ },
453
+ "book": {
454
+ "description": "book something for the user"
455
+ },
456
+ "bye": {
457
+ "description": "say goodbye to the user and end the conversation"
458
+ },
459
+ "thank": {
460
+ "description": "thanks for the help"
461
+ },
462
+ "welcome": {
463
+ "description": "you're welcome"
464
+ },
465
+ "greet": {
466
+ "description": "express greeting"
467
+ },
468
+ "recommend": {
469
+ "description": "recommend a choice to the user"
470
+ },
471
+ "select": {
472
+ "description": "provide several choices for the user"
473
+ },
474
+ "offerbook": {
475
+ "description": "ask the user if he or she needs booking"
476
+ },
477
+ "offerbooked": {
478
+ "description": "provide information about the booking"
479
+ },
480
+ "nooffer": {
481
+ "description": "inform the user that there is no result satisfies user requirements"
482
+ }
483
+ },
484
+ "state": {
485
+ "attraction": {
486
+ "type": "",
487
+ "name": "",
488
+ "area": ""
489
+ },
490
+ "hotel": {
491
+ "name": "",
492
+ "area": "",
493
+ "parking": "",
494
+ "price range": "",
495
+ "stars": "",
496
+ "internet": "",
497
+ "type": "",
498
+ "book stay": "",
499
+ "book day": "",
500
+ "book people": ""
501
+ },
502
+ "restaurant": {
503
+ "food": "",
504
+ "price range": "",
505
+ "name": "",
506
+ "area": "",
507
+ "book time": "",
508
+ "book day": "",
509
+ "book people": ""
510
+ },
511
+ "taxi": {
512
+ "leave at": "",
513
+ "destination": "",
514
+ "departure": "",
515
+ "arrive by": ""
516
+ },
517
+ "train": {
518
+ "leave at": "",
519
+ "destination": "",
520
+ "day": "",
521
+ "arrive by": "",
522
+ "departure": "",
523
+ "book people": ""
524
+ },
525
+ "hospital": {
526
+ "department": ""
527
+ }
528
+ },
529
+ "dialogue_acts": {
530
+ "categorical": {},
531
+ "non-categorical": {},
532
+ "binary": {}
533
+ }
534
+ }
535
+
536
+ slot_name_map = {
537
+ 'addr': "address",
538
+ 'post': "postcode",
539
+ 'pricerange': "price range",
540
+ 'arrive': "arrive by",
541
+ 'arriveby': "arrive by",
542
+ 'leave': "leave at",
543
+ 'leaveat': "leave at",
544
+ 'depart': "departure",
545
+ 'dest': "destination",
546
+ 'fee': "entrance fee",
547
+ 'open': 'open hours',
548
+ 'car': "type",
549
+ 'car type': "type",
550
+ 'ticket': 'price',
551
+ 'trainid': 'train id',
552
+ 'id': 'train id',
553
+ 'people': 'book people',
554
+ 'stay': 'book stay',
555
+ 'none': '',
556
+ 'attraction': {
557
+ 'price': 'entrance fee'
558
+ },
559
+ 'hospital': {},
560
+ 'hotel': {
561
+ 'day': 'book day', 'price': "price range"
562
+ },
563
+ 'restaurant': {
564
+ 'day': 'book day', 'time': 'book time', 'price': "price range"
565
+ },
566
+ 'taxi': {},
567
+ 'train': {
568
+ 'day': 'day', 'time': "duration"
569
+ },
570
+ 'police': {},
571
+ 'booking': {}
572
+ }
573
+
574
+ reverse_da_slot_name_map = {
575
+ 'address': 'Addr',
576
+ 'postcode': 'Post',
577
+ 'price range': 'Price',
578
+ 'arrive by': 'Arrive',
579
+ 'leave at': 'Leave',
580
+ 'departure': 'Depart',
581
+ 'destination': 'Dest',
582
+ 'entrance fee': 'Fee',
583
+ 'open hours': 'Open',
584
+ 'price': 'Ticket',
585
+ 'train id': 'Id',
586
+ 'book people': 'People',
587
+ 'book stay': 'Stay',
588
+ 'book day': 'Day',
589
+ 'book time': 'Time',
590
+ 'duration': 'Time',
591
+ 'taxi': {
592
+ 'type': 'Car',
593
+ 'phone': 'Phone'
594
+ }
595
+ }
596
+
597
+ digit2word = {
598
+ '0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five',
599
+ '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10': 'ten'
600
+ }
601
+
602
+ cnt_domain_slot = Counter()
603
+
604
+
605
+ class BookingActRemapper:
606
+
607
+ def __init__(self, ontology):
608
+ self.ontology = ontology
609
+ self.reset()
610
+
611
+ def reset(self):
612
+ self.current_domains_user = []
613
+ self.current_domains_system = []
614
+ self.booked_domains = []
615
+
616
+ def retrieve_current_domain_from_user(self, turn_id, ori_dialog):
617
+ prev_user_turn = ori_dialog[turn_id - 1]
618
+
619
+ dialog_acts = prev_user_turn.get('dialog_act', [])
620
+ keyword_domains_user = get_keyword_domains(prev_user_turn)
621
+ current_domains_temp = get_current_domains_from_act(dialog_acts)
622
+ self.current_domains_user = current_domains_temp if current_domains_temp else self.current_domains_user
623
+ next_user_domains = get_next_user_act_domains(ori_dialog, turn_id)
624
+
625
+ return keyword_domains_user, next_user_domains
626
+
627
+ def retrieve_current_domain_from_system(self, turn_id, ori_dialog):
628
+
629
+ system_turn = ori_dialog[turn_id]
630
+ dialog_acts = system_turn.get('dialog_act', [])
631
+ keyword_domains_system = get_keyword_domains(system_turn)
632
+ current_domains_temp = get_current_domains_from_act(dialog_acts)
633
+ self.current_domains_system = current_domains_temp if current_domains_temp else self.current_domains_system
634
+ booked_domain_current = self.check_domain_booked(system_turn)
635
+
636
+ return keyword_domains_system, booked_domain_current
637
+
638
+ def remap(self, turn_id, ori_dialog):
639
+
640
+ keyword_domains_user, next_user_domains = self.retrieve_current_domain_from_user(
641
+ turn_id, ori_dialog)
642
+ keyword_domains_system, booked_domain_current = self.retrieve_current_domain_from_system(
643
+ turn_id, ori_dialog)
644
+
645
+ # only need to remap if there is a dialog action labelled
646
+ dialog_acts = ori_dialog[turn_id].get('dialog_act', [])
647
+ spans = ori_dialog[turn_id].get('span_info', [])
648
+ if dialog_acts:
649
+
650
+ flattened_acts = flatten_acts(dialog_acts)
651
+ # flattened_spans = flatten_span_acts(spans)
652
+ remapped_acts, error_local = remap_acts(flattened_acts, self.current_domains_user,
653
+ booked_domain_current, keyword_domains_user,
654
+ keyword_domains_system, self.current_domains_system,
655
+ next_user_domains, self.ontology)
656
+
657
+ # remapped_spans, _ = remap_acts(flattened_spans, self.current_domains_user,
658
+ # booked_domain_current, keyword_domains_user,
659
+ # keyword_domains_system, self.current_domains_system,
660
+ # next_user_domains, self.ontology)
661
+
662
+ deflattened_remapped_acts = deflat_acts(remapped_acts)
663
+ # deflattened_remapped_spans = deflat_span_acts(remapped_spans)
664
+
665
+ return deflattened_remapped_acts, spans # deflattened_remapped_spans
666
+ else:
667
+ return dialog_acts, spans
668
+
669
+ def check_domain_booked(self, turn):
670
+
671
+ booked_domain_current = None
672
+ return booked_domain_current
673
+
674
+ # workaround
675
+ for domain in turn['metadata']:
676
+ if turn['metadata'][domain]["book"]["booked"] and domain not in self.booked_domains:
677
+ booked_domain_current = domain.capitalize()
678
+ self.booked_domains.append(domain)
679
+ return booked_domain_current
680
+
681
+
682
+ def get_keyword_domains(turn):
683
+ keyword_domains = []
684
+ text = turn['text']
685
+ for d in ["Hotel", "Restaurant", "Train"]:
686
+ if d.lower() in text.lower():
687
+ keyword_domains.append(d)
688
+ return keyword_domains
689
+
690
+
691
+ def get_current_domains_from_act(dialog_acts):
692
+
693
+ current_domains_temp = []
694
+ for dom_int in dialog_acts:
695
+ domain, intent = dom_int.split('-')
696
+ if domain in ["general", "Booking"]:
697
+ continue
698
+ if domain not in current_domains_temp:
699
+ current_domains_temp.append(domain)
700
+
701
+ return current_domains_temp
702
+
703
+
704
+ def get_next_user_act_domains(ori_dialog, turn_id):
705
+ domains = []
706
+ try:
707
+ next_user_act = ori_dialog[turn_id + 1]['dialog_act']
708
+ domains = get_current_domains_from_act(next_user_act)
709
+ except:
710
+ # will fail if system act is the last act of the dialogue
711
+ pass
712
+ return domains
713
+
714
+
715
+ def flatten_acts(dialog_acts):
716
+ flattened_acts = []
717
+ for dom_int in dialog_acts:
718
+ domain, intent = dom_int.split('-')
719
+ for slot_value in dialog_acts[dom_int]:
720
+ slot = slot_value[0]
721
+ value = slot_value[1]
722
+ flattened_acts.append((domain, intent, slot, value))
723
+
724
+ return flattened_acts
725
+
726
+
727
+ def flatten_span_acts(span_acts):
728
+
729
+ flattened_acts = []
730
+ for span_act in span_acts:
731
+ domain, intent = span_act[0].split("-")
732
+ flattened_acts.append((domain, intent, span_act[1], span_act[2:]))
733
+ return flattened_acts
734
+
735
+
736
+ def deflat_acts(flattened_acts):
737
+
738
+ dialog_acts = dict()
739
+
740
+ for act in flattened_acts:
741
+ domain, intent, slot, value = act
742
+ if f"{domain}-{intent}" not in dialog_acts.keys():
743
+ dialog_acts[f"{domain}-{intent}"] = [[slot, value]]
744
+ else:
745
+ dialog_acts[f"{domain}-{intent}"].append([slot, value])
746
+
747
+ return dialog_acts
748
+
749
+
750
+ def deflat_span_acts(flattened_acts):
751
+
752
+ dialog_span_acts = []
753
+ for act in flattened_acts:
754
+ domain, intent, slot, value = act
755
+ if value == 'none':
756
+ continue
757
+ new_act = [f"{domain}-{intent}", slot]
758
+ new_act.extend(value)
759
+ dialog_span_acts.append(new_act)
760
+
761
+ return dialog_span_acts
762
+
763
+
764
+ def remap_acts(flattened_acts, current_domains, booked_domain=None, keyword_domains_user=None,
765
+ keyword_domains_system=None, current_domain_system=None, next_user_domain=None, ontology=None):
766
+
767
+ # We now look for all cases that can happen: Booking domain, Booking within a domain or taxi-inform-car for booking
768
+ error = 0
769
+ remapped_acts = []
770
+
771
+ # if there is more than one current domain or none at all, we try to get booked domain differently
772
+ if len(current_domains) != 1 and booked_domain:
773
+ current_domains = [booked_domain]
774
+ elif len(current_domains) != 1 and len(keyword_domains_user) == 1:
775
+ current_domains = keyword_domains_user
776
+ elif len(current_domains) != 1 and len(keyword_domains_system) == 1:
777
+ current_domains = keyword_domains_system
778
+ elif len(current_domains) != 1 and len(current_domain_system) == 1:
779
+ current_domains = current_domain_system
780
+ elif len(current_domains) != 1 and len(next_user_domain) == 1:
781
+ current_domains = next_user_domain
782
+
783
+ for act in flattened_acts:
784
+ try:
785
+ domain, intent, slot, value = act
786
+ if f"{domain}-{intent}-{slot}" == "Booking-Book-Ref":
787
+ # We need to remap that booking act now
788
+ potential_domain = current_domains[0]
789
+ remapped_acts.append(
790
+ (potential_domain, "Book", "none", "none"))
791
+ if ontology_check(potential_domain, slot, ontology):
792
+ remapped_acts.append(
793
+ (potential_domain, "Inform", "Ref", value))
794
+ elif domain == "Booking" and intent == "Book" and slot != "Ref":
795
+ # the book intent is here actually an inform intent according to the data
796
+ potential_domain = current_domains[0]
797
+ if ontology_check(potential_domain, slot, ontology):
798
+ remapped_acts.append(
799
+ (potential_domain, "Inform", slot, value))
800
+ elif domain == "Booking" and intent == "Inform":
801
+ # the inform intent is here actually a request intent according to the data
802
+ potential_domain = current_domains[0]
803
+ if ontology_check(potential_domain, slot, ontology):
804
+ remapped_acts.append(
805
+ (potential_domain, "OfferBook", slot, value))
806
+ elif domain == "Booking" and intent in ["NoBook", "Request"]:
807
+ potential_domain = current_domains[0]
808
+ if ontology_check(potential_domain, slot, ontology):
809
+ remapped_acts.append(
810
+ (potential_domain, intent, slot, value))
811
+ elif f"{domain}-{intent}-{slot}" == "Taxi-Inform-Car":
812
+ # taxi-inform-car actually triggers the booking and informs on a car
813
+ remapped_acts.append((domain, "Book", "none", "none"))
814
+ remapped_acts.append((domain, intent, slot, value))
815
+ elif f"{domain}-{intent}-{slot}" in ["Train-Inform-Ref", "Train-OfferBooked-Ref"]:
816
+ # train-inform/offerbooked-ref actually triggers the booking and informs on the reference number
817
+ remapped_acts.append((domain, "Book", "none", "none"))
818
+ remapped_acts.append((domain, "Inform", slot, value))
819
+ elif domain == "Train" and intent == "OfferBooked" and slot != "Ref":
820
+ # this is actually an inform act
821
+ remapped_acts.append((domain, "Inform", slot, value))
822
+ else:
823
+ remapped_acts.append(act)
824
+ except Exception as e:
825
+ print("Error detected:", e)
826
+ error += 1
827
+
828
+ return remapped_acts, error
829
+
830
+
831
+ def ontology_check(domain_, slot_, init_ontology):
832
+
833
+ domain = domain_.lower()
834
+ slot = slot_.lower()
835
+ if slot not in init_ontology['domains'][domain]['slots']:
836
+ if slot in slot_name_map:
837
+ slot = slot_name_map[slot]
838
+ elif slot in slot_name_map[domain]:
839
+ slot = slot_name_map[domain][slot]
840
+ return slot in init_ontology['domains'][domain]['slots']
841
+
842
+
843
+ def reverse_da(dialogue_acts):
844
+ global reverse_da_slot_name_map
845
+ das = {}
846
+ for da_type in dialogue_acts:
847
+ for da in dialogue_acts[da_type]:
848
+ intent, domain, slot, value = da['intent'], da['domain'], da['slot'], da.get(
849
+ 'value', '')
850
+ if domain == 'general':
851
+ Domain_Intent = '-'.join([domain, intent])
852
+ elif intent == 'nooffer':
853
+ Domain_Intent = '-'.join([domain.capitalize(), 'NoOffer'])
854
+ elif intent == 'nobook':
855
+ Domain_Intent = '-'.join([domain.capitalize(), 'NoBook'])
856
+ elif intent == 'offerbook':
857
+ Domain_Intent = '-'.join([domain.capitalize(), 'OfferBook'])
858
+ else:
859
+ Domain_Intent = '-'.join([domain.capitalize(),
860
+ intent.capitalize()])
861
+ das.setdefault(Domain_Intent, [])
862
+ if slot in reverse_da_slot_name_map:
863
+ Slot = reverse_da_slot_name_map[slot]
864
+ elif domain in reverse_da_slot_name_map and slot in reverse_da_slot_name_map[domain]:
865
+ Slot = reverse_da_slot_name_map[domain][slot]
866
+ else:
867
+ Slot = slot.capitalize()
868
+ if value == '':
869
+ if intent == 'request':
870
+ value = '?'
871
+ else:
872
+ value = 'none'
873
+ if Slot == '':
874
+ Slot = 'none'
875
+ das[Domain_Intent].append([Slot, value])
876
+ return das
877
+
878
+
879
+ def normalize_domain_slot_value(domain, slot, value):
880
+ global ontology, slot_name_map
881
+ domain = domain.lower()
882
+ slot = slot.lower()
883
+ value = value.strip()
884
+ if value in ['do nt care', "do n't care"]:
885
+ value = 'dontcare'
886
+ if value in ['?', 'none', 'not mentioned']:
887
+ value = ""
888
+ if domain not in ontology['domains']:
889
+ raise Exception(f'{domain} not in ontology')
890
+ if slot not in ontology['domains'][domain]['slots']:
891
+ if slot in slot_name_map:
892
+ slot = slot_name_map[slot]
893
+ elif slot in slot_name_map[domain]:
894
+ slot = slot_name_map[domain][slot]
895
+ else:
896
+ raise Exception(f'{domain}-{slot} not in ontology')
897
+ assert slot == '' or slot in ontology['domains'][domain][
898
+ 'slots'], f'{(domain, slot, value)} not in ontology'
899
+ return domain, slot, value
900
+
901
+
902
+ def convert_da(da_dict, utt, sent_tokenizer, word_tokenizer):
903
+ '''
904
+ convert multiwoz dialogue acts to required format
905
+ :param da_dict: dict[(intent, domain, slot, value)] = [word_start, word_end]
906
+ :param utt: user or system utt
907
+ '''
908
+ global ontology, digit2word, cnt_domain_slot
909
+
910
+ converted_da = {
911
+ 'categorical': [],
912
+ 'non-categorical': [],
913
+ 'binary': []
914
+ }
915
+ sentences = sent_tokenizer.tokenize(utt)
916
+ sent_spans = sent_tokenizer.span_tokenize(utt)
917
+ tokens = [
918
+ token for sent in sentences for token in word_tokenizer.tokenize(sent)]
919
+ token_spans = [(sent_span[0] + token_span[0], sent_span[0] + token_span[1]) for sent, sent_span in
920
+ zip(sentences, sent_spans) for token_span in word_tokenizer.span_tokenize(sent)]
921
+ # assert len(tokens) == len(token_spans)
922
+ # for token, span in zip(tokens, token_spans):
923
+ # if utt[span[0]:span[1]] != '"':
924
+ # assert utt[span[0]:span[1]] == token
925
+
926
+ for (intent, domain, slot, value), span in da_dict.items():
927
+ if intent == 'request' or slot == '' or value == '':
928
+ # binary dialog acts
929
+ assert value == ''
930
+ converted_da['binary'].append({
931
+ 'intent': intent,
932
+ 'domain': domain,
933
+ 'slot': slot
934
+ })
935
+ elif ontology['domains'][domain]['slots'][slot]['is_categorical']:
936
+ # categorical dialog acts
937
+ converted_da['categorical'].append({
938
+ 'intent': intent,
939
+ 'domain': domain,
940
+ 'slot': slot,
941
+ 'value': value
942
+ })
943
+ else:
944
+ # non-categorical dialog acts
945
+ converted_da['non-categorical'].append({
946
+ 'intent': intent,
947
+ 'domain': domain,
948
+ 'slot': slot,
949
+ 'value': value
950
+ })
951
+ # correct some value and try to give char level span
952
+ match = False
953
+ value = value.lower()
954
+ if span and span[0] <= span[1]:
955
+ # use original span annotation, but tokenizations are different
956
+ start_word, end_word = span
957
+ if end_word >= len(tokens):
958
+ # due to different tokenization, sometimes will out of index
959
+ delta = end_word - len(tokens) + 1
960
+ start_word -= delta
961
+ end_word -= delta
962
+ start_char, end_char = token_spans[start_word][0], token_spans[end_word][1]
963
+ value_span = utt[start_char:end_char].lower()
964
+ match = True
965
+ if value_span == value:
966
+ cnt_domain_slot['span match'] += 1
967
+ elif value.isdigit() and value in digit2word and digit2word[value] == value_span:
968
+ # !!!CHANGE VALUE: value is digit but value span is word
969
+ cnt_domain_slot['digit value match'] += 1
970
+ elif ''.join(value.split()) == ''.join(value_span.split()):
971
+ # !!!CHANGE VALUE: equal when remove blank
972
+ cnt_domain_slot['remove blank'] += 1
973
+ elif value in value_span:
974
+ # value in value_span
975
+ start_char += value_span.index(value)
976
+ end_char = start_char + len(value)
977
+ assert utt[start_char:end_char].lower(
978
+ ) == value, f'{[value, utt[start_char:end_char], utt]}'
979
+ cnt_domain_slot['value in span'] += 1
980
+ elif ':' in value and value == '0' + value_span:
981
+ # !!!CHANGE VALUE: time x:xx == 0x:xx
982
+ cnt_domain_slot['x:xx == 0x:xx'] += 1
983
+ else:
984
+ # span mismatch, search near 1-2 words
985
+ for window in range(1, 3):
986
+ start = max(0, start_word - window)
987
+ end = min(len(token_spans) - 1, end_word + window)
988
+ large_span = utt[token_spans[start]
989
+ [0]:token_spans[end][1]].lower()
990
+ if value in large_span:
991
+ start_char = token_spans[start][0] + \
992
+ large_span.index(value)
993
+ end_char = start_char + len(value)
994
+ assert utt[
995
+ start_char:end_char].lower() == value, f'{[value, utt[start_char:end_char], utt]}'
996
+ cnt_domain_slot[f'window={window}'] += 1
997
+ break
998
+ else:
999
+ # still not found
1000
+ match = False
1001
+
1002
+ if match:
1003
+ converted_da['non-categorical'][-1]['value'] = utt[start_char:end_char]
1004
+ converted_da['non-categorical'][-1]['start'] = start_char
1005
+ converted_da['non-categorical'][-1]['end'] = end_char
1006
+ cnt_domain_slot['have span'] += 1
1007
+ else:
1008
+ cnt_domain_slot['no span'] += 1
1009
+ return converted_da
1010
+
1011
+
1012
+ def act_list2dict(act_list):
1013
+ act_dict = {}
1014
+ for intent, domain, slot, value in act_list:
1015
+ key = f"{domain}-{intent}"
1016
+ if key not in act_dict:
1017
+ act_dict[key] = []
1018
+ act_dict[key].append([slot, value])
1019
+ return act_dict
1020
+
1021
+
1022
+ def preprocess():
1023
+ original_data_dir = 'emowoz'
1024
+ new_data_dir = 'data'
1025
+
1026
+ if not os.path.exists(original_data_dir):
1027
+ original_data_zip = 'MultiWOZ_2.1.zip'
1028
+ if not os.path.exists(original_data_zip):
1029
+ raise FileNotFoundError(
1030
+ f'cannot find original data {original_data_zip} in multiwoz21/, should manually download MultiWOZ_2.1.zip from https://github.com/budzianowski/multiwoz/blob/master/data/MultiWOZ_2.1.zip')
1031
+ else:
1032
+ archive = ZipFile(original_data_zip)
1033
+ archive.extractall()
1034
+
1035
+ os.makedirs(new_data_dir, exist_ok=True)
1036
+ for filename in os.listdir(original_data_dir):
1037
+ if 'db' in filename:
1038
+ copy2(f'{original_data_dir}/{filename}', new_data_dir)
1039
+
1040
+ # how about emowoz-dialmage
1041
+ original_data = json.load(
1042
+ open(f'{original_data_dir}/emowoz-dialmage.json'))
1043
+ global ontology, cnt_domain_slot
1044
+
1045
+ raw_data = pickle.load(open('dialog_state.pkl', 'rb'))
1046
+ actions = raw_data[0]
1047
+
1048
+ data_split = json.load(open(f'{original_data_dir}/data_split.json'))
1049
+ val_list = data_split["dev"]["dialmage"]
1050
+ test_list = data_split["test"]["dialmage"]
1051
+ dataset = 'emowoz-dialmage'
1052
+ splits = ['train', 'validation', 'test']
1053
+ dialogues_by_split = {split: [] for split in splits}
1054
+ sent_tokenizer = PunktSentenceTokenizer()
1055
+ word_tokenizer = TreebankWordTokenizer()
1056
+ booking_remapper = BookingActRemapper(ontology)
1057
+ for ori_dialog_id, ori_dialog in tqdm(original_data.items()):
1058
+ act = actions[ori_dialog_id]
1059
+ for turn_id in range(len(ori_dialog["log"])):
1060
+ ori_dialog["log"][turn_id]["dialog_act"] = act_list2dict(
1061
+ act[turn_id])
1062
+
1063
+ if ori_dialog_id in val_list:
1064
+ split = 'validation'
1065
+ elif ori_dialog_id in test_list:
1066
+ split = 'test'
1067
+ else:
1068
+ split = 'train'
1069
+ dialogue_id = f'{dataset}-{split}-{len(dialogues_by_split[split])}'
1070
+
1071
+ # get user goal and involved domains
1072
+ cur_domains = []
1073
+
1074
+ dialogue = {
1075
+ 'dataset': dataset,
1076
+ 'data_split': split,
1077
+ 'dialogue_id': dialogue_id,
1078
+ 'original_id': ori_dialog_id,
1079
+ 'domains': cur_domains, # will be updated by dialog_acts and state
1080
+ 'goal': "",
1081
+ 'turns': []
1082
+ }
1083
+
1084
+ booking_remapper.reset()
1085
+ belief_domains = ['attraction', 'restaurant',
1086
+ 'train', 'hotel', 'taxi', 'hospital']
1087
+ entity_booked_dict = dict((domain, False) for domain in belief_domains)
1088
+
1089
+ for turn_id, turn in enumerate(ori_dialog['log']):
1090
+ # correct some grammar errors in the text, mainly following `tokenization.md` in MultiWOZ_2.1
1091
+ text = turn['text']
1092
+ text = re.sub(" Im ", " I'm ", text)
1093
+ text = re.sub(" im ", " i'm ", text)
1094
+ text = re.sub(r"^Im ", "I'm ", text)
1095
+ text = re.sub(r"^im ", "i'm ", text)
1096
+ text = re.sub("theres", "there's", text)
1097
+ text = re.sub("dont", "don't", text)
1098
+ text = re.sub("whats", "what's", text)
1099
+ text = re.sub('thats', "that's", text)
1100
+ utt = text
1101
+ speaker = 'user' if turn_id % 2 == 0 else 'system'
1102
+
1103
+ das = turn.get('dialog_act', [])
1104
+ spans = turn.get('span_info', [])
1105
+
1106
+ # if speaker == 'system':
1107
+ das, spans = booking_remapper.remap(turn_id, ori_dialog['log'])
1108
+
1109
+ da_dict = {}
1110
+ # transform DA
1111
+ for Domain_Intent in das:
1112
+ domain, intent = Domain_Intent.lower().split('-')
1113
+ assert intent in ontology['intents'], f'{ori_dialog_id}:{turn_id}:da\t{intent} not in ontology'
1114
+ for Slot, value in das[Domain_Intent]:
1115
+ domain, slot, value = normalize_domain_slot_value(
1116
+ domain, Slot, value)
1117
+ if domain not in cur_domains:
1118
+ # update original cur_domains
1119
+ cur_domains.append(domain)
1120
+ da_dict[(intent, domain, slot, value,)] = []
1121
+
1122
+ # for span in spans:
1123
+ # Domain_Intent, Slot, value, start_word, end_word = span
1124
+ # domain, intent = Domain_Intent.lower().split('-')
1125
+ # domain, slot, value = normalize_domain_slot_value(
1126
+ # domain, Slot, value)
1127
+ # print(da_dict)
1128
+ # assert (intent, domain, slot, value,) in da_dict
1129
+ # da_dict[(intent, domain, slot, value,)] = [
1130
+ # start_word, end_word]
1131
+
1132
+ dialogue_acts = convert_da(
1133
+ da_dict, utt, sent_tokenizer, word_tokenizer)
1134
+
1135
+ # reverse_das = reverse_da(dialogue_acts)
1136
+ # das_list = sorted([(Domain_Intent, Slot, ''.join(value.split()).lower()) for Domain_Intent in das for Slot, value in das[Domain_Intent]])
1137
+ # reverse_das_list = sorted([(Domain_Intent, Slot, ''.join(value.split()).lower()) for Domain_Intent in reverse_das for Slot, value in reverse_das[Domain_Intent]])
1138
+ # if das_list != reverse_das_list:
1139
+ # print(das_list)
1140
+ # print(reverse_das_list)
1141
+ # print()
1142
+ # print()
1143
+
1144
+ dialogue['turns'].append({
1145
+ 'speaker': speaker,
1146
+ 'utterance': utt,
1147
+ 'utt_idx': turn_id,
1148
+ 'dialogue_acts': dialogue_acts,
1149
+ 'emotion': turn['emotion']
1150
+ })
1151
+
1152
+ # add to dialogue_acts dictionary in the ontology
1153
+ for da_type in dialogue_acts:
1154
+ das = dialogue_acts[da_type]
1155
+ for da in das:
1156
+ ontology["dialogue_acts"][da_type].setdefault(
1157
+ (da['intent'], da['domain'], da['slot']), {})
1158
+ ontology["dialogue_acts"][da_type][(
1159
+ da['intent'], da['domain'], da['slot'])][speaker] = True
1160
+
1161
+ if speaker == 'system':
1162
+ # add state to last user turn
1163
+ # add empty db_results
1164
+ # turn_state = turn['metadata']
1165
+ cur_state = copy.deepcopy(ontology['state'])
1166
+ booked = {}
1167
+ # for domain in turn_state:
1168
+ # if domain not in cur_state:
1169
+ # continue
1170
+ # for subdomain in ['semi', 'book']:
1171
+ # for slot, value in turn_state[domain][subdomain].items():
1172
+ # if slot == 'ticket':
1173
+ # continue
1174
+ # elif slot == 'booked':
1175
+ # assert domain in ontology['domains']
1176
+ # booked[domain] = value
1177
+ # continue
1178
+ # _, slot, value = normalize_domain_slot_value(
1179
+ # domain, slot, value)
1180
+ # cur_state[domain][slot] = value
1181
+ dialogue['turns'][-2]['state'] = cur_state
1182
+ # entity_booked_dict, booked = fix_entity_booked_info(
1183
+ # entity_booked_dict, booked)
1184
+ dialogue['turns'][-1]['booked'] = booked
1185
+ dialogues_by_split[split].append(dialogue)
1186
+ # pprint(cnt_domain_slot.most_common())
1187
+ dialogues = []
1188
+ for split in splits:
1189
+ dialogues += dialogues_by_split[split]
1190
+ for da_type in ontology['dialogue_acts']:
1191
+ ontology["dialogue_acts"][da_type] = sorted([str(
1192
+ {'user': speakers.get('user', False), 'system': speakers.get('system', False), 'intent': da[0],
1193
+ 'domain': da[1], 'slot': da[2]}) for da, speakers in ontology["dialogue_acts"][da_type].items()])
1194
+ json.dump(dialogues[:10], open(f'dummy_data.json', 'w',
1195
+ encoding='utf-8'), indent=2, ensure_ascii=False)
1196
+ json.dump(ontology, open(f'{new_data_dir}/ontology.json',
1197
+ 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
1198
+ json.dump(dialogues, open(f'{new_data_dir}/dialogues.json',
1199
+ 'w', encoding='utf-8'), indent=2, ensure_ascii=False)
1200
+ with ZipFile('data.zip', 'w', ZIP_DEFLATED) as zf:
1201
+ for filename in os.listdir(new_data_dir):
1202
+ zf.write(f'{new_data_dir}/{filename}')
1203
+ # rmtree(original_data_dir)
1204
+ # rmtree(new_data_dir)
1205
+ return dialogues, ontology
1206
+
1207
+
1208
+ def fix_entity_booked_info(entity_booked_dict, booked):
1209
+ for domain in entity_booked_dict:
1210
+ if not entity_booked_dict[domain] and booked[domain]:
1211
+ entity_booked_dict[domain] = True
1212
+ booked[domain] = []
1213
+ return entity_booked_dict, booked
1214
+
1215
+
1216
+ if __name__ == '__main__':
1217
+ preprocess()
shuffled_dial_ids.json ADDED
@@ -0,0 +1 @@
 
 
1
+ [{"train": [0, 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, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794], "validation": [0, 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], "test": [0, 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]}]