Wstępnie działający DST

This commit is contained in:
Anna Nowak 2021-05-30 14:45:42 +02:00
parent 2eca0a043d
commit f58a1b47c7
6 changed files with 101 additions and 96 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*slot-model* *slot-model*
.venv* .venv*
env* env*
*__pycache__*

View File

@ -1,9 +1,6 @@
import json import json
from convlab2.dst.dst import DST
from convlab2.dst.rule.multiwoz.dst_util import normalize_value
class Rules_DST(): #Dialogue State Tracker
class Rules_DST(DST): #Dialogue State Tracker
""" """
Moduł odpowiedzialny za śledzenie stanu dialogu. Przechowuje informacje o tym jakie dane zostały uzyskane od użytkownika w toku prowadzonej konwersacji. Moduł odpowiedzialny za śledzenie stanu dialogu. Przechowuje informacje o tym jakie dane zostały uzyskane od użytkownika w toku prowadzonej konwersacji.
@ -12,37 +9,28 @@ class Rules_DST(DST): #Dialogue State Tracker
Wyjście: Reprezentacja stanu dialogu (rama) Wyjście: Reprezentacja stanu dialogu (rama)
""" """
def __init__(self): def __init__(self):
DST.__init__(self)
self.state = json.load(open('default_state.json')) self.state = json.load(open('default_state.json'))
self.value_dict = json.load(open('value_dict.json'))
def update(self, user_act=None):
slots = user_act["slots"]
intent = user_act["act"]
domain = user_act["act"].split('/')[0]
def update(self, user_acts=None):
for intent, domain, slot, value in user_acts:
self.state["user_action"].append([intent, domain, slot, value])
if domain in ['password', 'name', 'email', 'enter_email', 'enter_name']: if domain in ['password', 'name', 'email', 'enter_email', 'enter_name']:
return return
if 'appointment' in intent: if 'appointment' in intent:
for full_slot in slots: if (slot == 'appointment'):
slot = full_slot[1] continue
value = full_slot[1]
k = self.value_dict[domain.lower()].get(slot, slot)
if k is None: if(domain in slot):
return slot.replace(domain + "/", '')
domain_dic = self.state['belief_state'][domain] domain_dic = self.state['belief_state'][domain]
if slot in domain_dic:
if k in domain_dic['semi']: self.state['belief_state'][domain][slot] = value
nvalue = normalize_value(self.value_dict, domain, k, value) else:
self.state['belief_state'][domain]['semi'][k] = nvalue print(slot)
elif k in domain_dic['book']: print(domain)
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 == 'end_conversation': elif intent == 'end_conversation':
self.state = {} self.state = json.load(open('default_state.json'))
print(self.state)
return self.state return self.state

View File

@ -48,7 +48,7 @@ class ML_NLU:
slots, act = self.predict(utterance.split()) slots, act = self.predict(utterance.split())
slots = [x for x in slots if x[1] != 'O'] slots = [x for x in slots if x[1] != 'O']
arguments = self.convert_slot_to_argument(slots) arguments = self.convert_slot_to_argument(slots)
return {'act': act, 'slots': arguments} return self.convert_act_to_list(act, arguments)
else: else:
return 'Critical Error' return 'Critical Error'
@ -65,3 +65,13 @@ class ML_NLU:
if(candidate != None): if(candidate != None):
arguments.append(candidate) arguments.append(candidate)
return [(x[0], x[1]) for x in arguments] return [(x[0], x[1]) for x in arguments]
def convert_act_to_list(self, act, slots):
result = []
for i in range(len(slots)):
intent = act
domain = act.split('/')[0]
slot = slots[i][0]
value = slots[i][1]
result.append([intent, domain, slot, value])
return result

View File

