update DST

This commit is contained in:
Kacper Dudzic 2022-05-28 14:18:38 +02:00
parent 3b10cab794
commit 9abc4a1af3
3 changed files with 18 additions and 4444 deletions

View File

@ -1,34 +1,20 @@
from dialogue_state import default_state
import json
from convlab2.dst.dst import DST as CL2DST
from convlab2.dst.rule.multiwoz.dst_util import normalize_value
# from convlab2.util.multiwoz.multiwoz_slot_trans import REF_SYS_DA
REF_SYS_DA = {
'Cinema': {
'Type': 'type','Price': 'price','Stars': 'stars',
'Name': 'name','Day': 'day','People': 'people','Movie': 'movie',
'E-mail': 'e-mail', 'none': None
},
}
# Monitor stanu dialogu
class DST(CL2DST):
class DST:
def __init__(self):
CL2DST.__init__(self)
self.state = default_state()
self.value_dict = json.load(open('value_dict.json'))
def update(self, user_act=None):
for intent, domain, slot, value in user_act:
domain = domain.lower()
intent = intent.lower()
slot = slot.lower()
if domain in ['unk', 'general', 'booking']:
continue
k = slot
if intent == 'inform':
k = REF_SYS_DA[domain.capitalize()].get(slot, slot)
if 'inform' in intent:
if k is None:
continue
@ -36,31 +22,30 @@ class DST(CL2DST):
domain_dic = self.state['belief_state'][domain]
if k in domain_dic['semi']:
nvalue = normalize_value(self.value_dict, domain, k, value)
self.state['belief_state'][domain]['semi'][k] = nvalue
self.state['belief_state'][domain]['semi'][k] = value
elif k in domain_dic['book']:
self.state['belief_state'][domain]['book'][k] = value
elif k.lower() in domain_dic['book']:
self.state['belief_state'][domain]['book'][k.lower()] = value
elif intent == 'request':
k = REF_SYS_DA[domain.capitalize()].get(slot, slot)
if 'request' in intent:
if domain not in self.state['request_state']:
self.state['request_state'][domain] = {}
if k not in self.state['request_state'][domain]:
self.state['request_state'][domain][k] = 0
self.state['user_action'].append([intent, domain, slot, value])
return self.state
def init_session(self):
self.state = default_state()
# Przykładowe uruchomienie dla kodu jeszcze bez zmian pod rezerwację biletów kinowych
# Przykładowe uruchomienie dla kodu w izolacji
"""
dst = DST()
print(dst.state)
dst.update([['Inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']])
print(dst.state['belief_state']['cinema'])
dst.update([['hello_inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']])
print(dst.state)
"""

View File

@ -9,97 +9,18 @@ def default_state():
"cinema": {
"book": {
"booked": [],
"people": "",
"day": "",
"seat": ""
"date": "",
"hour": "",
"seat": "",
"movie": ""
},
"semi": {
"name": "",
"e-mail": "",
"price": "",
"stars": "",
"movie": "",
"number": "",
"type": ""
}
},
"police": {
"book": {
"booked": []
},
"semi": {}
},
"hotel": {
"book": {
"booked": [],
"people": "",
"day": "",
"stay": ""
},
"semi": {
"name": "",
"area": "",
"parking": "",
"pricerange": "",
"stars": "",
"internet": "",
"type": ""
}
},
"attraction": {
"book": {
"booked": []
},
"semi": {
"type": "",
"name": "",
"area": ""
}
},
"restaurant": {
"book": {
"booked": [],
"people": "",
"day": "",
"time": ""
},
"semi": {
"food": "",
"pricerange": "",
"name": "",
"area": "",
}
},
"hospital": {
"book": {
"booked": []
},
"semi": {
"department": ""
}
},
"taxi": {
"book": {
"booked": []
},
"semi": {
"leaveAt": "",
"destination": "",
"departure": "",
"arriveBy": ""
}
},
"train": {
"book": {
"booked": [],
"people": ""
},
"semi": {
"leaveAt": "",
"destination": "",
"day": "",
"arriveBy": "",
"departure": ""
}
}
}
return state

File diff suppressed because it is too large Load Diff