Usunięcie convlaba z DSM

This commit is contained in:
Patryk Osiński 2024-06-09 23:05:07 +02:00
parent caea45471c
commit 4483747021
2 changed files with 16 additions and 17 deletions

View File

@ -1,5 +1,4 @@
from model.frame import Frame from src.model.frame import Frame
from convlab.dst.dst import DST
import copy import copy
@ -8,14 +7,9 @@ def normalize(value):
return ' '.join(value.split()) return ' '.join(value.split())
class DialogStateMonitor(DST): class DialogStateMonitor:
domain = 'restaurant'
def __init__(self): def __init__(self):
DST.__init__(self) self.__initial_state = dict(belief_state={
self.__initial_state = dict(user_action=[],
system_action=[],
belief_state={
'order': [], 'order': [],
'address': {}, 'address': {},
'order-complete': False, 'order-complete': False,
@ -25,13 +19,11 @@ class DialogStateMonitor(DST):
'time': {}, 'time': {},
'name': {}, 'name': {},
}, },
booked={},
request_state={},
terminated=False,
history=[]) history=[])
self.state = copy.deepcopy(self.__initial_state) self.state = copy.deepcopy(self.__initial_state)
def update(self, frame: Frame): def update(self, frame: Frame):
self.state['history'].append(frame)
if frame.source != 'user': if frame.source != 'user':
return return
if frame.act == 'inform/order': if frame.act == 'inform/order':

View File

@ -4,15 +4,22 @@ from src.model.slot import Slot
dst = DialogStateMonitor() dst = DialogStateMonitor()
dst.update(Frame('user', 'inform/order', [Slot('pizza', 'margaritta'), Slot('sauce', 'ketchup')])) frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margaritta'), Slot('sauce', 'ketchup')])
dst.update(Frame('user', 'inform/order', [Slot('pizza', 'carbonara')])) frame2 = Frame('user', 'inform/order', [Slot('pizza', 'carbonara')])
dst.update(Frame('user', 'inform/order-complete', [])) frame3 = Frame('user', 'inform/order-complete', [])
dst.update(frame1)
dst.update(frame2)
dst.update(frame3)
assert dst.state['belief_state']['order'][0]['pizza'] == 'margaritta' assert dst.state['belief_state']['order'][0]['pizza'] == 'margaritta'
assert dst.state['belief_state']['order'][0]['sauce'] == 'ketchup' assert dst.state['belief_state']['order'][0]['sauce'] == 'ketchup'
assert dst.state['belief_state']['order-complete'] == True assert dst.state['belief_state']['order-complete'] is True
assert dst.state['history'][0] == frame1
assert dst.state['history'][1] == frame2
assert dst.state['history'][2] == frame3
dst.reset() dst.reset()
assert dst.state['belief_state']['order'] == [] assert dst.state['belief_state']['order'] == []
assert dst.state['belief_state']['order-complete'] == False assert dst.state['belief_state']['order-complete'] is False
assert len(dst.state['history']) == 0