change dialog policy
This commit is contained in:
parent
43115895e5
commit
53d498fb2c
@ -102,20 +102,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 122,
|
"execution_count": 132,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from collections import defaultdict\n",
|
"from collections import defaultdict\n",
|
||||||
"import json\n",
|
"import json\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"class SimpleRulePolicy():\n",
|
"class SimpleRulePolicy():\n",
|
||||||
" def __init__(self):\n",
|
" def __init__(self):\n",
|
||||||
" with open('product_db.json', encoding='utf-8') as json_file:\n",
|
" self.db = json.load(open('product_db.json'))\n",
|
||||||
" self.db = json.load(json_file)\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" def predict(self, state):\n",
|
" def predict(self, state):\n",
|
||||||
" self.results = []\n",
|
" self.results = []\n",
|
||||||
@ -135,14 +131,15 @@
|
|||||||
"\n",
|
"\n",
|
||||||
" def update_system_action(self, user_act, user_action, state, system_action):\n",
|
" def update_system_action(self, user_act, user_action, state, system_action):\n",
|
||||||
" domain, intent = user_act\n",
|
" domain, intent = user_act\n",
|
||||||
|
" self.results = self.db['database'][domain]\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Reguła 1\n",
|
" # Reguła 1\n",
|
||||||
" if intent == 'request':\n",
|
" if intent == 'request':\n",
|
||||||
" if len(self.results) == 0:\n",
|
" if len(self.results) == 0:\n",
|
||||||
" system_action[(domain, 'NoOffer')] = []\n",
|
" system_action[(domain, 'NoOffer')] = []\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" for slot in user_action[user_act]: \n",
|
" for slot in user_action[user_act]:\n",
|
||||||
" if slot[0] in self.results[0]:\n",
|
" if self.results and slot[0] in self.results[0]:\n",
|
||||||
" system_action[(domain, 'Inform')].append([slot[0], self.results[0].get(slot[0], 'unknown')])\n",
|
" system_action[(domain, 'Inform')].append([slot[0], self.results[0].get(slot[0], 'unknown')])\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Reguła 2\n",
|
" # Reguła 2\n",
|
||||||
@ -151,15 +148,17 @@
|
|||||||
" system_action[(domain, 'NoOffer')] = []\n",
|
" system_action[(domain, 'NoOffer')] = []\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))])\n",
|
" system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))])\n",
|
||||||
" choice = self.results[0]\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" if domain in [\"payment\", \"delivery\", \"product\"]:\n",
|
" if self.results and 'name' in self.results[0]:\n",
|
||||||
" system_action[(domain, 'Recommend')].append(['Name', choice['name']])"
|
" choice = self.results[0]\n",
|
||||||
|
"\n",
|
||||||
|
" if domain in [\"payment\", \"delivery\", \"product\"]:\n",
|
||||||
|
" system_action[(domain, 'Recommend')].append(['Name', choice['name']])"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 123,
|
"execution_count": 133,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -176,10 +175,19 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"[]"
|
"[['Inform', 'payment', 'Choice', '1'],\n",
|
||||||
|
" ['Inform', 'payment', 'Choice', '1'],\n",
|
||||||
|
" ['Inform', 'delivery', 'Choice', '1'],\n",
|
||||||
|
" ['Inform', 'delivery', 'Choice', '1'],\n",
|
||||||
|
" ['Inform', 'product', 'Choice', '3'],\n",
|
||||||
|
" ['Inform', 'product', 'Choice', '3'],\n",
|
||||||
|
" ['Inform', 'product', 'name', 'banan'],\n",
|
||||||
|
" ['Inform', 'product', 'name', 'banan'],\n",
|
||||||
|
" ['Recommend', 'product', 'Name', 'banan'],\n",
|
||||||
|
" ['Recommend', 'product', 'Name', 'banan']]"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 123,
|
"execution_count": 133,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user