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 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 # Monitor stanu dialogu
class DST(CL2DST): class DST:
def __init__(self): def __init__(self):
CL2DST.__init__(self)
self.state = default_state() self.state = default_state()
self.value_dict = json.load(open('value_dict.json'))
def update(self, user_act=None): def update(self, user_act=None):
for intent, domain, slot, value in user_act: for intent, domain, slot, value in user_act:
domain = domain.lower() domain = domain.lower()
intent = intent.lower() intent = intent.lower()
slot = slot.lower()
if domain in ['unk', 'general', 'booking']: k = slot
continue
if intent == 'inform': if 'inform' in intent:
k = REF_SYS_DA[domain.capitalize()].get(slot, slot)
if k is None: if k is None:
continue continue
@ -36,31 +22,30 @@ class DST(CL2DST):
domain_dic = self.state['belief_state'][domain] domain_dic = self.state['belief_state'][domain]
if k in domain_dic['semi']: if k in domain_dic['semi']:
nvalue = normalize_value(self.value_dict, domain, k, value) self.state['belief_state'][domain]['semi'][k] = value
self.state['belief_state'][domain]['semi'][k] = nvalue
elif k in domain_dic['book']: elif k in domain_dic['book']:
self.state['belief_state'][domain]['book'][k] = value self.state['belief_state'][domain]['book'][k] = value
elif k.lower() in domain_dic['book']:
self.state['belief_state'][domain]['book'][k.lower()] = value if 'request' in intent:
elif intent == 'request':
k = REF_SYS_DA[domain.capitalize()].get(slot, slot)
if domain not in self.state['request_state']: if domain not in self.state['request_state']:
self.state['request_state'][domain] = {} self.state['request_state'][domain] = {}
if k not in self.state['request_state'][domain]: if k not in self.state['request_state'][domain]:
self.state['request_state'][domain][k] = 0 self.state['request_state'][domain][k] = 0
self.state['user_action'].append([intent, domain, slot, value])
return self.state return self.state
def init_session(self): def init_session(self):
self.state = default_state() 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() dst = DST()
print(dst.state) print(dst.state)
dst.update([['Inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']]) dst.update([['hello_inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']])
print(dst.state['belief_state']['cinema']) print(dst.state)
""" """

View File

@ -9,97 +9,18 @@ def default_state():
"cinema": { "cinema": {
"book": { "book": {
"booked": [], "booked": [],
"people": "", "date": "",
"day": "", "hour": "",
"seat": "" "seat": "",
"movie": ""
}, },
"semi": { "semi": {
"name": "", "name": "",
"e-mail": "", "e-mail": "",
"price": "", "price": "",
"stars": "", "number": "",
"movie": "",
"type": "" "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 return state

File diff suppressed because it is too large Load Diff