Zmiana metody zapisu pamięci w DST
This commit is contained in:
parent
d789fcc10b
commit
72e17d2106
@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
"address": null,
|
|
||||||
"order-complete": false,
|
|
||||||
"dough": ["thick"],
|
"dough": ["thick"],
|
||||||
"drink": ["pepsi", "cola", "water"],
|
"drink": ["pepsi", "cola", "water"],
|
||||||
"food": ["pizza"],
|
"food": ["pizza"],
|
||||||
@ -49,6 +47,5 @@
|
|||||||
"xl": {
|
"xl": {
|
||||||
"price_multiplier": 1.4
|
"price_multiplier": 1.4
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"order": []
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
from src.model.frame import Frame
|
from src.model.frame import Frame
|
||||||
from convlab.dst.dst import DST
|
from convlab.dst.dst import DST
|
||||||
import json
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
|
||||||
@ -10,19 +9,27 @@ def normalize(value):
|
|||||||
|
|
||||||
|
|
||||||
class DialogStateMonitor(DST):
|
class DialogStateMonitor(DST):
|
||||||
def __init__(self, initial_state_file: str = '../attributes.json'):
|
domain = 'restaurant'
|
||||||
DST.__init__(self)
|
|
||||||
with open(initial_state_file) as file:
|
|
||||||
self.__initial_state = json.load(file)
|
|
||||||
self.__memory = copy.deepcopy(self.__initial_state)
|
|
||||||
|
|
||||||
# def __access_memory__(self, path: str) -> str | int | float | None:
|
def __init__(self):
|
||||||
# result = self.state['memory']
|
DST.__init__(self)
|
||||||
# for segment in path.split('.'):
|
self.__initial_state = dict(user_action=[],
|
||||||
# if segment not in result:
|
system_action=[],
|
||||||
# return None
|
belief_state={
|
||||||
# result = result[segment]
|
'order': [],
|
||||||
# return result
|
'address': {},
|
||||||
|
'order-complete': False,
|
||||||
|
'phone': {},
|
||||||
|
'delivery': {},
|
||||||
|
'payment': {},
|
||||||
|
'time': {},
|
||||||
|
'name': {},
|
||||||
|
},
|
||||||
|
booked={},
|
||||||
|
request_state={},
|
||||||
|
terminated=False,
|
||||||
|
history=[])
|
||||||
|
self.state = copy.deepcopy(self.__initial_state)
|
||||||
|
|
||||||
def update(self, frame: Frame):
|
def update(self, frame: Frame):
|
||||||
if frame.source != 'user':
|
if frame.source != 'user':
|
||||||
@ -31,30 +38,27 @@ class DialogStateMonitor(DST):
|
|||||||
new_order = dict()
|
new_order = dict()
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
new_order[slot.name] = normalize(slot.value)
|
new_order[slot.name] = normalize(slot.value)
|
||||||
self.__memory['order'].append(new_order)
|
self.state['belief_state']['order'].append(new_order)
|
||||||
elif frame.act == 'inform/address':
|
elif frame.act == 'inform/address':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['address'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['address'][slot.name] = normalize(slot.value)
|
||||||
elif frame.act == 'inform/phone':
|
elif frame.act == 'inform/phone':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['phone'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['phone'][slot.name] = normalize(slot.value)
|
||||||
elif frame.act == 'inform/order-complete':
|
elif frame.act == 'inform/order-complete':
|
||||||
self.__memory['order-complete'] = True
|
self.state['belief_state']['order-complete'] = True
|
||||||
elif frame.act == 'inform/delivery':
|
elif frame.act == 'inform/delivery':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['delivery'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['delivery'][slot.name] = normalize(slot.value)
|
||||||
elif frame.act == 'inform/payment':
|
elif frame.act == 'inform/payment':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['payment'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['payment'][slot.name] = normalize(slot.value)
|
||||||
elif frame.act == 'inform/time':
|
elif frame.act == 'inform/time':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['time'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['time'][slot.name] = normalize(slot.value)
|
||||||
elif frame.act == 'inform/name':
|
elif frame.act == 'inform/name':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.__memory['name'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['name'][slot.name] = normalize(slot.value)
|
||||||
|
|
||||||
def read(self) -> dict:
|
|
||||||
return self.__memory
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.__memory = copy.deepcopy(self.__initial_state)
|
self.state = copy.deepcopy(self.__initial_state)
|
||||||
|
@ -4,17 +4,15 @@ from src.model.slot import Slot
|
|||||||
|
|
||||||
dst = DialogStateMonitor()
|
dst = DialogStateMonitor()
|
||||||
|
|
||||||
assert dst.read()['pizza']['capri']['price'] == 25
|
dst.update(Frame('user', 'inform/order', [Slot('pizza', 'margaritta'), Slot('sauce', 'ketchup')]))
|
||||||
|
dst.update(Frame('user', 'inform/order', [Slot('pizza', 'carbonara')]))
|
||||||
dst.update(Frame('user', 'inform/order', [Slot('B-pizza', 'margaritta'), Slot('B-sauce', 'ketchup')]))
|
|
||||||
dst.update(Frame('user', 'inform/order', [Slot('B-pizza', 'carbonara')]))
|
|
||||||
dst.update(Frame('user', 'inform/order-complete', []))
|
dst.update(Frame('user', 'inform/order-complete', []))
|
||||||
|
|
||||||
assert dst.read()['order'][0]['B-pizza'] == 'margaritta'
|
assert dst.state['belief_state']['order'][0]['pizza'] == 'margaritta'
|
||||||
assert dst.read()['order'][0]['B-sauce'] == 'ketchup'
|
assert dst.state['belief_state']['order'][0]['sauce'] == 'ketchup'
|
||||||
assert dst.read()['order-complete'] == True
|
assert dst.state['belief_state']['order-complete'] == True
|
||||||
|
|
||||||
dst.reset()
|
dst.reset()
|
||||||
|
|
||||||
assert dst.read()['order'] == []
|
assert dst.state['belief_state']['order'] == []
|
||||||
assert dst.read()['order-complete'] == False
|
assert dst.state['belief_state']['order-complete'] == False
|
||||||
|
Loading…
Reference in New Issue
Block a user