DP happy path

This commit is contained in:
s444417 2022-05-27 18:01:18 +02:00
parent 4f51c56312
commit 184bc462e0
6 changed files with 1262 additions and 359 deletions

View File

@ -14,8 +14,10 @@
---
## Zadanie 9/10 DST
## Zadanie 9/10 DST i DP
- implementacja regułowego modułu DST: **src/components DST.py**
- implementacja regułowego DP, tylko happy path: **src/components DP.py**
- wykorzystanie w pliku **src/dialogue_system.py**

View File

@ -0,0 +1,972 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n",
"<div class=\"alert alert-block alert-info\">\n",
"<h1> Systemy Dialogowe </h1>\n",
"<h2> 9. <i>Zarządzanie dialogiem z wykorzystaniem reguł</i> [laboratoria]</h2> \n",
"<h3> Marek Kubis (2021)</h3>\n",
"</div>\n",
"\n",
"![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zarządzanie dialogiem z wykorzystaniem reguł\n",
"============================================\n",
"\n",
"Agent dialogowy wykorzystuje do zarządzanie dialogiem dwa moduły:\n",
"\n",
" - monitor stanu dialogu (dialogue state tracker, DST) — moduł odpowiedzialny za śledzenie stanu dialogu.\n",
"\n",
" - taktykę prowadzenia dialogu (dialogue policy) — moduł, który na podstawie stanu dialogu\n",
" podejmuje decyzję o tym jaką akcję (akt systemu) agent ma podjąć w kolejnej turze.\n",
"\n",
"Oba moduły mogą być realizowane zarówno z wykorzystaniem reguł jak i uczenia maszynowego.\n",
"Mogą one zostać również połączone w pojedynczy moduł zwany wówczas *menedżerem dialogu*.\n",
"\n",
"Przykład\n",
"--------\n",
"\n",
"Zaimplementujemy regułowe moduły monitora stanu dialogu oraz taktyki dialogowej a następnie\n",
"osadzimy je w środowisku *[ConvLab-2](https://github.com/thu-coai/ConvLab-2)*,\n",
"które służy do ewaluacji systemów dialogowych.\n",
"\n",
"**Uwaga:** Niektóre moduły środowiska *ConvLab-2* nie są zgodne z najnowszymi wersjami Pythona,\n",
"dlatego przed uruchomieniem poniższych przykładów należy się upewnić, że mają Państwo interpreter\n",
"Pythona w wersji 3.7. W przypadku nowszych wersji Ubuntu Pythona 3.7 można zainstalować z\n",
"repozytorium `deadsnakes`, wykonując polecenia przedstawione poniżej.\n",
"\n",
"```\n",
"sudo add-apt-repository ppa:deadsnakes/ppa\n",
"sudo apt update\n",
"sudo apt install python3.7 python3.7-dev python3.7-venv\n",
"```\n",
"\n",
"W przypadku innych systemów można skorzystać np. z narzędzia [pyenv](https://github.com/pyenv/pyenv) lub środowiska [conda](https://conda.io).\n",
"\n",
"Ze względu na to, że *ConvLab-2* ma wiele zależności zachęcam również do skorzystania ze środowiska\n",
"wirtualnego `venv`, w którym moduły zależne mogą zostać zainstalowane.\n",
"W tym celu należy wykonać następujące polecenia\n",
"\n",
"```\n",
"python3.7 -m venv convenv # utworzenie nowego środowiska o nazwie convenv\n",
"source convenv/bin/activate # aktywacja środowiska w bieżącej powłoce\n",
"pip install --ignore-installed jupyter # instalacja jupytera w środowisku convenv\n",
"```\n",
"\n",
"Po skonfigurowaniu środowiska można przystąpić do instalacji *ConvLab-2*, korzystając z\n",
"następujących poleceń\n",
"\n",
"```\n",
"mkdir -p l08\n",
"cd l08\n",
"git clone https://github.com/thu-coai/ConvLab-2.git\n",
"cd ConvLab-2\n",
"pip install -e .\n",
"python -m spacy download en_core_web_sm\n",
"cd ../..\n",
"```\n",
"\n",
"Po zakończeniu instalacji należy ponownie uruchomić notatnik w powłoce, w której aktywne jest\n",
"środowisko wirtualne *convenv*.\n",
"\n",
"```\n",
"jupyter notebook 08-zarzadzanie-dialogiem-reguly.ipynb\n",
"```\n",
"\n",
"Działanie zaimplementowanych modułów zilustrujemy, korzystając ze zbioru danych\n",
"[MultiWOZ](https://github.com/budzianowski/multiwoz) (Budzianowski i in., 2018), który zawiera\n",
"wypowiedzi dotyczące m.in. rezerwacji pokoi hotelowych, zamawiania biletów kolejowych oraz\n",
"rezerwacji stolików w restauracji.\n",
"\n",
"### Monitor Stanu Dialogu\n",
"\n",
"Do reprezentowania stanu dialogu użyjemy struktury danych wykorzystywanej w *ConvLab-2*."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': '',\n",
" 'date': '',\n",
" 'time': '',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'request_state': {},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# from convlab2.util.multiwoz.state import default_state\n",
"from utils.state import default_state\n",
"default_state()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Metoda `update` naszego monitora stanu dialogu będzie przyjmować akty użytkownika i odpowiednio\n",
"modyfikować stan dialogu.\n",
"W przypadku aktów typu `inform` wartości slotów zostaną zapamiętane w słownikach odpowiadających\n",
"poszczególnym dziedzinom pod kluczem `belief_state`.\n",
"W przypadku aktów typu `request` sloty, o które pyta użytkownik zostaną zapisane pod kluczem\n",
"`request_state`.\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\nclass SimpleRuleDST(DST):\\n def __init__(self):\\n DST.__init__(self)\\n self.state = default_state()\\n self.value_dict = json.load(open('l08/ConvLab-2/data/multiwoz/value_dict.json'))\\n\\n def update(self, user_act=None):\\n for intent, domain, slot, value in user_act:\\n domain = domain.lower()\\n intent = intent.lower()\\n\\n if domain in ['unk', 'general', 'booking']:\\n continue\\n\\n if intent == 'inform':\\n k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\\n\\n if k is None:\\n continue\\n\\n domain_dic = self.state['belief_state'][domain]\\n\\n if k in domain_dic['semi']:\\n nvalue = normalize_value(self.value_dict, domain, k, value)\\n self.state['belief_state'][domain]['semi'][k] = nvalue\\n elif k in domain_dic['book']:\\n self.state['belief_state'][domain]['book'][k] = value\\n elif k.lower() in domain_dic['book']:\\n self.state['belief_state'][domain]['book'][k.lower()] = value\\n elif intent == 'request':\\n k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\\n\\n if domain not in self.state['request_state']:\\n self.state['request_state'][domain] = {}\\n if k not in self.state['request_state'][domain]:\\n self.state['request_state'][domain][k] = 0\\n\\n return self.state\\n\\n def init_session(self):\\n self.state = default_state()\\n\""
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import json\n",
"import os\n",
"from convlab2.dst.dst import DST\n",
"from convlab2.dst.rule.multiwoz.dst_util import normalize_value\n",
"from convlab2.util.multiwoz.multiwoz_slot_trans import REF_SYS_DA\n",
"\n",
"class SimpleRuleDST(DST):\n",
" def __init__(self):\n",
" DST.__init__(self)\n",
" self.state = default_state()\n",
" self.value_dict = json.load(open('utils/value_dict.json'))\n",
"\n",
" def update(self, user_act=None):\n",
" for intent, domain, slot, value in user_act:\n",
" domain = domain.lower()\n",
" intent = intent.lower()\n",
" value = value.lower()\n",
"\n",
" # if domain in ['unk', 'cinema']:\n",
" # continue\n",
" k = slot\n",
"\n",
" if intent == 'inform':\n",
" # k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
" # if k is None:\n",
" # continue\n",
"\n",
" domain_dic = self.state['belief_state'][domain]\n",
"\n",
" if k in domain_dic['semi']:\n",
" # nvalue = normalize_value(self.value_dict, domain, k, value)\n",
" self.state['belief_state'][domain]['semi'][k] = value\n",
" elif k in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k] = value\n",
" elif k.lower() in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k.lower()] = value\n",
" elif intent == 'request':\n",
" # k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
"\n",
" if domain not in self.state['request_state']:\n",
" self.state['request_state'][domain] = {}\n",
" if k not in self.state['request_state'][domain]:\n",
" self.state['request_state'][domain][k] = 0\n",
"\n",
" return self.state\n",
"\n",
" def init_session(self):\n",
" self.state = default_state()\n",
"\n",
"'''\n",
"class SimpleRuleDST(DST):\n",
" def __init__(self):\n",
" DST.__init__(self)\n",
" self.state = default_state()\n",
" self.value_dict = json.load(open('l08/ConvLab-2/data/multiwoz/value_dict.json'))\n",
"\n",
" def update(self, user_act=None):\n",
" for intent, domain, slot, value in user_act:\n",
" domain = domain.lower()\n",
" intent = intent.lower()\n",
"\n",
" if domain in ['unk', 'general', 'booking']:\n",
" continue\n",
"\n",
" if intent == 'inform':\n",
" k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
"\n",
" if k is None:\n",
" continue\n",
"\n",
" domain_dic = self.state['belief_state'][domain]\n",
"\n",
" if k in domain_dic['semi']:\n",
" nvalue = normalize_value(self.value_dict, domain, k, value)\n",
" self.state['belief_state'][domain]['semi'][k] = nvalue\n",
" elif k in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k] = value\n",
" elif k.lower() in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k.lower()] = value\n",
" elif intent == 'request':\n",
" k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
"\n",
" if domain not in self.state['request_state']:\n",
" self.state['request_state'][domain] = {}\n",
" if k not in self.state['request_state'][domain]:\n",
" self.state['request_state'][domain][k] = 0\n",
"\n",
" return self.state\n",
"\n",
" def init_session(self):\n",
" self.state = default_state()\n",
"'''\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"W definicji metody `update` zakładamy, że akty dialogowe przekazywane do monitora stanu dialogu z\n",
"modułu NLU są czteroelementowymi listami złożonymi z:\n",
"\n",
" - nazwy aktu użytkownika,\n",
" - nazwy dziedziny, której dotyczy wypowiedź,\n",
" - nazwy slotu,\n",
" - wartości slotu.\n",
"\n",
"Zobaczmy na kilku prostych przykładach jak stan dialogu zmienia się pod wpływem przekazanych aktów\n",
"użytkownika."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': '',\n",
" 'date': '',\n",
" 'time': '',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'request_state': {},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst = SimpleRuleDST()\n",
"dst.state"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"{'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Inform', 'Cinema', 'time', '15:00'], ['Inform', 'Cinema', 'title', 'Batman']])\n",
"dst.state['belief_state']['cinema']"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"{'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': 'na górze na środku',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Inform', 'Cinema', 'area', 'na górze na środku']])\n",
"dst.state['belief_state']['cinema']"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/plain": [
"{'cinema': {'date': 0}}"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Request', 'Cinema', 'date', '?']])\n",
"dst.state['request_state']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"dst.update([['Inform', 'Hotel', 'Day', 'tuesday'], ['Inform', 'Hotel', 'People', '2'], ['Inform', 'Hotel', 'Stay', '4']])\n",
"dst.state['belief_state']['hotel']"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': 'na górze na środku',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'request_state': {'cinema': {'date': 0}},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.state"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Taktyka Prowadzenia Dialogu\n",
"\n",
"Prosta taktyka prowadzenia dialogu dla systemu rezerwacji pokoi hotelowych może składać się z następujących reguł:\n",
"\n",
" 1. Jeżeli użytkownik przekazał w ostatniej turze akt typu `Request`, to udziel odpowiedzi na jego\n",
" pytanie.\n",
"\n",
" 2. Jeżeli użytkownik przekazał w ostatniej turze akt typu `Inform`, to zaproponuj mu hotel\n",
" spełniający zdefiniowane przez niego kryteria.\n",
"\n",
" 3. Jeżeli użytkownik przekazał w ostatniej turze akt typu `Inform` zawierający szczegóły\n",
" rezerwacji, to zarezerwuj pokój.\n",
"\n",
"Metoda `predict` taktyki `SimpleRulePolicy` realizuje reguły przedstawione powyżej."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"from collections import defaultdict\n",
"import copy\n",
"import json\n",
"from copy import deepcopy\n",
"\n",
"from convlab2.policy.policy import Policy\n",
"from convlab2.util.multiwoz.dbquery import Database\n",
"from convlab2.util.multiwoz.multiwoz_slot_trans import REF_SYS_DA, REF_USR_DA\n",
"\n",
"\n",
"class SimpleRulePolicy(Policy):\n",
" def __init__(self):\n",
" Policy.__init__(self)\n",
" self.db = Database()\n",
"\n",
" def predict(self, state):\n",
" self.results = []\n",
" system_action = defaultdict(list)\n",
" user_action = defaultdict(list)\n",
"\n",
" for intent, domain, slot, value in state['user_action']:\n",
" user_action[(domain, intent)].append((slot, value))\n",
"\n",
" for user_act in user_action:\n",
" self.update_system_action(user_act, user_action, state, system_action)\n",
"\n",
" # Reguła 3\n",
" if any(True for slots in user_action.values() for (slot, _) in slots if slot in ['Stay', 'Day', 'People']):\n",
" if self.results:\n",
" system_action = {('Booking', 'Book'): [[\"Ref\", self.results[0].get('Ref', 'N/A')]]}\n",
"\n",
" system_acts = [[intent, domain, slot, value] for (domain, intent), slots in system_action.items() for slot, value in slots]\n",
" state['system_action'] = system_acts\n",
" return system_acts\n",
"\n",
" def update_system_action(self, user_act, user_action, state, system_action):\n",
" domain, intent = user_act\n",
" constraints = [(slot, value) for slot, value in state['belief_state'][domain.lower()]['semi'].items() if value != '']\n",
" self.results = deepcopy(self.db.query(domain.lower(), constraints))\n",
"\n",
" # Reguła 1\n",
" if intent == 'Request':\n",
" if len(self.results) == 0:\n",
" system_action[(domain, 'NoOffer')] = []\n",
" else:\n",
" for slot in user_action[user_act]:\n",
" kb_slot_name = REF_SYS_DA[domain].get(slot[0], slot[0])\n",
"\n",
" if kb_slot_name in self.results[0]:\n",
" system_action[(domain, 'Inform')].append([slot[0], self.results[0].get(kb_slot_name, 'unknown')])\n",
"\n",
" # Reguła 2\n",
" elif intent == 'Inform':\n",
" if len(self.results) == 0:\n",
" system_action[(domain, 'NoOffer')] = []\n",
" else:\n",
" system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))])\n",
" choice = self.results[0]\n",
"\n",
" if domain in [\"Hotel\", \"Attraction\", \"Police\", \"Restaurant\"]:\n",
" system_action[(domain, 'Recommend')].append(['Name', choice['name']])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Podobnie jak w przypadku aktów użytkownika akty systemowe przekazywane do modułu NLG są czteroelementowymi listami złożonymi z:\n",
"\n",
" - nazwy aktu systemowe,\n",
" - nazwy dziedziny, której dotyczy wypowiedź,\n",
" - nazwy slotu,\n",
" - wartości slotu.\n",
"\n",
"Sprawdźmy jakie akty systemowe zwraca taktyka `SimpleRulePolicy` w odpowiedzi na zmieniający się stan dialogu."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"from convlab2.dialog_agent import PipelineAgent\n",
"dst.init_session()\n",
"policy = SimpleRulePolicy()\n",
"agent = PipelineAgent(nlu=None, dst=dst, policy=policy, nlg=None, name='sys')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response([['Inform', 'Hotel', 'Price', 'cheap'], ['Inform', 'Hotel', 'Parking', 'yes']])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response([['Inform', 'Hotel', 'Area', 'north']])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response([['Request', 'Hotel', 'Area', '?']])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response([['Inform', 'Hotel', 'Day', 'tuesday'], ['Inform', 'Hotel', 'People', '2'], ['Inform', 'Hotel', 'Stay', '4']])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Testy End-to-End\n",
"\n",
"Na koniec przeprowadźmy dialog łącząc w potok nasze moduły\n",
"z modułami NLU i NLG dostępnymi dla MultiWOZ w środowisku `ConvLab-2`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"from convlab2.nlu.svm.multiwoz import SVMNLU\n",
"from convlab2.nlg.template.multiwoz import TemplateNLG\n",
"\n",
"nlu = SVMNLU()\n",
"nlg = TemplateNLG(is_user=False)\n",
"agent = PipelineAgent(nlu=nlu, dst=dst, policy=policy, nlg=nlg, name='sys')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response(\"I need a cheap hotel with free parking .\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response(\"Where it is located ?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response(\"I would prefer the hotel be in the north part of town .\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"source": [
"agent.response(\"Yeah , could you book me a room for 2 people for 4 nights starting Tuesday ?\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zauważmy, ze nasza prosta taktyka dialogowa zawiera wiele luk, do których należą m.in.:\n",
"\n",
" 1. Niezdolność do udzielenia odpowiedzi na przywitanie, prośbę o pomoc lub restart.\n",
"\n",
" 2. Brak reguł dopytujących użytkownika o szczegóły niezbędne do dokonania rezerwacji takie, jak długość pobytu czy liczba osób.\n",
"\n",
"Bardziej zaawansowane moduły zarządzania dialogiem zbudowane z wykorzystaniem reguł można znaleźć w\n",
"środowisku `ConvLab-2`. Należą do nich m.in. monitor [RuleDST](https://github.com/thu-coai/ConvLab-2/blob/master/convlab2/dst/rule/multiwoz/dst.py) oraz taktyka [RuleBasedMultiwozBot](https://github.com/thu-coai/ConvLab-2/blob/master/convlab2/policy/rule/multiwoz/rule_based_multiwoz_bot.py).\n",
"\n",
"Zadania\n",
"-------\n",
" 1. Zaimplementować w projekcie monitor stanu dialogu.\n",
"\n",
" 2. Zaimplementować w projekcie taktykę prowadzenia dialogu.\n",
"\n",
"Termin: 24.05.2021, godz. 23:59.\n",
"\n",
"Literatura\n",
"----------\n",
" 1. Pawel Budzianowski, Tsung-Hsien Wen, Bo-Hsiang Tseng, Iñigo Casanueva, Stefan Ultes, Osman Ramadan, Milica Gasic, MultiWOZ - A Large-Scale Multi-Domain Wizard-of-Oz Dataset for Task-Oriented Dialogue Modelling. EMNLP 2018, pp. 5016-5026\n",
" 2. Cathy Pearl, Basic principles for designing voice user interfaces, https://www.oreilly.com/content/basic-principles-for-designing-voice-user-interfaces/ data dostępu: 21 marca 2021\n",
" 3. Cathy Pearl, Designing Voice User Interfaces, Excerpts from Chapter 5: Advanced Voice User Interface Design, https://www.uxmatters.com/mt/archives/2018/01/designing-voice-user-interfaces.php data dostępu: 21 marca 2021"
]
}
],
"metadata": {
"author": "Marek Kubis",
"email": "mkubis@amu.edu.pl",
"interpreter": {
"hash": "91e2b0d1baa6ebb76863bdb1d11380bf032a6a1fc1b919194f041a5133852891"
},
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "Python 3.7.9 ('venv': venv)",
"language": "python",
"name": "python3"
},
"lang": "pl",
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
},
"subtitle": "9.Zarządzanie dialogiem z wykorzystaniem reguł[laboratoria]",
"title": "Systemy Dialogowe",
"year": "2021"
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@ -95,7 +95,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
@ -103,27 +103,43 @@
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': '',\n",
" 'date': '',\n",
" 'time': '',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'belief_state': {'police': {'book': {'booked': []}, 'semi': {}},\n",
" 'hotel': {'book': {'booked': [], 'people': '', 'day': '', 'stay': ''},\n",
" 'semi': {'name': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'parking': '',\n",
" 'pricerange': '',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}},\n",
" 'attraction': {'book': {'booked': []},\n",
" 'semi': {'type': '', 'name': '', 'area': ''}},\n",
" 'restaurant': {'book': {'booked': [], 'people': '', 'day': '', 'time': ''},\n",
" 'semi': {'food': '', 'pricerange': '', 'name': '', 'area': ''}},\n",
" 'hospital': {'book': {'booked': []}, 'semi': {'department': ''}},\n",
" 'taxi': {'book': {'booked': []},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'departure': '',\n",
" 'arriveBy': ''}},\n",
" 'train': {'book': {'booked': [], 'people': ''},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'day': '',\n",
" 'arriveBy': '',\n",
" 'departure': ''}}},\n",
" 'request_state': {},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# from convlab2.util.multiwoz.state import default_state\n",
"from utils.state import default_state\n",
"from convlab2.util.multiwoz.state import default_state\n",
"default_state()"
]
},
@ -141,20 +157,9 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\nclass SimpleRuleDST(DST):\\n def __init__(self):\\n DST.__init__(self)\\n self.state = default_state()\\n self.value_dict = json.load(open('l08/ConvLab-2/data/multiwoz/value_dict.json'))\\n\\n def update(self, user_act=None):\\n for intent, domain, slot, value in user_act:\\n domain = domain.lower()\\n intent = intent.lower()\\n\\n if domain in ['unk', 'general', 'booking']:\\n continue\\n\\n if intent == 'inform':\\n k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\\n\\n if k is None:\\n continue\\n\\n domain_dic = self.state['belief_state'][domain]\\n\\n if k in domain_dic['semi']:\\n nvalue = normalize_value(self.value_dict, domain, k, value)\\n self.state['belief_state'][domain]['semi'][k] = nvalue\\n elif k in domain_dic['book']:\\n self.state['belief_state'][domain]['book'][k] = value\\n elif k.lower() in domain_dic['book']:\\n self.state['belief_state'][domain]['book'][k.lower()] = value\\n elif intent == 'request':\\n k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\\n\\n if domain not in self.state['request_state']:\\n self.state['request_state'][domain] = {}\\n if k not in self.state['request_state'][domain]:\\n self.state['request_state'][domain][k] = 0\\n\\n return self.state\\n\\n def init_session(self):\\n self.state = default_state()\\n\""
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import json\n",
"import os\n",
@ -162,55 +167,12 @@
"from convlab2.dst.rule.multiwoz.dst_util import normalize_value\n",
"from convlab2.util.multiwoz.multiwoz_slot_trans import REF_SYS_DA\n",
"\n",
"\n",
"class SimpleRuleDST(DST):\n",
" def __init__(self):\n",
" DST.__init__(self)\n",
" self.state = default_state()\n",
" self.value_dict = json.load(open('utils/value_dict.json'))\n",
"\n",
" def update(self, user_act=None):\n",
" for intent, domain, slot, value in user_act:\n",
" domain = domain.lower()\n",
" intent = intent.lower()\n",
" value = value.lower()\n",
"\n",
" # if domain in ['unk', 'cinema']:\n",
" # continue\n",
" k = slot\n",
"\n",
" if intent == 'inform':\n",
" # k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
" # if k is None:\n",
" # continue\n",
"\n",
" domain_dic = self.state['belief_state'][domain]\n",
"\n",
" if k in domain_dic['semi']:\n",
" # nvalue = normalize_value(self.value_dict, domain, k, value)\n",
" self.state['belief_state'][domain]['semi'][k] = value\n",
" elif k in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k] = value\n",
" elif k.lower() in domain_dic['book']:\n",
" self.state['belief_state'][domain]['book'][k.lower()] = value\n",
" elif intent == 'request':\n",
" # k = REF_SYS_DA[domain.capitalize()].get(slot, slot)\n",
"\n",
" if domain not in self.state['request_state']:\n",
" self.state['request_state'][domain] = {}\n",
" if k not in self.state['request_state'][domain]:\n",
" self.state['request_state'][domain][k] = 0\n",
"\n",
" return self.state\n",
"\n",
" def init_session(self):\n",
" self.state = default_state()\n",
"\n",
"'''\n",
"class SimpleRuleDST(DST):\n",
" def __init__(self):\n",
" DST.__init__(self)\n",
" self.state = default_state()\n",
" self.value_dict = json.load(open('l08/ConvLab-2/data/multiwoz/value_dict.json'))\n",
" self.value_dict = json.load(open('ConvLab-2/data/multiwoz/value_dict.json'))\n",
"\n",
" def update(self, user_act=None):\n",
" for intent, domain, slot, value in user_act:\n",
@ -246,8 +208,7 @@
" return self.state\n",
"\n",
" def init_session(self):\n",
" self.state = default_state()\n",
"'''\n"
" self.state = default_state()\n"
]
},
{
@ -268,7 +229,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 3,
"metadata": {
"lines_to_next_cell": 0
},
@ -278,20 +239,37 @@
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': '',\n",
" 'date': '',\n",
" 'time': '',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'belief_state': {'police': {'book': {'booked': []}, 'semi': {}},\n",
" 'hotel': {'book': {'booked': [], 'people': '', 'day': '', 'stay': ''},\n",
" 'semi': {'name': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'parking': '',\n",
" 'pricerange': '',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}},\n",
" 'attraction': {'book': {'booked': []},\n",
" 'semi': {'type': '', 'name': '', 'area': ''}},\n",
" 'restaurant': {'book': {'booked': [], 'people': '', 'day': '', 'time': ''},\n",
" 'semi': {'food': '', 'pricerange': '', 'name': '', 'area': ''}},\n",
" 'hospital': {'book': {'booked': []}, 'semi': {'department': ''}},\n",
" 'taxi': {'book': {'booked': []},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'departure': '',\n",
" 'arriveBy': ''}},\n",
" 'train': {'book': {'booked': [], 'people': ''},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'day': '',\n",
" 'arriveBy': '',\n",
" 'departure': ''}}},\n",
" 'request_state': {},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 35,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -303,7 +281,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 4,
"metadata": {
"lines_to_next_cell": 0
},
@ -311,29 +289,29 @@
{
"data": {
"text/plain": [
"{'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
"{'book': {'booked': [], 'people': '', 'day': '', 'stay': ''},\n",
" 'semi': {'name': '',\n",
" 'area': '',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}"
" 'parking': 'yes',\n",
" 'pricerange': 'cheap',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}}"
]
},
"execution_count": 36,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Inform', 'Cinema', 'time', '15:00'], ['Inform', 'Cinema', 'title', 'Batman']])\n",
"dst.state['belief_state']['cinema']"
"dst.update([['Inform', 'Hotel', 'Price', 'cheap'], ['Inform', 'Hotel', 'Parking', 'yes']])\n",
"dst.state['belief_state']['hotel']"
]
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 5,
"metadata": {
"lines_to_next_cell": 0
},
@ -341,29 +319,29 @@
{
"data": {
"text/plain": [
"{'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': 'na górze na środku',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}"
"{'book': {'booked': [], 'people': '', 'day': '', 'stay': ''},\n",
" 'semi': {'name': '',\n",
" 'area': 'north',\n",
" 'parking': 'yes',\n",
" 'pricerange': 'cheap',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}}"
]
},
"execution_count": 37,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Inform', 'Cinema', 'area', 'na górze na środku']])\n",
"dst.state['belief_state']['cinema']"
"dst.update([['Inform', 'Hotel', 'Area', 'north']])\n",
"dst.state['belief_state']['hotel']"
]
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 6,
"metadata": {
"lines_to_next_cell": 0
},
@ -371,45 +349,42 @@
{
"data": {
"text/plain": [
"{'cinema': {'date': 0}}"
"{'hotel': {'area': 0}}"
]
},
"execution_count": 38,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dst.update([['Request', 'Cinema', 'date', '?']])\n",
"dst.update([['Request', 'Hotel', 'Area', '?']])\n",
"dst.state['request_state']"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
"data": {
"text/plain": [
"{'book': {'booked': [], 'people': '2', 'day': 'tuesday', 'stay': '4'},\n",
" 'semi': {'name': '',\n",
" 'area': 'north',\n",
" 'parking': 'yes',\n",
" 'pricerange': 'cheap',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -419,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@ -427,20 +402,40 @@
"text/plain": [
"{'user_action': [],\n",
" 'system_action': [],\n",
" 'belief_state': {'cinema': {'book': {'title': 'batman',\n",
" 'date': '',\n",
" 'time': '15:00',\n",
" 'quantity': '',\n",
" 'seats': '',\n",
" 'area': 'na górze na środku',\n",
" 'interval': ''},\n",
" 'semi': {'goal': ''}}},\n",
" 'request_state': {'cinema': {'date': 0}},\n",
" 'belief_state': {'police': {'book': {'booked': []}, 'semi': {}},\n",
" 'hotel': {'book': {'booked': [],\n",
" 'people': '2',\n",
" 'day': 'tuesday',\n",
" 'stay': '4'},\n",
" 'semi': {'name': '',\n",
" 'area': 'north',\n",
" 'parking': 'yes',\n",
" 'pricerange': 'cheap',\n",
" 'stars': '',\n",
" 'internet': '',\n",
" 'type': ''}},\n",
" 'attraction': {'book': {'booked': []},\n",
" 'semi': {'type': '', 'name': '', 'area': ''}},\n",
" 'restaurant': {'book': {'booked': [], 'people': '', 'day': '', 'time': ''},\n",
" 'semi': {'food': '', 'pricerange': '', 'name': '', 'area': ''}},\n",
" 'hospital': {'book': {'booked': []}, 'semi': {'department': ''}},\n",
" 'taxi': {'book': {'booked': []},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'departure': '',\n",
" 'arriveBy': ''}},\n",
" 'train': {'book': {'booked': [], 'people': ''},\n",
" 'semi': {'leaveAt': '',\n",
" 'destination': '',\n",
" 'day': '',\n",
" 'arriveBy': '',\n",
" 'departure': ''}}},\n",
" 'request_state': {'hotel': {'area': 0}},\n",
" 'terminated': False,\n",
" 'history': []}"
]
},
"execution_count": 39,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@ -471,30 +466,9 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import copy\n",
@ -575,32 +549,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"outputs": [],
"source": [
"from convlab2.dialog_agent import PipelineAgent\n",
"dst.init_session()\n",
@ -610,30 +563,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
"data": {
"text/plain": [
"[['Inform', 'Hotel', 'Choice', '10'],\n",
" ['Recommend', 'Hotel', 'Name', 'alexander bed and breakfast']]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -642,30 +586,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
"data": {
"text/plain": [
"[['Inform', 'Hotel', 'Choice', '2'],\n",
" ['Recommend', 'Hotel', 'Name', 'city centre north b and b']]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -674,30 +609,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
"data": {
"text/plain": [
"[['Inform', 'Hotel', 'Area', 'north']]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -706,28 +631,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
"data": {
"text/plain": [
"[['Book', 'Booking', 'Ref', '00000013']]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -746,27 +661,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
"name": "stdout",
"output_type": "stream",
"text": [
"[<convlab2.nlu.svm.Features.nbest object at 0x0000028BDD2032C8>]\n",
"loading saved Classifier\n",
"loaded.\n"
]
}
],
@ -781,29 +685,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"ename": "AttributeError",
"evalue": "'SVC' object has no attribute '_impl'",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_13500\\3260802613.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0magent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"I need a cheap hotel with free parking .\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\dialog_agent\\agent.py\u001b[0m in \u001b[0;36mresponse\u001b[1;34m(self, observation)\u001b[0m\n\u001b[0;32m 120\u001b[0m \u001b[1;31m# get dialog act\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 122\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobservation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhistory\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 123\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobservation\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\multiwoz\\nlu.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, utterance, context)\u001b[0m\n\u001b[0;32m 74\u001b[0m ]\n\u001b[0;32m 75\u001b[0m }\n\u001b[1;32m---> 76\u001b[1;33m \u001b[0mslu_hyps\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode_sent\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"decode\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"output\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 77\u001b[0m \u001b[0mact_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 78\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mhyp\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mslu_hyps\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode_sent\u001b[1;34m(self, sentinfo, output_fname, config)\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 321\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextractFeatures2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 322\u001b[1;33m \u001b[0mdecode_results\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 323\u001b[0m \u001b[0mcounter\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdefaultdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 324\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[0mbaseXs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mindex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseX_pointers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 259\u001b[0m \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtoSparse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdictionary\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 260\u001b[1;33m \u001b[0mresults\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclassifiers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 261\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 262\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 496\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 497\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 498\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 499\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 500\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36mpredict_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 588\u001b[0m \u001b[0mdatasets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 589\u001b[0m \"\"\"\n\u001b[1;32m--> 590\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_check_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 591\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_predict_proba\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 592\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36m_check_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 557\u001b[0m raise AttributeError(\"predict_proba is not available when \"\n\u001b[0;32m 558\u001b[0m \" probability=False\")\n\u001b[1;32m--> 559\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_impl\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'c_svc'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'nu_svc'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 560\u001b[0m raise AttributeError(\"predict_proba only implemented for SVC\"\n\u001b[0;32m 561\u001b[0m \" and NuSVC\")\n",
"\u001b[1;31mAttributeError\u001b[0m: 'SVC' object has no attribute '_impl'"
]
}
],
@ -813,29 +715,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"ename": "AttributeError",
"evalue": "'SVC' object has no attribute '_impl'",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_13500\\2723043776.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0magent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Where it is located ?\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\dialog_agent\\agent.py\u001b[0m in \u001b[0;36mresponse\u001b[1;34m(self, observation)\u001b[0m\n\u001b[0;32m 120\u001b[0m \u001b[1;31m# get dialog act\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 122\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobservation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhistory\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 123\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobservation\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\multiwoz\\nlu.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, utterance, context)\u001b[0m\n\u001b[0;32m 74\u001b[0m ]\n\u001b[0;32m 75\u001b[0m }\n\u001b[1;32m---> 76\u001b[1;33m \u001b[0mslu_hyps\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode_sent\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"decode\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"output\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 77\u001b[0m \u001b[0mact_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 78\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mhyp\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mslu_hyps\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode_sent\u001b[1;34m(self, sentinfo, output_fname, config)\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 321\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextractFeatures2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 322\u001b[1;33m \u001b[0mdecode_results\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 323\u001b[0m \u001b[0mcounter\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdefaultdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 324\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[0mbaseXs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mindex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseX_pointers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 259\u001b[0m \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtoSparse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdictionary\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 260\u001b[1;33m \u001b[0mresults\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclassifiers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 261\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 262\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 496\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 497\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 498\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 499\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 500\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36mpredict_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 588\u001b[0m \u001b[0mdatasets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 589\u001b[0m \"\"\"\n\u001b[1;32m--> 590\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_check_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 591\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_predict_proba\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 592\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36m_check_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 557\u001b[0m raise AttributeError(\"predict_proba is not available when \"\n\u001b[0;32m 558\u001b[0m \" probability=False\")\n\u001b[1;32m--> 559\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_impl\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'c_svc'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'nu_svc'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 560\u001b[0m raise AttributeError(\"predict_proba only implemented for SVC\"\n\u001b[0;32m 561\u001b[0m \" and NuSVC\")\n",
"\u001b[1;31mAttributeError\u001b[0m: 'SVC' object has no attribute '_impl'"
]
}
],
@ -845,29 +745,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"ename": "",
"evalue": "",
"ename": "AttributeError",
"evalue": "'SVC' object has no attribute '_impl'",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_13500\\871593950.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0magent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"I would prefer the hotel be in the north part of town .\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\dialog_agent\\agent.py\u001b[0m in \u001b[0;36mresponse\u001b[1;34m(self, observation)\u001b[0m\n\u001b[0;32m 120\u001b[0m \u001b[1;31m# get dialog act\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 122\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlu\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobservation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhistory\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 123\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 124\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minput_action\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobservation\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\multiwoz\\nlu.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, utterance, context)\u001b[0m\n\u001b[0;32m 74\u001b[0m ]\n\u001b[0;32m 75\u001b[0m }\n\u001b[1;32m---> 76\u001b[1;33m \u001b[0mslu_hyps\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode_sent\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"decode\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"output\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 77\u001b[0m \u001b[0mact_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 78\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mhyp\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mslu_hyps\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode_sent\u001b[1;34m(self, sentinfo, output_fname, config)\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 321\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextractFeatures2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msentinfo\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlog_input_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 322\u001b[1;33m \u001b[0mdecode_results\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 323\u001b[0m \u001b[0mcounter\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdefaultdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 324\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[0mbaseXs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mindex\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbaseX_pointers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 259\u001b[0m \u001b[0mX\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtoSparse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbaseXs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdictionary\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 260\u001b[1;33m \u001b[0mresults\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclassifiers\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mthis_tuple\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 261\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresults\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 262\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\develop\\wmi\\aitech\\sem1\\systemy dialogowe\\lab\\convlab-2\\convlab2\\nlu\\svm\\Classifier.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 496\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 497\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 498\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 499\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 500\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36mpredict_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 588\u001b[0m \u001b[0mdatasets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 589\u001b[0m \"\"\"\n\u001b[1;32m--> 590\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_check_proba\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 591\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_predict_proba\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 592\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Develop\\wmi\\AITECH\\sem1\\Systemy dialogowe\\lab\\venv\\lib\\site-packages\\sklearn\\svm\\base.py\u001b[0m in \u001b[0;36m_check_proba\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 557\u001b[0m raise AttributeError(\"predict_proba is not available when \"\n\u001b[0;32m 558\u001b[0m \" probability=False\")\n\u001b[1;32m--> 559\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_impl\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'c_svc'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'nu_svc'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 560\u001b[0m raise AttributeError(\"predict_proba only implemented for SVC\"\n\u001b[0;32m 561\u001b[0m \" and NuSVC\")\n",
"\u001b[1;31mAttributeError\u001b[0m: 'SVC' object has no attribute '_impl'"
]
}
],
@ -879,28 +777,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.6.15 ('sysdial')' requires ipykernel package.\n",
"Run the following command to install 'ipykernel' into the Python environment. \n",
"Command: 'conda install -n sysdial ipykernel --update-deps --force-reinstall'"
]
}
],
"outputs": [],
"source": [
"agent.response(\"Yeah , could you book me a room for 2 people for 4 nights starting Tuesday ?\")"
]

View File

@ -1,11 +1,31 @@
# Martyna
from urllib import request
class DP:
def __init__(self, slots):
self.slots = slots
def getAct(slots):
# iterate over slots
# find empty
# returns system act
def __init__(self):
pass
def getAction(self, lastUserAct, emptySlots, systemSlots):
systemAct = None
slotVal = None
if ((lastUserAct == "hello") | (lastUserAct == "inform") | (lastUserAct == None)):
# there are no empty slots
if not emptySlots:
systemAct = "inform"
slotVal = systemSlots
# there are empty slots
else:
for slot in systemSlots:
if slot in emptySlots:
systemAct = "request"
slotVal = slot
break
return ["Cinema", systemAct, slotVal, ""]
elif (lastUserAct == "request"):
# todo policy for user request
return ["Cinema", "", "", ""]
else:
systemAct = "repeat"
return ["Cinema", systemAct, "", ""]

View File

@ -5,11 +5,14 @@ class DST:
# self.value_dict = json.load(open('utils/value_dict.json'))
def update(self, user_act=None):
intentVal = None
for intent, domain, slot, value in user_act:
domain = domain.lower()
intent = intent.lower()
value = value.lower()
if intentVal is None : intentVal = intent
k = slot
if intent == 'inform':
@ -22,15 +25,38 @@ class DST:
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 == 'request':
elif intent == 'reqmore':
if domain not in self.state['request_state']:
self.state['request_state'][domain] = {}
if k not in self.state['request_state'][domain]:
self.state['request_state'][domain][k] = 0
self.state['user_action'].append(intentVal)
return self.state
def addSystemAct(self, act):
self.state["system_action"].append(act)
def getLastUserAct(self):
try:
return self.state["user_action"][-1]
except:
return None
def getEmptySlots(self):
result = []
for key in self.state['belief_state']["cinema"]["book"].keys():
if self.state['belief_state']["cinema"]["book"][key] == "":
result.append(key)
return result
def getSystemSlots(self):
result = []
for key in self.state['belief_state']["cinema"]["book"].keys():
if key != "interval":
result.append(key)
return result
def init_session(self):
self.state = self.default_state()

View File

@ -1,6 +1,7 @@
from components.NLU import NLU
from components.NLG import NLG
from components.DST import DST
from components.DP import DP
def chatbot():
@ -9,6 +10,7 @@ def chatbot():
# NLU
nlu = NLU()
dst = DST()
dp = DP()
# hello message
print("wpisz /exit aby zakończyć")
@ -22,6 +24,10 @@ def chatbot():
isActive = False
else:
nluPred = nlu.predict(sentence=userMessage)
# print(nluPred)
dst.update(nluPred)
print(dst.state)
# print(dst.state)
dpAct = dp.getAction(dst.getLastUserAct(), dst.getEmptySlots(), dst.getSystemSlots())
print(dpAct)
# todo update DST system act
chatbot()