Add mockups
This commit is contained in:
parent
363e2ebca3
commit
3d9908b9ec
237
SDMockup.ipynb
237
SDMockup.ipynb
@ -10,7 +10,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -29,50 +29,255 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Nlu:\n",
|
||||
"class NaturalLanguageUnderstanding:\n",
|
||||
" acts: dict[list[str], str] = {\n",
|
||||
" ( \"potwierdzam\", \"dobrze\", \"ok\" ): \"ack\",\n",
|
||||
" (\"do widziena\", \"czesc\", \"koniec\", \"do zobaczenia\"): \"bye\",\n",
|
||||
" (\"cześć\", \"dzień dobry\", \"hello\", \"hej\"): \"hello\",\n",
|
||||
" (\"pomóc\", \"pomocy\", \"pomoc\"): \"help\",\n",
|
||||
" (\"zaprzeczam\", \"odrzucam\"): \"negate\",\n",
|
||||
" (\"alternatywny\", \"inne\", \"alternatywa\", \"inna\"): \"requalts\",\n",
|
||||
" (\"szczegółów\", \"informacji\", \"info\", \"informacje\"): \"reqmore\",\n",
|
||||
" (\"restart\"): \"restart\",\n",
|
||||
" (\"dziękuję\", \"dzięki\"): \"thankyou\",\n",
|
||||
" (\"tak\", \"chcę\"): \"confirm\",\n",
|
||||
" (\"nie chce\"): \"deny\",\n",
|
||||
" (\"basen\", \"parking\", \"śniadania\", \"osoby\"): \"inform\",\n",
|
||||
" (\"jaki\",\"?\", \"czy\", \"jak\", \"ile\", \"co\", \"gdzie\"): \"request\"\n",
|
||||
" }\n",
|
||||
" def __init__(self, text: str):\n",
|
||||
" self.text = text\n",
|
||||
" self.slot = []\n",
|
||||
" self.act = \"\"\n",
|
||||
" \n",
|
||||
" def get_dialog_act(self):\n",
|
||||
" act = \"question\" if \"?\" in self.text else \"\"\n",
|
||||
" if \"imię\" in self.text:\n",
|
||||
" self.slot.append((\"o_co\", \"imie\"))\n",
|
||||
" return {\"act\": act, \"slot\": self.slot }\n",
|
||||
" \n",
|
||||
" def get_dialog_act(self): \n",
|
||||
" for word in self.text.lower().split():\n",
|
||||
" for key in NaturalLanguageUnderstanding.acts:\n",
|
||||
" if word in key:\n",
|
||||
" self.act = NaturalLanguageUnderstanding.acts[key]\n",
|
||||
" return\n",
|
||||
" self.act = \"null\"\n",
|
||||
" \n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'act': 'question', 'slot': [('o_co', 'imie')]}"
|
||||
"'request'"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"nlu = Nlu(\"Jak masz na imię?\")\n",
|
||||
"nlu.get_dialog_act()"
|
||||
"nlu = NaturalLanguageUnderstanding(\"Jaki pokój proponujesz w tym hotelu?\")\n",
|
||||
"nlu.get_dialog_act()\n",
|
||||
"nlu.act"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# DST"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 53,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"class DialogueStateTracker:\n",
|
||||
" \n",
|
||||
" slots_dict: dict[tuple[str], str] = {\n",
|
||||
" (\"osoby\", \"ludzie\", \"osób\", \"osobowy\"): \"people\",\n",
|
||||
" (\"miasto\", \"miasta\", \"miejsowość\", \"poznań\", \"warszawa\", \"warszawie\", \"poznaniu\", \"kraków\", \"krakowie\"): \"city\",\n",
|
||||
" (\"basen\", \"parking\", \"śniadania\"): \"facilities\",\n",
|
||||
" (\"data\", \"datę\"): \"date\",\n",
|
||||
" (\"pokój\", \"pokoje\"): \"room\"\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" def __init__(self, nlu: NaturalLanguageUnderstanding):\n",
|
||||
" self.slots = []\n",
|
||||
" self.act = nlu.act\n",
|
||||
" self.text = nlu.text\n",
|
||||
" \n",
|
||||
" def get_dialog_slots(self):\n",
|
||||
" for word in self.text.lower().split():\n",
|
||||
" for key in DialogueStateTracker.slots_dict:\n",
|
||||
" if word in key:\n",
|
||||
" self.slots.append(DialogueStateTracker.slots_dict[key])\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['room']"
|
||||
]
|
||||
},
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dst: DialogueStateTracker = DialogueStateTracker(nlu)\n",
|
||||
"dst.get_dialog_slots()\n",
|
||||
"dst.slots\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Dialogue Policy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class DialoguePolicy:\n",
|
||||
" user_act_to_system_act_dict: dict[str, str] = {\n",
|
||||
" \"ack\": \"reqmore\",\n",
|
||||
" \"bye\": \"bye\",\n",
|
||||
" \"hello\": \"welcomemsg\",\n",
|
||||
" \"help\": \"inform\",\n",
|
||||
" \"negate\": \"offer\",\n",
|
||||
" \"requalts\": \"offer\",\n",
|
||||
" \"reqmore\": \"inform\",\n",
|
||||
" \"restart\": \"welcomemsg\",\n",
|
||||
" \"thankyou\": \"reqmore\",\n",
|
||||
" \"confirm\": \"reqmore\",\n",
|
||||
" \"deny\": \"offer\",\n",
|
||||
" \"inform\": \"offer\",\n",
|
||||
" \"request\": \"inform\",\n",
|
||||
" \"null\": \"null\"\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" def __init__(self, dst: DialogueStateTracker):\n",
|
||||
" self.user_text = dst.text\n",
|
||||
" self.user_act = dst.act\n",
|
||||
" self.user_slots = dst.slots\n",
|
||||
" self.system_act = \"\"\n",
|
||||
" \n",
|
||||
" def get_system_act(self):\n",
|
||||
" self.system_act = DialoguePolicy.user_act_to_system_act_dict[self.user_act]\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'inform'"
|
||||
]
|
||||
},
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dp: DialoguePolicy = DialoguePolicy(dst)\n",
|
||||
"dp.get_system_act()\n",
|
||||
"dp.system_act"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# NLG"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 57,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class NaturalLanguageGeneration:\n",
|
||||
" system_act_to_text = {\n",
|
||||
" \"reqmore\": \"Informuje więcej o \",\n",
|
||||
" \"bye\": \"Do widzenia\",\n",
|
||||
" \"welcomemsg\": \"Witaj w systemie rezerwacji hotelowych. W czym mogę pomóc?\",\n",
|
||||
" \"inform\": \"Informuje cię o \",\n",
|
||||
" \"offer\": \"Co myślisz o hotlu z \",\n",
|
||||
" \"reqmore\": \"Czy mogę jeszcze jakoś Ci pomóc?\",\n",
|
||||
" \"null\": \"\"\n",
|
||||
" }\n",
|
||||
" user_slots_to_text = {\n",
|
||||
" \"people\": \"pojemności pokoju\",\n",
|
||||
" \"city\": \"mieście\",\n",
|
||||
" \"facilities\": \"udogodnieniach\",\n",
|
||||
" \"date\": \"dacie\",\n",
|
||||
" \"room\": \"pokoju\"\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" def __init__(self, dp: DialoguePolicy):\n",
|
||||
" self.user_text = dp.user_text\n",
|
||||
" self.user_act = dp.user_act\n",
|
||||
" self.user_slots = dp.user_slots\n",
|
||||
" self.system_act = dp.system_act\n",
|
||||
" self.system_text = \"\"\n",
|
||||
" \n",
|
||||
" def generate_system_text(self):\n",
|
||||
" text: str = NaturalLanguageGeneration.system_act_to_text[self.system_act]\n",
|
||||
" slots_transformed = [NaturalLanguageGeneration.user_slots_to_text[slot] for slot in self.user_slots]\n",
|
||||
" self.system_text = text + \" i \".join(slots_transformed)\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'Informuje cię o pokoju'"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"nlg: NaturalLanguageGeneration = NaturalLanguageGeneration(dp)\n",
|
||||
"nlg.generate_system_text()\n",
|
||||
"nlg.system_text"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
Loading…
Reference in New Issue
Block a user