Zmiana formatowania, dodano domyślne encodowanie, requirements z wersjami paczek

This commit is contained in:
Anna Nowak 2021-03-19 00:36:47 +01:00
parent c20eeebd19
commit 42b70150a4
6 changed files with 881 additions and 731 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.ipynb_checkpoints
.venv
.env

View File

@ -1,17 +1,4 @@
{ {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "DL_Chatbot_ver_1_0.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -33,30 +20,30 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "D7_8XDfpfH-X" "id": "D7_8XDfpfH-X"
}, },
"outputs": [],
"source": [ "source": [
"!pip install tflearn\r\n", "!pip install -r requirements.txt --user\n",
"!pip install tensorflow" "!pip list"
], ]
"execution_count": null,
"outputs": []
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "GOGs4hL6fwwK" "id": "GOGs4hL6fwwK"
}, },
"outputs": [],
"source": [ "source": [
"import numpy as np\r\n", "import numpy as np\n",
"import tflearn\r\n", "import tflearn\n",
"import tensorflow\r\n", "import tensorflow\n",
"import random\r\n", "import random\n",
"import json" "import json"
], ]
"execution_count": null,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -69,17 +56,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "jy4-9guXgBY3" "id": "jy4-9guXgBY3"
}, },
"outputs": [],
"source": [ "source": [
"import nltk\r\n", "import nltk\n",
"nltk.download('punkt')\r\n", "\n",
"from nltk.stem.lancaster import LancasterStemmer\r\n", "nltk.download('punkt')\n",
"from nltk.stem.lancaster import LancasterStemmer\n",
"stemmer_en = LancasterStemmer()" "stemmer_en = LancasterStemmer()"
], ]
"execution_count": null,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -92,27 +80,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"metadata": {
"id": "YgtIHwpKgBR4"
},
"source": [
"!pip install pystempel"
],
"execution_count": null, "execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": { "metadata": {
"id": "XBpvJXn1gBDi" "id": "XBpvJXn1gBDi"
}, },
"outputs": [],
"source": [ "source": [
"from stempel import StempelStemmer\r\n", "from stempel import StempelStemmer\n",
"\r\n", "\n",
"stemmer_pl = StempelStemmer.default() #może wersja \".polimorf()\" jest lepsza?" "stemmer_pl = StempelStemmer.default() #może wersja \".polimorf()\" jest lepsza?"
], ]
"execution_count": null,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -134,6 +111,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -141,21 +119,12 @@
"id": "jKsIW7hHhepB", "id": "jKsIW7hHhepB",
"outputId": "09ba1cb1-bb0e-44ee-9d28-017209902934" "outputId": "09ba1cb1-bb0e-44ee-9d28-017209902934"
}, },
"outputs": [],
"source": [ "source": [
"with open(\"intents_pl.json\") as file:\r\n", "with open(\"intents_pl.json\", encoding='utf-8') as file:\n",
" data_pl = json.load(file)\r\n", " data_pl = json.load(file)\n",
"\r\n", "\n",
"print(data_pl)" "print(data_pl)"
],
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"text": [
"{'intents': [{'tag': 'greeting', 'patterns': ['Cześć', 'Elo', 'Jesteś?', 'Hej', 'Dzień dobry', 'Sup'], 'responses': ['Cześć!', 'Dobrze Cię widzieć!', 'Hej, w czym mogę pomóc?'], 'context_set': ''}, {'tag': 'goodbye', 'patterns': ['narazie', 'Do zobaczenia', 'Dowidzenia', 'Dobranoc', 'Miłego dnia'], 'responses': ['Do zobaczenia później', 'Mam nadzieję, że później pogadamy', 'Narazie!'], 'context_set': ''}, {'tag': 'age', 'patterns': ['Ile masz lat', 'Ile lat ma Janet', 'Wiek', 'Jak stara jesteś', 'urodziny'], 'responses': ['Mam kilka dni', 'Urodziłam się 17.03.2021'], 'context_set': ''}, {'tag': 'name', 'patterns': ['Jak masz na imię', 'Jak Cię zwą?', 'twoje imie?', 'Imie', 'Jak cię nazywać', 'Kim jesteś'], 'responses': ['Możesz mnie nazywać Janet!', 'Jestem Janet', 'Jestem Janet, twój ulubiony chatbot'], 'context_set': ''}, {'tag': 'goout', 'patterns': ['Czy chcesz gdzieś wyjść?', 'zrobimy coś razem?', 'pójdziemy gdzieś razem?'], 'responses': ['Może kiedy indziej', 'Odezwę się latem'], 'context_set': ''}, {'tag': 'doing', 'patterns': ['Co robisz teraz?', 'co słychać', 'jakie masz plany?', 'jak się masz?'], 'responses': ['Gram w grę', 'Słucham muzyki', 'nie twój interes', 'nie mam czasu odpowiadać', ''], 'context_set': ''}, {'tag': 'game', 'patterns': ['a w co grasz?', 'a w co?', 'grasz?'], 'responses': ['nie interesuj się', 'a co cię to obchodzi', '...', 'w coś', 'W OSRS'], 'context_set': ''}, {'tag': 'music', 'patterns': ['czego?', 'czego słuchasz?', 'jakiej muzyki?'], 'responses': ['Starego vinyla z 1995 roku', 'mojego ulubionego setu rejwowego', 'czegoś tam...'], 'context_set': ''}, {'tag': 'angry', 'patterns': ['bo co?', 'dlaczego?', 'jak to?'], 'responses': ['Czas zakończyć rozmowę', 'nie mam na to siły i czasu', 'zostaw mnie w spokoju'], 'context_set': ''}, {'tag': 'why', 'patterns': ['o co chodzi?', 'czemu jesteś zła', 'poczekaj'], 'responses': ['...', 'Nie pisz do mnie więcej', 'Odezwę się latem'], 'context_set': ''}]}\n"
],
"name": "stdout"
}
] ]
}, },
{ {
@ -169,6 +138,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -176,21 +146,12 @@
"id": "gJbm_CtRhNOK", "id": "gJbm_CtRhNOK",
"outputId": "157196fc-6a25-4a70-aca3-9d886c743f6c" "outputId": "157196fc-6a25-4a70-aca3-9d886c743f6c"
}, },
"outputs": [],
"source": [ "source": [
"with open(\"intents_pl_short.json\") as file:\r\n", "with open(\"intents_pl_short.json\", encoding='utf-8') as file:\n",
" data_pl_short = json.load(file)\r\n", " data_pl_short = json.load(file)\n",
"\r\n", "\n",
"print(data_pl_short)" "print(data_pl_short)"
],
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"text": [
"{'intents': [{'tag': 'greeting', 'patterns': ['Cześć', 'Elo', 'Jesteś?', 'Hej', 'Dzień dobry', 'Sup'], 'responses': ['Cześć!', 'Dobrze Cię widzieć!', 'Hej, w czym mogę pomóc?'], 'context_set': ''}, {'tag': 'goodbye', 'patterns': ['narazie', 'Do zobaczenia', 'Dowidzenia', 'Dobranoc', 'Miłego dnia'], 'responses': ['Do zobaczenia później', 'Mam nadzieję, że później pogadamy', 'Narazie!'], 'context_set': ''}, {'tag': 'age', 'patterns': ['Ile masz lat', 'Ile lat ma Janet', 'Wiek', 'Jak stara jesteś', 'urodziny'], 'responses': ['Mam kilka dni', 'Urodziłam się 17.03.2021'], 'context_set': ''}, {'tag': 'name', 'patterns': ['Jak masz na imię', 'Jak Cię zwą?', 'twoje imie?', 'Imie', 'Jak cię nazywać', 'Kim jesteś'], 'responses': ['Możesz mnie nazywać Janet!', 'Jestem Janet', 'Jestem Janet, twój ulubiony chatbot'], 'context_set': ''}]}\n"
],
"name": "stdout"
}
] ]
}, },
{ {
@ -204,6 +165,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -211,21 +173,12 @@
"id": "vW5FyoRqhfIc", "id": "vW5FyoRqhfIc",
"outputId": "378d8894-9c9c-46be-ade1-b6491f095179" "outputId": "378d8894-9c9c-46be-ade1-b6491f095179"
}, },
"outputs": [],
"source": [ "source": [
"with open(\"intents_en.json\") as file:\r\n", "with open(\"intents_en.json\", encoding='utf-8') as file:\n",
" data_en = json.load(file)\r\n", " data_en = json.load(file)\n",
"\r\n", "\n",
"print(data_en)" "print(data_en)"
],
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"text": [
"{'intents': [{'tag': 'greeting', 'patterns': ['Hi', 'How are you', 'Is anyone there?', 'Hello', 'Good day', 'Whats up'], 'responses': ['Hello!', 'Good to see you again!', 'Hi there, how can I help?'], 'context_set': ''}, {'tag': 'goodbye', 'patterns': ['cya', 'See you later', 'Goodbye', 'I am Leaving', 'Have a Good day'], 'responses': ['Sad to see you go :(', 'Talk to you later', 'Goodbye!'], 'context_set': ''}, {'tag': 'age', 'patterns': ['how old', 'how old is tim', 'what is your age', 'how old are you', 'age?'], 'responses': ['I am 18 years old!', '18 years young!'], 'context_set': ''}, {'tag': 'name', 'patterns': ['what is your name', 'what should I call you', 'whats your name?'], 'responses': ['You can call me Tim.', \"I'm Tim!\", \"I'm Tim aka Tech With Tim.\"], 'context_set': ''}, {'tag': 'shop', 'patterns': ['Id like to buy something', 'whats on the menu', 'what do you reccommend?', 'could i get something to eat'], 'responses': ['We sell chocolate chip cookies for $2!', 'Cookies are on the menu!'], 'context_set': ''}, {'tag': 'hours', 'patterns': ['when are you guys open', 'what are your hours', 'hours of operation'], 'responses': ['We are open 7am-4pm Monday-Friday!'], 'context_set': ''}]}\n"
],
"name": "stdout"
}
] ]
}, },
{ {
@ -239,17 +192,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "gy6p55-DjLyY" "id": "gy6p55-DjLyY"
}, },
"outputs": [],
"source": [ "source": [
"words = []\r\n", "words = []\n",
"labels = []\r\n", "labels = []\n",
"docs_x = []\r\n", "docs_x = []\n",
"docs_y = []" "docs_y = []"
], ]
"execution_count": 12,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -262,41 +215,54 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "nBUKwSr_kVSd" "id": "nBUKwSr_kVSd"
}, },
"outputs": [],
"source": [ "source": [
"for intent in data_pl_short[\"intents\"]: #Loop przez cały json\r\n", "for intent in data_pl_short[\"intents\"]: #Loop przez cały json\n",
" for pattern in intent[\"patterns\"]: #loop przez wszystkie możliwe rodzaje przykładowego inputu użytkownika\r\n", " for pattern in intent[\"patterns\"]: #loop przez wszystkie możliwe rodzaje przykładowego inputu użytkownika\n",
" wrds = nltk.word_tokenize(pattern) #Tokenizing every word\r\n", " wrds = nltk.word_tokenize(pattern) #Tokenizing every word\n",
" words.extend(wrds) #Add every single tokenized word\r\n", " words.extend(wrds) #Add every single tokenized word\n",
" docs_x.append(wrds) #Add the whole tokenized sentence\r\n", " docs_x.append(wrds) #Add the whole tokenized sentence\n",
" docs_y.append(intent[\"tag\"]) #Pattern x coresponds to the tag y. Potrzebne do ustalenia relacji słowa z odpowiedzią\r\n", " docs_y.append(intent[\"tag\"]) #Pattern x coresponds to the tag y. Potrzebne do ustalenia relacji słowa z odpowiedzią\n",
"\r\n", "\n",
" if intent[\"tag\"] not in labels:\r\n", " if intent[\"tag\"] not in labels:\n",
" labels.append(intent[\"tag\"]) #Add the tag" " labels.append(intent[\"tag\"]) #Add the tag"
], ]
"execution_count": 13,
"outputs": []
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "wOyP5lbikV1e" "id": "wOyP5lbikV1e"
}, },
"outputs": [],
"source": [ "source": [
"words = [stemmer_pl.stem(w.lower()) for w in words if w not in \"?\"] #stemming -> take each word and bring it to the \"root\" form. Only the stemmed version of the word is important to us\r\n", "words = [stemmer_pl.stem(w.lower()) for w in words if w not in \"?\"] #stemming -> take each word and bring it to the \"root\" form. Only the stemmed version of the word is important to us\n",
"words = sorted(list(set(words))) #Sorting\r\n", "words = sorted(list(set(words))) #Sorting\n",
"\r\n", "\n",
"labels = sorted(labels) #sorting\r\n", "labels = sorted(labels) #sorting\n",
"\r\n", "\n",
"training = []\r\n", "training = []\n",
"output = []\r\n", "output = []\n",
"\r\n", "\n",
"out_empty = [0 for _ in range(len(labels))]" "out_empty = [0 for _ in range(len(labels))]"
], ]
"execution_count": 14, },
"outputs": [] {
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Podgląd zmiennych\n",
"print(f\"Words:\\n{words}\")\n",
"print(f\"labels:\\n{labels}\")\n",
"print(f\"docs_y:\\n{docs_y}\")\n",
"print(f\"docs_x:\\n{docs_x}\")"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -327,35 +293,36 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "8FDKrjpjkYsE" "id": "8FDKrjpjkYsE"
}, },
"outputs": [],
"source": [ "source": [
"for x, doc in enumerate(docs_x): #Przejście przez wszystkie słowa\r\n", "for x, doc in enumerate(docs_x): #Przejście przez wszystkie słowa\n",
" bag =[]\r\n", " bag =[]\n",
"\r\n", "\n",
" wrds = [stemmer_pl.stem(w) for w in doc] #podział wszystkich słów w danym zdaniu\r\n", " wrds = [stemmer_pl.stem(w) for w in doc] #podział wszystkich słów w danym zdaniu\n",
"\r\n", "\n",
" for w in words:\r\n", " for w in words:\n",
" if w in wrds:\r\n", " if w in wrds:\n",
" bag.append(1) #this word exist\r\n", " bag.append(1) #this word exist\n",
" else:\r\n", " else:\n",
" bag.append(0) #do not exist\r\n", " bag.append(0) #do not exist\n",
" \r\n", " \n",
" output_row = out_empty[:] #kopia\r\n", " output_row = out_empty[:] #kopia\n",
" output_row[labels.index(docs_y[x])] = 1\r\n", " output_row[labels.index(docs_y[x])] = 1\n",
"\r\n", "\n",
" training.append(bag) #dodajemy nowe wyrażenie zamienione na ciąg binarny\r\n", " training.append(bag) #dodajemy nowe wyrażenie zamienione na ciąg binarny\n",
" output.append(output_row)\r\n", " output.append(output_row)\n",
"\r\n", "\n",
"training = np.array(training) #Zbiór treningowy\r\n", "training = np.array(training) #Zbiór treningowy\n",
"output = np.array(output) #Zbiór outputów" "output = np.array(output) #Zbiór outputów"
], ]
"execution_count": 16,
"outputs": []
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -363,27 +330,14 @@
"id": "cJKUjbkC72-f", "id": "cJKUjbkC72-f",
"outputId": "7e2bff96-78ce-49ff-b27b-eee77752228d" "outputId": "7e2bff96-78ce-49ff-b27b-eee77752228d"
}, },
"outputs": [],
"source": [ "source": [
"len(training) #dla pl_short mamy 44 słowa" "len(training) #dla pl_short mamy 44 słowa"
],
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"44"
]
},
"metadata": {
"tags": []
},
"execution_count": 18
}
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -391,23 +345,19 @@
"id": "Kx43VDgS7-yN", "id": "Kx43VDgS7-yN",
"outputId": "4fa6f6fe-dc58-4e76-bb26-38c1784ab79c" "outputId": "4fa6f6fe-dc58-4e76-bb26-38c1784ab79c"
}, },
"outputs": [],
"source": [ "source": [
"len(output[0]) #Które można przypisać do 4 kategorii" "len(output[0]) #Które można przypisać do 4 kategorii"
],
"execution_count": 20,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"4"
] ]
}, },
"metadata": { {
"tags": [] "cell_type": "code",
}, "execution_count": null,
"execution_count": 20 "metadata": {},
} "outputs": [],
"source": [
"print(training)\n",
"print(output)"
] ]
}, },
{ {
@ -421,15 +371,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "MDA435sI1-Xl" "id": "MDA435sI1-Xl"
}, },
"outputs": [],
"source": [ "source": [
"training = np.array(training) #zamiana typu dla sieci neuronowej\r\n", "training = np.array(training) #zamiana typu dla sieci neuronowej\n",
"output = np.array(output) #zamiana typu dla sieci neuronowej" "output = np.array(output) #zamiana typu dla sieci neuronowej"
], ]
"execution_count": 22,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -442,6 +392,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -449,30 +400,19 @@
"id": "XaQJh1aG2hbj", "id": "XaQJh1aG2hbj",
"outputId": "80420df0-3a78-4583-9563-2165e968713d" "outputId": "80420df0-3a78-4583-9563-2165e968713d"
}, },
"outputs": [],
"source": [ "source": [
"tensorflow.compat.v1.reset_default_graph() #Reset na wszelki wypadek (w sumie nie wiem czy to jakaś super ważna linijka kodu)\r\n", "tensorflow.compat.v1.reset_default_graph() #Reset na wszelki wypadek (w sumie nie wiem czy to jakaś super ważna linijka kodu)\n",
"\r\n", "\n",
"net = tflearn.input_data(shape=[None, len(training[0])]) #Input layer\r\n", "net = tflearn.input_data(shape=[None, len(training[0])]) #Input layer\n",
"net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\r\n", "net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\n",
"net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\r\n", "net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\n",
"#net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\r\n", "#net = tflearn.fully_connected(net, 8) #8 neurons for hidden layer\n",
"net = tflearn.fully_connected(net, len(output[0]), activation=\"softmax\") #len(output) neurons for output layer + Softmax jako najlepsze wyjście dla tego typu danych\r\n", "net = tflearn.fully_connected(net, len(output[0]), activation=\"softmax\") #len(output) neurons for output layer + Softmax jako najlepsze wyjście dla tego typu danych\n",
"net = tflearn.regression(net)\r\n", "net = tflearn.regression(net)\n",
"\r\n", "\n",
"model = tflearn.DNN(net)\r\n", "model = tflearn.DNN(net)\n",
"\r\n" "\n"
],
"execution_count": 23,
"outputs": [
{
"output_type": "stream",
"text": [
"WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tflearn/initializations.py:165: calling TruncatedNormal.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Call initializer instance with the dtype argument instead of passing it to the constructor\n"
],
"name": "stdout"
}
] ]
}, },
{ {
@ -486,6 +426,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -493,25 +434,12 @@
"id": "REzkJL_r2hwl", "id": "REzkJL_r2hwl",
"outputId": "7ab2b0c5-944f-4e22-d478-1e35b41f87db" "outputId": "7ab2b0c5-944f-4e22-d478-1e35b41f87db"
}, },
"outputs": [],
"source": [ "source": [
"model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)\r\n", "model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)\n",
"\r\n", "\n",
"#Zapis Modelu\r\n", "#Zapis Modelu\n",
"#model.save(\"model.tflearn\")" "#model.save(\"model.tflearn\")"
],
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"text": [
"Training Step: 5999 | total loss: \u001b[1m\u001b[32m0.46985\u001b[0m\u001b[0m | time: 0.036s\n",
"| Adam | epoch: 1000 | loss: 0.46985 - acc: 0.7877 -- iter: 40/44\n",
"Training Step: 6000 | total loss: \u001b[1m\u001b[32m0.47602\u001b[0m\u001b[0m | time: 0.046s\n",
"| Adam | epoch: 1000 | loss: 0.47602 - acc: 0.7839 -- iter: 44/44\n",
"--\n"
],
"name": "stdout"
}
] ]
}, },
{ {
@ -534,24 +462,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "1IQyV1v33lC7" "id": "1IQyV1v33lC7"
}, },
"outputs": [],
"source": [ "source": [
"def bag_of_words(s, words):\r\n", "def bag_of_words(s, words):\n",
" bag = [0 for _ in range(len(words))]\r\n", " bag = [0 for _ in range(len(words))]\n",
"\r\n", "\n",
" s_words = nltk.word_tokenize(s)\r\n", " s_words = nltk.word_tokenize(s)\n",
" s_words = [stemmer_pl.stem(word.lower()) for word in s_words]\r\n", " s_words = [stemmer_pl.stem(word.lower()) for word in s_words]\n",
"\r\n", "\n",
" for se in s_words:\r\n", " for se in s_words:\n",
" for i, w in enumerate(words):\r\n", " for i, w in enumerate(words):\n",
" if w == se:\r\n", " if w == se:\n",
" bag[i] = 1\r\n", " bag[i] = 1\n",
" return np.array(bag)" " return np.array(bag)"
], ]
"execution_count": 26,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -564,29 +492,29 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"id": "Je6OSZ679-KL" "id": "Je6OSZ679-KL"
}, },
"outputs": [],
"source": [ "source": [
"def chat():\r\n", "def chat():\n",
" print(\"Możesz rozpocząć rozmowę z Botem! (type quit to stop)\")\r\n", " print(\"Możesz rozpocząć rozmowę z Botem! (type quit to stop)\")\n",
" while True: #Ciągła rozmowa\r\n", " while True: #Ciągła rozmowa\n",
" inp = input(\"Ty: \")\r\n", " inp = input(\"Ty: \")\n",
" if inp.lower() == \"quit\": #Quit by wyjść z loopa\r\n", " if inp.lower() == \"quit\": #Quit by wyjść z loopa\n",
" break\r\n", " break\n",
"\r\n", "\n",
" result = model.predict([bag_of_words(inp,words)]) #Predictowanie przy pomocy wyćwiczonego modelu\r\n", " result = model.predict([bag_of_words(inp,words)]) #Predictowanie przy pomocy wyćwiczonego modelu\n",
" result_index = np.argmax(result)\r\n", " result_index = np.argmax(result)\n",
" tag = labels[result_index]\r\n", " tag = labels[result_index]\n",
" \r\n", " \n",
" for tg in data_pl_short[\"intents\"]: #znalezienie poprawnego tagu do zdania\r\n", " for tg in data_pl_short[\"intents\"]: #znalezienie poprawnego tagu do zdania\n",
" if tg['tag'] == tag:\r\n", " if tg['tag'] == tag:\n",
" responses = tg['responses']\r\n", " responses = tg['responses']\n",
" \r\n", " \n",
" print(random.choice(responses)) #Wyprintuj losową odpowiedz z danego zbioru odpowiedzi" " print(random.choice(responses)) #Wyprintuj losową odpowiedz z danego zbioru odpowiedzi"
], ]
"execution_count": 32,
"outputs": []
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -599,6 +527,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -606,30 +535,36 @@
"id": "VZf_aCUM-Amm", "id": "VZf_aCUM-Amm",
"outputId": "9e3fcf7b-b9b3-47b0-acb5-48214f07f363" "outputId": "9e3fcf7b-b9b3-47b0-acb5-48214f07f363"
}, },
"outputs": [],
"source": [ "source": [
"chat()" "chat()"
],
"execution_count": 33,
"outputs": [
{
"output_type": "stream",
"text": [
"Możesz rozpocząć rozmowę z Botem! (type quit to stop)\n",
"Ty: hej\n",
"Dobrze Cię widzieć!\n",
"Ty: ile masz lat?\n",
"Mam kilka dni\n",
"Ty: Kim jesteś?\n",
"Dobrze Cię widzieć!\n",
"Ty: Jak masz na imię?\n",
"Jestem Janet, twój ulubiony chatbot\n",
"Ty: Miłego Dnia\n",
"Do zobaczenia później\n",
"Ty: quit\n"
],
"name": "stdout"
}
] ]
} }
] ],
"metadata": {
"colab": {
"name": "DL_Chatbot_ver_1_0.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
} }