@ -66,16 +66,16 @@ frame_tagger = SequenceTagger(hidden_size=256, embeddings=embeddings,
tag_type='frame', use_crf=True) tag_type='frame', use_crf=True)
slot_trainer = ModelTrainer(slot_tagger, slot_corpus) slot_trainer = ModelTrainer(slot_tagger, slot_corpus)
# slot_trainer.train('slot-model', slot_trainer.train('slot-model',
# learning_rate=0.1, learning_rate=0.1,
# mini_batch_size=32, mini_batch_size=32,
# max_epochs=100, max_epochs=100,
# train_with_dev=False) train_with_dev=False)
# frame_trainer = ModelTrainer(frame_tagger, frame_corpus) frame_trainer = ModelTrainer(frame_tagger, frame_corpus)
# frame_trainer.train('frame-model', frame_trainer.train('frame-model',
# learning_rate=0.1, learning_rate=0.1,
# mini_batch_size=32, mini_batch_size=32,
# max_epochs=100, max_epochs=100,
# train_with_dev=False) train_with_dev=False)

View File

@ -50,8 +50,8 @@
6 na appointment/create_appointment NoLabel 6 na appointment/create_appointment NoLabel
7 wizytę appointment/create_appointment B-appointment 7 wizytę appointment/create_appointment B-appointment
8 u appointment/create_appointment NoLabel 8 u appointment/create_appointment NoLabel
9 lekarza appointment/create_appointment B-appointment/doctor 9 lekarza appointment/create_appointment B-doctor
10 internisty appointment/create_appointment I-appointment/doctor 10 internisty appointment/create_appointment I-doctor
# text: Nie mam swojego identyfikatora nie pamiętam # text: Nie mam swojego identyfikatora nie pamiętam
# intent: login/forgot_id # intent: login/forgot_id
@ -83,9 +83,9 @@
7 terminie request_information/available_dates NoLabel 7 terminie request_information/available_dates NoLabel
8 20.04.2021 request_information/available_dates B-datetime 8 20.04.2021 request_information/available_dates B-datetime
9 u request_information/available_dates NoLabel 9 u request_information/available_dates NoLabel
10 dr request_information/available_dates B-appointment/doctor 10 dr request_information/available_dates B-doctor
11 adam request_information/available_dates I-appointment/doctor 11 adam request_information/available_dates I-doctor
12 skrzypczak request_information/available_dates I-appointment/doctor 12 skrzypczak request_information/available_dates I-doctor
# text: tak # text: tak
# intent: affirm # intent: affirm
@ -104,7 +104,7 @@
7 20.04.2021 request_information/available_dates B-datetime 7 20.04.2021 request_information/available_dates B-datetime
8 u request_information/available_dates NoLabel 8 u request_information/available_dates NoLabel
9 dowolnego request_information/available_dates NoLabel 9 dowolnego request_information/available_dates NoLabel
10 internisty request_information/available_dates B-appointment/doctor 10 internisty request_information/available_dates B-doctor
# text: prosze o rejestrację do mrożego na 12:00 dziękuję to wszystko # text: prosze o rejestrację do mrożego na 12:00 dziękuję to wszystko
# intent: appointment/create_appointment # intent: appointment/create_appointment
@ -113,7 +113,7 @@
2 o appointment/create_appointment NoLabel 2 o appointment/create_appointment NoLabel
3 rejestrację appointment/create_appointment NoLabel 3 rejestrację appointment/create_appointment NoLabel
4 do appointment/create_appointment NoLabel 4 do appointment/create_appointment NoLabel
5 mrożego appointment/create_appointment B-appointment/doctor 5 mrożego appointment/create_appointment B-doctor
6 na appointment/create_appointment NoLabel 6 na appointment/create_appointment NoLabel
7 12:00 appointment/create_appointment B-datetime 7 12:00 appointment/create_appointment B-datetime
8 dziękuję appointment/create_appointment B-end_conversation 8 dziękuję appointment/create_appointment B-end_conversation
@ -128,7 +128,7 @@
3 zarezerwować appointment/create_appointment NoLabel 3 zarezerwować appointment/create_appointment NoLabel
4 wizytę appointment/create_appointment B-appointment 4 wizytę appointment/create_appointment B-appointment
5 u appointment/create_appointment NoLabel 5 u appointment/create_appointment NoLabel
6 lekarza appointment/create_appointment B-appointment/doctor 6 lekarza appointment/create_appointment B-doctor
# text: 15.04.2021 12:00 # text: 15.04.2021 12:00
# intent: appointment/set_date # intent: appointment/set_date
@ -157,7 +157,7 @@
4 na appointment/create_appointment NoLabel 4 na appointment/create_appointment NoLabel
5 wizytę appointment/create_appointment B-appointment 5 wizytę appointment/create_appointment B-appointment
6 u appointment/create_appointment NoLabel 6 u appointment/create_appointment NoLabel
7 specjalisty appointment/create_appointment B-appointment/doctor 7 specjalisty appointment/create_appointment B-doctor
# text: Proszę podać listę specjalistów # text: Proszę podać listę specjalistów
# intent: request_information/doctors # intent: request_information/doctors
@ -173,9 +173,9 @@
1 chciałbym appointment/create_appointment NoLabel 1 chciałbym appointment/create_appointment NoLabel
2 wizytę appointment/create_appointment NoLabel 2 wizytę appointment/create_appointment NoLabel
3 u appointment/create_appointment NoLabel 3 u appointment/create_appointment NoLabel
4 internista appointment/create_appointment B-appointment/doctor 4 internista appointment/create_appointment B-doctor
5 andrzej appointment/create_appointment I-appointment/doctor 5 andrzej appointment/create_appointment I-doctor
6 mroży appointment/create_appointment I-appointment/doctor 6 mroży appointment/create_appointment I-doctor
# text: wybieram termin 15.04.2021 o 14:30 # text: wybieram termin 15.04.2021 o 14:30
# intent: appointment/set_date appointment/set_time # intent: appointment/set_date appointment/set_time
@ -218,8 +218,8 @@
4 mam appointment/where NoLabel 4 mam appointment/where NoLabel
5 wizytę appointment/where B-appointment 5 wizytę appointment/where B-appointment
6 u appointment/where NoLabel 6 u appointment/where NoLabel
7 dentysty appointment/where B-appointment/doctor 7 dentysty appointment/where B-doctor
8 anny appointment/where I-appointment/doctor 8 anny appointment/where I-doctor
# text: a jaki adres # text: a jaki adres
# intent: request_information/location # intent: request_information/location
@ -241,7 +241,7 @@
2 zarezerować appointment/create_appointment NoLabel 2 zarezerować appointment/create_appointment NoLabel
3 wizytę appointment/create_appointment B-appointment 3 wizytę appointment/create_appointment B-appointment
4 u appointment/create_appointment NoLabel 4 u appointment/create_appointment NoLabel
5 lekarza appointment/create_appointment B-appointment/doctor 5 lekarza appointment/create_appointment B-doctor
# text: Chciałbym umówić wyzytę z dermatologiem # text: Chciałbym umówić wyzytę z dermatologiem
# intent: appointment/create_appointment # intent: appointment/create_appointment
@ -249,8 +249,8 @@
1 chciałbym appointment/create_appointment NoLabel 1 chciałbym appointment/create_appointment NoLabel
2 umówić appointment/create_appointment NoLabel 2 umówić appointment/create_appointment NoLabel
3 wyzytę appointment/create_appointment B-appointment 3 wyzytę appointment/create_appointment B-appointment
4 z appointment/create_appointment B-appointment/doctor 4 z appointment/create_appointment B-doctor
5 dermatologiem appointment/create_appointment I-appointment/doctor 5 dermatologiem appointment/create_appointment I-doctor
# text: Który ma wcześniejszy termin? # text: Który ma wcześniejszy termin?
# intent: appointment/compare_dates # intent: appointment/compare_dates
@ -268,8 +268,8 @@
3 zapisać appointment/create_appointment NoLabel 3 zapisać appointment/create_appointment NoLabel
4 się appointment/create_appointment NoLabel 4 się appointment/create_appointment NoLabel
5 do appointment/create_appointment NoLabel 5 do appointment/create_appointment NoLabel
6 jana appointment/create_appointment B-appointment/doctor 6 jana appointment/create_appointment B-doctor
7 kowalskiego appointment/create_appointment I-appointment/doctor 7 kowalskiego appointment/create_appointment I-doctor
# text: 15.04 o 14:30 # text: 15.04 o 14:30
# intent: appointment/set_date_and_time # intent: appointment/set_date_and_time
@ -320,8 +320,8 @@
# text: Jan kowalski # text: Jan kowalski
# intent: appointment/select_doctor # intent: appointment/select_doctor
# slots: # slots:
1 jan appointment/select_doctor B-appointment/doctor 1 jan appointment/select_doctor B-doctor
2 kowalski appointment/select_doctor I-appointment/doctor 2 kowalski appointment/select_doctor I-doctor
# text: proszę o termin 14.04.2021 - 14:30 # text: proszę o termin 14.04.2021 - 14:30
# intent: appointment/set_date_time # intent: appointment/set_date_time
@ -365,9 +365,9 @@
# text: Dr Anna Kowalska # text: Dr Anna Kowalska
# intent: appointment/select_doctor # intent: appointment/select_doctor
# slots: # slots:
1 dr appointment/select_doctor B-appointment/doctor 1 dr appointment/select_doctor B-doctor
2 anna appointment/select_doctor I-appointment/doctor 2 anna appointment/select_doctor I-doctor
3 kowalska appointment/select_doctor I-appointment/doctor 3 kowalska appointment/select_doctor I-doctor
# text: Proszę zapisać mnie na termin 14.04.2021 13:30 # text: Proszę zapisać mnie na termin 14.04.2021 13:30
# intent: appointment/create_appointment # intent: appointment/create_appointment
@ -448,7 +448,7 @@
2 o appointment/when NoLabel 2 o appointment/when NoLabel
3 której appointment/when NoLabel 3 której appointment/when NoLabel
4 mam appointment/when NoLabel 4 mam appointment/when NoLabel
5 dentystę appointment/when B-appointment/doctor 5 dentystę appointment/when B-doctor
# text: Ok Wszystko wiem dzięki! # text: Ok Wszystko wiem dzięki!
# intent: end_conversation # intent: end_conversation
@ -540,7 +540,7 @@
4 na appointment/create_appointment NoLabel 4 na appointment/create_appointment NoLabel
5 wizytę appointment/create_appointment B-appointment 5 wizytę appointment/create_appointment B-appointment
6 do appointment/create_appointment NoLabel 6 do appointment/create_appointment NoLabel
7 okulisty appointment/create_appointment B-appointment/doctor 7 okulisty appointment/create_appointment B-doctor
8 jakie appointment/create_appointment NoLabel 8 jakie appointment/create_appointment NoLabel
9 są appointment/create_appointment NoLabel 9 są appointment/create_appointment NoLabel
10 dostępne appointment/create_appointment NoLabel 10 dostępne appointment/create_appointment NoLabel
@ -656,8 +656,8 @@
6 na appointment/create_appointment NoLabel 6 na appointment/create_appointment NoLabel
7 wizytę appointment/create_appointment B-appointment 7 wizytę appointment/create_appointment B-appointment
8 do appointment/create_appointment NoLabel 8 do appointment/create_appointment NoLabel
9 lekarza appointment/create_appointment B-appointment/doctor 9 lekarza appointment/create_appointment B-doctor
10 rodzinnego appointment/create_appointment I-appointment/doctor 10 rodzinnego appointment/create_appointment I-doctor
11 najlepiej appointment/create_appointment NoLabel 11 najlepiej appointment/create_appointment NoLabel
12 dzisiaj appointment/create_appointment B-datetime 12 dzisiaj appointment/create_appointment B-datetime
13 w appointment/create_appointment I-datetime 13 w appointment/create_appointment I-datetime
@ -673,10 +673,10 @@
4 zapisać appointment/create_appointment NoLabel 4 zapisać appointment/create_appointment NoLabel
5 się appointment/create_appointment NoLabel 5 się appointment/create_appointment NoLabel
6 do appointment/create_appointment NoLabel 6 do appointment/create_appointment NoLabel
7 pani appointment/create_appointment B-appointment/doctor 7 pani appointment/create_appointment B-doctor
8 doktor appointment/create_appointment I-appointment/doctor 8 doktor appointment/create_appointment I-doctor
9 zofii appointment/create_appointment I-appointment/doctor 9 zofii appointment/create_appointment I-doctor
10 wątroby appointment/create_appointment I-appointment/doctor 10 wątroby appointment/create_appointment I-doctor
# text: Ten termin mi odpowiada! # text: Ten termin mi odpowiada!
# intent: appointment/confirm # intent: appointment/confirm
@ -755,8 +755,8 @@
3 umówić appointment/create_appointment NoLabel 3 umówić appointment/create_appointment NoLabel
4 spotkanie appointment/create_appointment B-appointment 4 spotkanie appointment/create_appointment B-appointment
5 z appointment/create_appointment NoLabel 5 z appointment/create_appointment NoLabel
6 lekarzem appointment/create_appointment B-appointment/doctor 6 lekarzem appointment/create_appointment B-doctor
7 internistą appointment/create_appointment I-appointment/doctor 7 internistą appointment/create_appointment I-doctor
# text: Tak # text: Tak
# intent: affirm # intent: affirm
@ -817,7 +817,7 @@
2 odwołać appointment/cancel NoLabel 2 odwołać appointment/cancel NoLabel
3 wizytę appointment/cancel B-appointment 3 wizytę appointment/cancel B-appointment
4 u appointment/cancel NoLabel 4 u appointment/cancel NoLabel
5 internisty appointment/cancel B-appointment/doctor 5 internisty appointment/cancel B-doctor
# text: Tak # text: Tak
# intent: affirm # intent: affirm
@ -828,8 +828,8 @@
# intent: request_information/doctors # intent: request_information/doctors
# slots: # slots:
1 jacy request_information/doctors NoLabel 1 jacy request_information/doctors NoLabel
2 lekarze request_information/doctors B-appointment/doctor 2 lekarze request_information/doctors B-doctor
3 specjaliści request_information/doctors B-appointment/doctor 3 specjaliści request_information/doctors B-doctor
4 przyjmują request_information/doctors NoLabel 4 przyjmują request_information/doctors NoLabel
5 w request_information/doctors NoLabel 5 w request_information/doctors NoLabel
6 państwa request_information/doctors NoLabel 6 państwa request_information/doctors NoLabel
@ -842,8 +842,8 @@
2 umówić appointment/create_appointment NoLabel 2 umówić appointment/create_appointment NoLabel
3 wizytę appointment/create_appointment B-appointment 3 wizytę appointment/create_appointment B-appointment
4 do appointment/create_appointment NoLabel 4 do appointment/create_appointment NoLabel
5 doktora appointment/create_appointment B-appointment/doctor 5 doktora appointment/create_appointment B-doctor
6 kolano appointment/create_appointment I-appointment/doctor 6 kolano appointment/create_appointment I-doctor
# text: Ten termin mi odpowiada # text: Ten termin mi odpowiada
# intent: appointment/confirm # intent: appointment/confirm
@ -888,7 +888,7 @@
2 zapisać appointment/create_appointment NoLabel 2 zapisać appointment/create_appointment NoLabel
3 się appointment/create_appointment NoLabel 3 się appointment/create_appointment NoLabel
4 do appointment/create_appointment NoLabel 4 do appointment/create_appointment NoLabel
5 okulisty appointment/create_appointment B-appointment/doctor 5 okulisty appointment/create_appointment B-doctor
6 ile request_information/cost NoLabel 6 ile request_information/cost NoLabel
7 kosztuje request_information/cost NoLabel 7 kosztuje request_information/cost NoLabel
8 wizyta request_information/cost B-appointment 8 wizyta request_information/cost B-appointment

View File

@ -3,15 +3,21 @@
"system_action": [], "system_action": [],
"belief_state": { "belief_state": {
"appointment": { "appointment": {
"prescription": { "name": "",
"url": {}, "location": "",
"type": {} "doctor": "",
"url": "",
"type": "",
"datetime": ""
}, },
"doctor": {}, "register": {
"where": {} "name": "",
"secondname": "",
"username": "",
"password": ""
}
}, },
"request_state": {}, "request_state": {},
"terminated": false, "terminated": false,
"history": [] "history": []
} }
}