Wstępnie działający DST
This commit is contained in:
parent
2eca0a043d
commit
f58a1b47c7
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*frame-model*
|
||||
*slot-model*
|
||||
.venv*
|
||||
env*
|
||||
env*
|
||||
*__pycache__*
|
@ -1,9 +1,6 @@
|
||||
import json
|
||||
from convlab2.dst.dst import DST
|
||||
from convlab2.dst.rule.multiwoz.dst_util import normalize_value
|
||||
|
||||
|
||||
class Rules_DST(DST): #Dialogue State Tracker
|
||||
class Rules_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.
|
||||
|
||||
@ -12,37 +9,28 @@ class Rules_DST(DST): #Dialogue State Tracker
|
||||
Wyjście: Reprezentacja stanu dialogu (rama)
|
||||
"""
|
||||
def __init__(self):
|
||||
DST.__init__(self)
|
||||
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']:
|
||||
return
|
||||
|
||||
if domain in ['password', 'name', 'email', 'enter_email', 'enter_name']:
|
||||
return
|
||||
|
||||
if 'appointment' in intent:
|
||||
for full_slot in slots:
|
||||
slot = full_slot[1]
|
||||
value = full_slot[1]
|
||||
k = self.value_dict[domain.lower()].get(slot, slot)
|
||||
|
||||
if k is None:
|
||||
return
|
||||
if 'appointment' in intent:
|
||||
if (slot == 'appointment'):
|
||||
continue
|
||||
|
||||
if(domain in slot):
|
||||
slot.replace(domain + "/", '')
|
||||
|
||||
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
|
||||
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 == 'end_conversation':
|
||||
self.state = {}
|
||||
|
||||
return self.state
|
||||
if slot in domain_dic:
|
||||
self.state['belief_state'][domain][slot] = value
|
||||
else:
|
||||
print(slot)
|
||||
print(domain)
|
||||
elif intent == 'end_conversation':
|
||||
self.state = json.load(open('default_state.json'))
|
||||
print(self.state)
|
||||
return self.state
|
||||
|
@ -48,7 +48,7 @@ class ML_NLU:
|
||||
slots, act = self.predict(utterance.split())
|
||||
slots = [x for x in slots if x[1] != 'O']
|
||||
arguments = self.convert_slot_to_argument(slots)
|
||||
return {'act': act, 'slots': arguments}
|
||||
return self.convert_act_to_list(act, arguments)
|
||||
else:
|
||||
return 'Critical Error'
|
||||
|
||||
@ -65,3 +65,13 @@ class ML_NLU:
|
||||
if(candidate != None):
|
||||
arguments.append(candidate)
|
||||
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
|
@ -66,16 +66,16 @@ frame_tagger = SequenceTagger(hidden_size=256, embeddings=embeddings,
|
||||
tag_type='frame', use_crf=True)
|
||||
|
||||
slot_trainer = ModelTrainer(slot_tagger, slot_corpus)
|
||||
# slot_trainer.train('slot-model',
|
||||
# learning_rate=0.1,
|
||||
# mini_batch_size=32,
|
||||
# max_epochs=100,
|
||||
# train_with_dev=False)
|
||||
slot_trainer.train('slot-model',
|
||||
learning_rate=0.1,
|
||||
mini_batch_size=32,
|
||||
max_epochs=100,
|
||||
train_with_dev=False)
|
||||
|
||||
|
||||
# frame_trainer = ModelTrainer(frame_tagger, frame_corpus)
|
||||
# frame_trainer.train('frame-model',
|
||||
# learning_rate=0.1,
|
||||
# mini_batch_size=32,
|
||||
# max_epochs=100,
|
||||
# train_with_dev=False)
|
||||
frame_trainer = ModelTrainer(frame_tagger, frame_corpus)
|
||||
frame_trainer.train('frame-model',
|
||||
learning_rate=0.1,
|
||||
mini_batch_size=32,
|
||||
max_epochs=100,
|
||||
train_with_dev=False)
|
80
Janet.conllu
80
Janet.conllu
@ -50,8 +50,8 @@
|
||||
6 na appointment/create_appointment NoLabel
|
||||
7 wizytę appointment/create_appointment B-appointment
|
||||
8 u appointment/create_appointment NoLabel
|
||||
9 lekarza appointment/create_appointment B-appointment/doctor
|
||||
10 internisty appointment/create_appointment I-appointment/doctor
|
||||
9 lekarza appointment/create_appointment B-doctor
|
||||
10 internisty appointment/create_appointment I-doctor
|
||||
|
||||
# text: Nie mam swojego identyfikatora nie pamiętam
|
||||
# intent: login/forgot_id
|
||||
@ -83,9 +83,9 @@
|
||||
7 terminie request_information/available_dates NoLabel
|
||||
8 20.04.2021 request_information/available_dates B-datetime
|
||||
9 u request_information/available_dates NoLabel
|
||||
10 dr request_information/available_dates B-appointment/doctor
|
||||
11 adam request_information/available_dates I-appointment/doctor
|
||||
12 skrzypczak request_information/available_dates I-appointment/doctor
|
||||
10 dr request_information/available_dates B-doctor
|
||||
11 adam request_information/available_dates I-doctor
|
||||
12 skrzypczak request_information/available_dates I-doctor
|
||||
|
||||
# text: tak
|
||||
# intent: affirm
|
||||
@ -104,7 +104,7 @@
|
||||
7 20.04.2021 request_information/available_dates B-datetime
|
||||
8 u 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
|
||||
# intent: appointment/create_appointment
|
||||
@ -113,7 +113,7 @@
|
||||
2 o appointment/create_appointment NoLabel
|
||||
3 rejestrację 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
|
||||
7 12:00 appointment/create_appointment B-datetime
|
||||
8 dziękuję appointment/create_appointment B-end_conversation
|
||||
@ -128,7 +128,7 @@
|
||||
3 zarezerwować appointment/create_appointment NoLabel
|
||||
4 wizytę appointment/create_appointment B-appointment
|
||||
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
|
||||
# intent: appointment/set_date
|
||||
@ -157,7 +157,7 @@
|
||||
4 na appointment/create_appointment NoLabel
|
||||
5 wizytę appointment/create_appointment B-appointment
|
||||
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
|
||||
# intent: request_information/doctors
|
||||
@ -173,9 +173,9 @@
|
||||
1 chciałbym appointment/create_appointment NoLabel
|
||||
2 wizytę appointment/create_appointment NoLabel
|
||||
3 u appointment/create_appointment NoLabel
|
||||
4 internista appointment/create_appointment B-appointment/doctor
|
||||
5 andrzej appointment/create_appointment I-appointment/doctor
|
||||
6 mroży appointment/create_appointment I-appointment/doctor
|
||||
4 internista appointment/create_appointment B-doctor
|
||||
5 andrzej appointment/create_appointment I-doctor
|
||||
6 mroży appointment/create_appointment I-doctor
|
||||
|
||||
# text: wybieram termin 15.04.2021 o 14:30
|
||||
# intent: appointment/set_date appointment/set_time
|
||||
@ -218,8 +218,8 @@
|
||||
4 mam appointment/where NoLabel
|
||||
5 wizytę appointment/where B-appointment
|
||||
6 u appointment/where NoLabel
|
||||
7 dentysty appointment/where B-appointment/doctor
|
||||
8 anny appointment/where I-appointment/doctor
|
||||
7 dentysty appointment/where B-doctor
|
||||
8 anny appointment/where I-doctor
|
||||
|
||||
# text: a jaki adres
|
||||
# intent: request_information/location
|
||||
@ -241,7 +241,7 @@
|
||||
2 zarezerować appointment/create_appointment NoLabel
|
||||
3 wizytę appointment/create_appointment B-appointment
|
||||
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
|
||||
# intent: appointment/create_appointment
|
||||
@ -249,8 +249,8 @@
|
||||
1 chciałbym appointment/create_appointment NoLabel
|
||||
2 umówić appointment/create_appointment NoLabel
|
||||
3 wyzytę appointment/create_appointment B-appointment
|
||||
4 z appointment/create_appointment B-appointment/doctor
|
||||
5 dermatologiem appointment/create_appointment I-appointment/doctor
|
||||
4 z appointment/create_appointment B-doctor
|
||||
5 dermatologiem appointment/create_appointment I-doctor
|
||||
|
||||
# text: Który ma wcześniejszy termin?
|
||||
# intent: appointment/compare_dates
|
||||
@ -268,8 +268,8 @@
|
||||
3 zapisać appointment/create_appointment NoLabel
|
||||
4 się appointment/create_appointment NoLabel
|
||||
5 do appointment/create_appointment NoLabel
|
||||
6 jana appointment/create_appointment B-appointment/doctor
|
||||
7 kowalskiego appointment/create_appointment I-appointment/doctor
|
||||
6 jana appointment/create_appointment B-doctor
|
||||
7 kowalskiego appointment/create_appointment I-doctor
|
||||
|
||||
# text: 15.04 o 14:30
|
||||
# intent: appointment/set_date_and_time
|
||||
@ -320,8 +320,8 @@
|
||||
# text: Jan kowalski
|
||||
# intent: appointment/select_doctor
|
||||
# slots:
|
||||
1 jan appointment/select_doctor B-appointment/doctor
|
||||
2 kowalski appointment/select_doctor I-appointment/doctor
|
||||
1 jan appointment/select_doctor B-doctor
|
||||
2 kowalski appointment/select_doctor I-doctor
|
||||
|
||||
# text: proszę o termin 14.04.2021 - 14:30
|
||||
# intent: appointment/set_date_time
|
||||
@ -365,9 +365,9 @@
|
||||
# text: Dr Anna Kowalska
|
||||
# intent: appointment/select_doctor
|
||||
# slots:
|
||||
1 dr appointment/select_doctor B-appointment/doctor
|
||||
2 anna appointment/select_doctor I-appointment/doctor
|
||||
3 kowalska appointment/select_doctor I-appointment/doctor
|
||||
1 dr appointment/select_doctor B-doctor
|
||||
2 anna appointment/select_doctor I-doctor
|
||||
3 kowalska appointment/select_doctor I-doctor
|
||||
|
||||
# text: Proszę zapisać mnie na termin 14.04.2021 13:30
|
||||
# intent: appointment/create_appointment
|
||||
@ -448,7 +448,7 @@
|
||||
2 o appointment/when NoLabel
|
||||
3 której 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!
|
||||
# intent: end_conversation
|
||||
@ -540,7 +540,7 @@
|
||||
4 na appointment/create_appointment NoLabel
|
||||
5 wizytę appointment/create_appointment B-appointment
|
||||
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
|
||||
9 są appointment/create_appointment NoLabel
|
||||
10 dostępne appointment/create_appointment NoLabel
|
||||
@ -656,8 +656,8 @@
|
||||
6 na appointment/create_appointment NoLabel
|
||||
7 wizytę appointment/create_appointment B-appointment
|
||||
8 do appointment/create_appointment NoLabel
|
||||
9 lekarza appointment/create_appointment B-appointment/doctor
|
||||
10 rodzinnego appointment/create_appointment I-appointment/doctor
|
||||
9 lekarza appointment/create_appointment B-doctor
|
||||
10 rodzinnego appointment/create_appointment I-doctor
|
||||
11 najlepiej appointment/create_appointment NoLabel
|
||||
12 dzisiaj appointment/create_appointment B-datetime
|
||||
13 w appointment/create_appointment I-datetime
|
||||
@ -673,10 +673,10 @@
|
||||
4 zapisać appointment/create_appointment NoLabel
|
||||
5 się appointment/create_appointment NoLabel
|
||||
6 do appointment/create_appointment NoLabel
|
||||
7 pani appointment/create_appointment B-appointment/doctor
|
||||
8 doktor appointment/create_appointment I-appointment/doctor
|
||||
9 zofii appointment/create_appointment I-appointment/doctor
|
||||
10 wątroby appointment/create_appointment I-appointment/doctor
|
||||
7 pani appointment/create_appointment B-doctor
|
||||
8 doktor appointment/create_appointment I-doctor
|
||||
9 zofii appointment/create_appointment I-doctor
|
||||
10 wątroby appointment/create_appointment I-doctor
|
||||
|
||||
# text: Ten termin mi odpowiada!
|
||||
# intent: appointment/confirm
|
||||
@ -755,8 +755,8 @@
|
||||
3 umówić appointment/create_appointment NoLabel
|
||||
4 spotkanie appointment/create_appointment B-appointment
|
||||
5 z appointment/create_appointment NoLabel
|
||||
6 lekarzem appointment/create_appointment B-appointment/doctor
|
||||
7 internistą appointment/create_appointment I-appointment/doctor
|
||||
6 lekarzem appointment/create_appointment B-doctor
|
||||
7 internistą appointment/create_appointment I-doctor
|
||||
|
||||
# text: Tak
|
||||
# intent: affirm
|
||||
@ -817,7 +817,7 @@
|
||||
2 odwołać appointment/cancel NoLabel
|
||||
3 wizytę appointment/cancel B-appointment
|
||||
4 u appointment/cancel NoLabel
|
||||
5 internisty appointment/cancel B-appointment/doctor
|
||||
5 internisty appointment/cancel B-doctor
|
||||
|
||||
# text: Tak
|
||||
# intent: affirm
|
||||
@ -828,8 +828,8 @@
|
||||
# intent: request_information/doctors
|
||||
# slots:
|
||||
1 jacy request_information/doctors NoLabel
|
||||
2 lekarze request_information/doctors B-appointment/doctor
|
||||
3 specjaliści request_information/doctors B-appointment/doctor
|
||||
2 lekarze request_information/doctors B-doctor
|
||||
3 specjaliści request_information/doctors B-doctor
|
||||
4 przyjmują request_information/doctors NoLabel
|
||||
5 w request_information/doctors NoLabel
|
||||
6 państwa request_information/doctors NoLabel
|
||||
@ -842,8 +842,8 @@
|
||||
2 umówić appointment/create_appointment NoLabel
|
||||
3 wizytę appointment/create_appointment B-appointment
|
||||
4 do appointment/create_appointment NoLabel
|
||||
5 doktora appointment/create_appointment B-appointment/doctor
|
||||
6 kolano appointment/create_appointment I-appointment/doctor
|
||||
5 doktora appointment/create_appointment B-doctor
|
||||
6 kolano appointment/create_appointment I-doctor
|
||||
|
||||
# text: Ten termin mi odpowiada
|
||||
# intent: appointment/confirm
|
||||
@ -888,7 +888,7 @@
|
||||
2 zapisać appointment/create_appointment NoLabel
|
||||
3 się 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
|
||||
7 kosztuje request_information/cost NoLabel
|
||||
8 wizyta request_information/cost B-appointment
|
||||
|
@ -3,15 +3,21 @@
|
||||
"system_action": [],
|
||||
"belief_state": {
|
||||
"appointment": {
|
||||
"prescription": {
|
||||
"url": {},
|
||||
"type": {}
|
||||
},
|
||||
"doctor": {},
|
||||
"where": {}
|
||||
"name": "",
|
||||
"location": "",
|
||||
"doctor": "",
|
||||
"url": "",
|
||||
"type": "",
|
||||
"datetime": ""
|
||||
},
|
||||
"request_state": {},
|
||||
"terminated": false,
|
||||
"history": []
|
||||
}
|
||||
"register": {
|
||||
"name": "",
|
||||
"secondname": "",
|
||||
"username": "",
|
||||
"password": ""
|
||||
}
|
||||
},
|
||||
"request_state": {},
|
||||
"terminated": false,
|
||||
"history": []
|
||||
}
|
Loading…
Reference in New Issue
Block a user