View File

@ -1,32 +1,91 @@
{"intents": [ {
{"tag": "greeting", "intents": [
"patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day", "Whats up"], {
"responses": ["Hello!", "Good to see you again!", "Hi there, how can I help?"], "tag": "greeting",
"patterns": [
"Hi",
"How are you",
"Is anyone there?",
"Hello",
"Good day",
"Whats up"
],
"responses": [
"Hello!",
"Good to see you again!",
"Hi there, how can I help?"
],
"context_set": "" "context_set": ""
}, },
{"tag": "goodbye", {
"patterns": ["cya", "See you later", "Goodbye", "I am Leaving", "Have a Good day"], "tag": "goodbye",
"responses": ["Sad to see you go :(", "Talk to you later", "Goodbye!"], "patterns": [
"cya",
"See you later",
"Goodbye",
"I am Leaving",
"Have a Good day"
],
"responses": [
"Sad to see you go :(",
"Talk to you later",
"Goodbye!"
],
"context_set": "" "context_set": ""
}, },
{"tag": "age", {
"patterns": ["how old", "how old is tim", "what is your age", "how old are you", "age?"], "tag": "age",
"responses": ["I am 18 years old!", "18 years young!"], "patterns": [
"how old",
"how old is tim",
"what is your age",
"how old are you",
"age?"
],
"responses": [
"I am 18 years old!",
"18 years young!"
],
"context_set": "" "context_set": ""
}, },
{"tag": "name", {
"patterns": ["what is your name", "what should I call you", "whats your name?"], "tag": "name",
"responses": ["You can call me Tim.", "I'm Tim!", "I'm Tim aka Tech With Tim."], "patterns": [
"what is your name",
"what should I call you",
"whats your name?"
],
"responses": [
"You can call me Tim.",
"I'm Tim!",
"I'm Tim aka Tech With Tim."
],
"context_set": "" "context_set": ""
}, },
{"tag": "shop", {
"patterns": ["Id like to buy something", "whats on the menu", "what do you reccommend?", "could i get something to eat"], "tag": "shop",
"responses": ["We sell chocolate chip cookies for $2!", "Cookies are on the menu!"], "patterns": [
"Id like to buy something",
"whats on the menu",
"what do you reccommend?",
"could i get something to eat"
],
"responses": [
"We sell chocolate chip cookies for $2!",
"Cookies are on the menu!"
],
"context_set": "" "context_set": ""
}, },
{"tag": "hours", {
"patterns": ["when are you guys open", "what are your hours", "hours of operation"], "tag": "hours",
"responses": ["We are open 7am-4pm Monday-Friday!"], "patterns": [
"when are you guys open",
"what are your hours",
"hours of operation"
],
"responses": [
"We are open 7am-4pm Monday-Friday!"
],
"context_set": "" "context_set": ""
} }
] ]

View File

@ -1,52 +1,156 @@
{"intents": [ {
{"tag": "greeting", "intents": [
"patterns": ["Cześć", "Elo", "Jesteś?", "Hej", "Dzień dobry", "Sup"], {
"responses": ["Cześć!", "Dobrze Cię widzieć!", "Hej, w czym mogę pomóc?"], "tag": "greeting",
"patterns": [
"Cześć",
"Elo",
"Jesteś?",
"Hej",
"Dzień dobry",
"Sup"
],
"responses": [
"Cześć!",
"Dobrze Cię widzieć!",
"Hej, w czym mogę pomóc?"
],
"context_set": "" "context_set": ""
}, },
{"tag": "goodbye", {
"patterns": ["narazie", "Do zobaczenia", "Dowidzenia", "Dobranoc", "Miłego dnia"], "tag": "goodbye",
"responses": ["Do zobaczenia później", "Mam nadzieję, że później pogadamy", "Narazie!"], "patterns": [
"narazie",
"Do zobaczenia",
"Dowidzenia",
"Dobranoc",
"Miłego dnia"
],
"responses": [
"Do zobaczenia później",
"Mam nadzieję, że później pogadamy",
"Narazie!"
],
"context_set": "" "context_set": ""
}, },
{"tag": "age", {
"patterns": ["Ile masz lat", "Ile lat ma Janet", "Wiek", "Jak stara jesteś", "urodziny"], "tag": "age",
"responses": ["Mam kilka dni", "Urodziłam się 17.03.2021"], "patterns": [
"Ile masz lat",
"Ile lat ma Janet",
"Wiek",
"Jak stara jesteś",
"urodziny"
],
"responses": [
"Mam kilka dni",
"Urodziłam się 17.03.2021"
],
"context_set": "" "context_set": ""
}, },
{"tag": "name", {
"patterns": ["Jak masz na imię", "Jak Cię zwą?", "twoje imie?", "Imie", "Jak cię nazywać", "Kim jesteś"], "tag": "name",
"responses": ["Możesz mnie nazywać Janet!", "Jestem Janet", "Jestem Janet, twój ulubiony chatbot"], "patterns": [
"Jak masz na imię",
"Jak Cię zwą?",
"twoje imie?",
"Imie",
"Jak cię nazywać",
"Kim jesteś"
],
"responses": [
"Możesz mnie nazywać Janet!",
"Jestem Janet",
"Jestem Janet, twój ulubiony chatbot"
],
"context_set": "" "context_set": ""
}, },
{"tag": "goout", {
"patterns": ["Czy chcesz gdzieś wyjść?", "zrobimy coś razem?", "pójdziemy gdzieś razem?"], "tag": "goout",
"responses": ["Może kiedy indziej", "Odezwę się latem"], "patterns": [
"Czy chcesz gdzieś wyjść?",
"zrobimy coś razem?",
"pójdziemy gdzieś razem?"
],
"responses": [
"Może kiedy indziej",
"Odezwę się latem"
],
"context_set": "" "context_set": ""
}, },
{"tag": "doing", {
"patterns": ["Co robisz teraz?", "co słychać", "jakie masz plany?", "jak się masz?"], "tag": "doing",
"responses": ["Gram w grę", "Słucham muzyki", "nie twój interes", "nie mam czasu odpowiadać", ""], "patterns": [
"Co robisz teraz?",
"co słychać",
"jakie masz plany?",
"jak się masz?"
],
"responses": [
"Gram w grę",
"Słucham muzyki",
"nie twój interes",
"nie mam czasu odpowiadać",
""
],
"context_set": "" "context_set": ""
}, },
{"tag": "game", {
"patterns": ["a w co grasz?", "a w co?", "grasz?"], "tag": "game",
"responses": ["nie interesuj się", "a co cię to obchodzi", "...", "w coś", "W OSRS"], "patterns": [
"a w co grasz?",
"a w co?",
"grasz?"
],
"responses": [
"nie interesuj się",
"a co cię to obchodzi",
"...",
"w coś",
"W OSRS"
],
"context_set": "" "context_set": ""
}, },
{"tag": "music", {
"patterns": ["czego?", "czego słuchasz?", "jakiej muzyki?"], "tag": "music",
"responses": ["Starego vinyla z 1995 roku", "mojego ulubionego setu rejwowego", "czegoś tam..."], "patterns": [
"czego?",
"czego słuchasz?",
"jakiej muzyki?"
],
"responses": [
"Starego vinyla z 1995 roku",
"mojego ulubionego setu rejwowego",
"czegoś tam..."
],
"context_set": "" "context_set": ""
}, },
{"tag": "angry", {
"patterns": ["bo co?", "dlaczego?", "jak to?"], "tag": "angry",
"responses": ["Czas zakończyć rozmowę", "nie mam na to siły i czasu", "zostaw mnie w spokoju"], "patterns": [
"bo co?",
"dlaczego?",
"jak to?"
],
"responses": [
"Czas zakończyć rozmowę",
"nie mam na to siły i czasu",
"zostaw mnie w spokoju"
],
"context_set": "" "context_set": ""
}, },
{"tag": "why", {
"patterns": ["o co chodzi?", "czemu jesteś zła", "poczekaj"], "tag": "why",
"responses": ["...", "Nie pisz do mnie więcej", "Odezwę się latem"], "patterns": [
"o co chodzi?",
"czemu jesteś zła",
"poczekaj"
],
"responses": [
"...",
"Nie pisz do mnie więcej",
"Odezwę się latem"
],
"context_set": "" "context_set": ""
} }
] ]

View File

@ -1,22 +1,68 @@
{"intents": [ {
{"tag": "greeting", "intents": [
"patterns": ["Cześć", "Elo", "Jesteś?", "Hej", "Dzień dobry", "Sup"], {
"responses": ["Cześć!", "Dobrze Cię widzieć!", "Hej, w czym mogę pomóc?"], "tag": "greeting",
"patterns": [
"Cześć",
"Elo",
"Jesteś?",
"Hej",
"Dzień dobry",
"Sup"
],
"responses": [
"Cześć!",
"Dobrze Cię widzieć!",
"Hej, w czym mogę pomóc?"
],
"context_set": "" "context_set": ""
}, },
{"tag": "goodbye", {
"patterns": ["narazie", "Do zobaczenia", "Dowidzenia", "Dobranoc", "Miłego dnia"], "tag": "goodbye",
"responses": ["Do zobaczenia później", "Mam nadzieję, że później pogadamy", "Narazie!"], "patterns": [
"narazie",
"Do zobaczenia",
"Dowidzenia",
"Dobranoc",
"Miłego dnia"
],
"responses": [
"Do zobaczenia później",
"Mam nadzieję, że później pogadamy",
"Narazie!"
],
"context_set": "" "context_set": ""
}, },
{"tag": "age", {
"patterns": ["Ile masz lat", "Ile lat ma Janet", "Wiek", "Jak stara jesteś", "urodziny"], "tag": "age",
"responses": ["Mam kilka dni", "Urodziłam się 17.03.2021"], "patterns": [
"Ile masz lat",
"Ile lat ma Janet",
"Wiek",
"Jak stara jesteś",
"urodziny"
],
"responses": [
"Mam kilka dni",
"Urodziłam się 17.03.2021"
],
"context_set": "" "context_set": ""
}, },
{"tag": "name", {
"patterns": ["Jak masz na imię", "Jak Cię zwą?", "twoje imie?", "Imie", "Jak cię nazywać", "Kim jesteś"], "tag": "name",
"responses": ["Możesz mnie nazywać Janet!", "Jestem Janet", "Jestem Janet, twój ulubiony chatbot"], "patterns": [
"Jak masz na imię",
"Jak Cię zwą?",
"twoje imie?",
"Imie",
"Jak cię nazywać",
"Kim jesteś"
],
"responses": [
"Możesz mnie nazywać Janet!",
"Jestem Janet",
"Jestem Janet, twój ulubiony chatbot"
],
"context_set": "" "context_set": ""
} }
] ]

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
tflearn==0.5
tensorflow
pystempel==1.2