change dialog policy

This commit is contained in:
s459312 2023-05-25 15:06:14 +02:00
parent 53d498fb2c
commit a1257f29fb

View File

@ -102,7 +102,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 132, "execution_count": 136,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -120,10 +120,8 @@
" system_acts = []\n", " system_acts = []\n",
" for intent, domain, slot, value in state['user_act']:\n", " for intent, domain, slot, value in state['user_act']:\n",
" user_action[(domain.lower(), intent.lower())].append((slot.lower(), value))\n", " user_action[(domain.lower(), intent.lower())].append((slot.lower(), value))\n",
" print(user_action)\n",
" for user_act in user_action:\n", " for user_act in user_action:\n",
" self.update_system_action(user_act, user_action, state, system_action)\n", " self.update_system_action(user_act, user_action, state, system_action)\n",
" print(self.update_system_action(user_act, user_action, state, system_action))\n",
" system_acts = [[intent, domain, slot, value] for (domain, intent), slots in system_action.items() for slot, value in slots]\n", " system_acts = [[intent, domain, slot, value] for (domain, intent), slots in system_action.items() for slot, value in slots]\n",
" state['system_act'] = system_acts\n", " state['system_act'] = system_acts\n",
" return system_acts\n", " return system_acts\n",
@ -131,6 +129,7 @@
"\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",
" constraints = [(slot, value) for slot, value in state['belief_state'][domain.lower()].items() if value != '']\n",
" self.results = self.db['database'][domain]\n", " self.results = self.db['database'][domain]\n",
"\n", "\n",
" # Reguła 1\n", " # Reguła 1\n",
@ -149,45 +148,30 @@
" 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",
"\n", "\n",
" if self.results and 'name' in self.results[0]:\n", " if domain == \"product\":\n",
" choice = self.results[0]\n", " # Select the first product that matches the user's constraints\n",
"\n", " for product in self.results:\n",
" if domain in [\"payment\", \"delivery\", \"product\"]:\n", " if all(product.get(slot, '').lower() == value.lower() for slot, value in constraints):\n",
" system_action[(domain, 'Recommend')].append(['Name', choice['name']])" " system_action[(domain, 'Recommend')].append(['Name', product['name']])\n",
" break\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 133, "execution_count": 137,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"defaultdict(<class 'list'>, {('payment', 'inform'): [('type', 'karta')], ('delivery', 'inform'): [('type', 'paczkomat')], ('product', 'inform'): [('type', 'telefon')], ('product', 'request'): [('name', '?')]})\n",
"None\n",
"None\n",
"None\n",
"None\n"
]
},
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[['Inform', 'payment', 'Choice', '1'],\n", "[['Inform', 'payment', 'Choice', '1'],\n",
" ['Inform', 'payment', 'Choice', '1'],\n",
" ['Inform', 'delivery', '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', 'Choice', '3'],\n",
" ['Inform', 'product', 'name', 'banan'],\n", " ['Inform', 'product', 'name', 'banan'],\n",
" ['Inform', 'product', 'name', 'banan'],\n", " ['Recommend', 'product', 'Name', 'iPhone']]"
" ['Recommend', 'product', 'Name', 'banan'],\n",
" ['Recommend', 'product', 'Name', 'banan']]"
] ]
}, },
"execution_count": 133, "execution_count": 137,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }