{ "cells": [ { "cell_type": "code", "execution_count": 20, "metadata": { "id": "wUWIn56C2EVy" }, "outputs": [], "source": [ "import nltk\n", "from nltk.stem import WordNetLemmatizer\n", "lemmatizer = WordNetLemmatizer()\n", "import json\n", "import pickle\n", "import numpy as np\n", "from keras.models import Sequential\n", "from keras.layers import Dense, Activation, Dropout\n", "# from keras.optimizers import SGD\n", "from tensorflow.keras.optimizers import SGD\n", "import random" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "hBb-ddKr2zlg", "outputId": "d216a15f-5142-4cad-a214-cc911a214394" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package punkt to C:\\Users\\Makara\n", "[nltk_data] PC\\AppData\\Roaming\\nltk_data...\n", "[nltk_data] Unzipping tokenizers\\punkt.zip.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nltk.download('punkt')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "WJNKSOig29LD", "outputId": "4a6505c1-4080-4097-d661-95275788348f" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package wordnet to C:\\Users\\Makara\n", "[nltk_data] PC\\AppData\\Roaming\\nltk_data...\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nltk.download('wordnet')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package omw-1.4 to C:\\Users\\Makara\n", "[nltk_data] PC\\AppData\\Roaming\\nltk_data...\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nltk.download('omw-1.4')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "id": "CcRMqaqy2aXK" }, "outputs": [], "source": [ "words=[]\n", "classes = []\n", "documents = []\n", "ignore_words = ['?', '!']\n", "data_file = open('data.json').read()\n", "intents = json.loads(data_file)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "85GcOWiP2iWf" }, "outputs": [], "source": [ "for intent in intents['intents']:\n", " for pattern in intent['patterns']:\n", " #tokenize each word\n", " w = nltk.word_tokenize(pattern)\n", " words.extend(w)\n", " #add documents in the corpus\n", " documents.append((w, intent['tag']))\n", " # add to our classes list\n", " if intent['tag'] not in classes:\n", " classes.append(intent['tag'])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "p1iYlVBm2i8v", "outputId": "a0696f92-8558-484d-fab1-8287685658cc" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "47 documents\n", "9 classes ['adverse_drug', 'blood_pressure', 'blood_pressure_search', 'goodbye', 'greeting', 'hospital_search', 'options', 'pharmacy_search', 'thanks']\n", "88 unique lemmatized words [\"'s\", ',', 'a', 'adverse', 'all', 'anyone', 'are', 'awesome', 'be', 'behavior', 'blood', 'by', 'bye', 'can', 'causing', 'chatting', 'check', 'could', 'data', 'day', 'detail', 'do', 'dont', 'drug', 'entry', 'find', 'for', 'give', 'good', 'goodbye', 'have', 'hello', 'help', 'helpful', 'helping', 'hey', 'hi', 'history', 'hola', 'hospital', 'how', 'i', 'id', 'is', 'later', 'list', 'load', 'locate', 'log', 'looking', 'lookup', 'management', 'me', 'module', 'nearby', 'next', 'nice', 'of', 'offered', 'open', 'patient', 'pharmacy', 'pressure', 'provide', 'reaction', 'related', 'result', 'search', 'searching', 'see', 'show', 'suitable', 'support', 'task', 'thank', 'thanks', 'that', 'there', 'till', 'time', 'to', 'transfer', 'up', 'want', 'what', 'which', 'with', 'you']\n" ] } ], "source": [ "# lemmaztize and lower each word and remove duplicates\n", "words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]\n", "words = sorted(list(set(words)))\n", "# sort classes\n", "classes = sorted(list(set(classes)))\n", "# documents = combination between patterns and intents\n", "print (len(documents), \"documents\")\n", "# classes = intents\n", "print (len(classes), \"classes\", classes)\n", "# words = all words, vocabulary\n", "print (len(words), \"unique lemmatized words\", words)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "H5EZ1wf325dH" }, "outputs": [], "source": [ "pickle.dump(words,open('texts.pkl','wb'))\n", "pickle.dump(classes,open('labels.pkl','wb'))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "id": "oTj9egGz3CMZ" }, "outputs": [], "source": [ "# create our training data\n", "training = []\n", "# create an empty array for our output\n", "output_empty = [0] * len(classes)\n", "# training set, bag of words for each sentence\n", "for doc in documents:\n", " # initialize our bag of words\n", " bag = []\n", " # list of tokenized words for the pattern\n", " pattern_words = doc[0]\n", " # lemmatize each word - create base word, in attempt to represent related words\n", " pattern_words = [lemmatizer.lemmatize(word.lower()) for word in pattern_words]\n", " # create our bag of words array with 1, if word match found in current pattern\n", " for w in words:\n", " bag.append(1) if w in pattern_words else bag.append(0)\n", "\n", " # output is a '0' for each tag and '1' for current tag (for each pattern)\n", " output_row = list(output_empty)\n", " output_row[classes.index(doc[1])] = 1\n", "\n", " training.append([bag, output_row])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "TWZKpn-43KaH", "outputId": "c2b89f6a-d1e8-4e25-908f-5b8f1a5bb84a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Training data created\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\Makara PC\\.conda\\envs\\chat-bot-app\\lib\\site-packages\\ipykernel_launcher.py:3: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray\n", " This is separate from the ipykernel package so we can avoid doing imports until\n" ] } ], "source": [ "# shuffle our features and turn into np.array\n", "random.shuffle(training)\n", "training = np.array(training)\n", "# create train and test lists. X - patterns, Y - intents\n", "train_x = list(training[:,0])\n", "train_y = list(training[:,1])\n", "print(\"Training data created\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "id": "c4rbUrWB3MAX" }, "outputs": [], "source": [ "# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons\n", "# equal to number of intents to predict output intent with softmax\n", "model = Sequential()\n", "model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))\n", "model.add(Dropout(0.5))\n", "model.add(Dense(64, activation='relu'))\n", "model.add(Dropout(0.5))\n", "model.add(Dense(len(train_y[0]), activation='softmax'))" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "fRmg-rBd3OnQ", "outputId": "5369506c-da45-4dd5-8773-59f52875bc68" }, "outputs": [], "source": [ "# Compile model. Stochastic gradient descent with Nesterov accelerated gradient gives good results for this model\n", "sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)\n", "model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "DeD0fV0c3RBn", "outputId": "392059e2-dfe7-46a0-b2c8-db2f3702a483" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1/200\n", "10/10 [==============================] - 1s 2ms/step - loss: 2.2413 - accuracy: 0.1064\n", "Epoch 2/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 2.1823 - accuracy: 0.2340\n", "Epoch 3/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 2.1345 - accuracy: 0.2128\n", "Epoch 4/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.9794 - accuracy: 0.3191\n", "Epoch 5/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 1.8818 - accuracy: 0.3191\n", "Epoch 6/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.7872 - accuracy: 0.4043\n", "Epoch 7/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.6584 - accuracy: 0.5106\n", "Epoch 8/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 1.5289 - accuracy: 0.5319\n", "Epoch 9/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 1.4448 - accuracy: 0.5957\n", "Epoch 10/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.2668 - accuracy: 0.5957\n", "Epoch 11/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.2086 - accuracy: 0.6809\n", "Epoch 12/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.9905 - accuracy: 0.8085\n", "Epoch 13/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 1.0099 - accuracy: 0.7872\n", "Epoch 14/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.9804 - accuracy: 0.7234\n", "Epoch 15/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.8112 - accuracy: 0.8298\n", "Epoch 16/200\n", "10/10 [==============================] - 0s 7ms/step - loss: 0.7849 - accuracy: 0.7447\n", "Epoch 17/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.6714 - accuracy: 0.7872\n", "Epoch 18/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.6601 - accuracy: 0.7872\n", "Epoch 19/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.4989 - accuracy: 0.8936\n", "Epoch 20/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.7604 - accuracy: 0.7447\n", "Epoch 21/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.7019 - accuracy: 0.7872\n", "Epoch 22/200\n", "10/10 [==============================] - 0s 8ms/step - loss: 0.5007 - accuracy: 0.8936\n", "Epoch 23/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.4494 - accuracy: 0.8723\n", "Epoch 24/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.3297 - accuracy: 0.9362\n", "Epoch 25/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.3112 - accuracy: 0.9362\n", "Epoch 26/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.3624 - accuracy: 0.9362\n", "Epoch 27/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.2498 - accuracy: 0.9362\n", "Epoch 28/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.2607 - accuracy: 0.9362\n", "Epoch 29/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.2573 - accuracy: 0.9362\n", "Epoch 30/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1811 - accuracy: 0.9787\n", "Epoch 31/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.3079 - accuracy: 0.8936\n", "Epoch 32/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.2232 - accuracy: 0.9574\n", "Epoch 33/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1904 - accuracy: 0.9787\n", "Epoch 34/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.2117 - accuracy: 0.9149\n", "Epoch 35/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1476 - accuracy: 0.9787\n", "Epoch 36/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1317 - accuracy: 1.0000\n", "Epoch 37/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0762 - accuracy: 1.0000\n", "Epoch 38/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1502 - accuracy: 0.9149\n", "Epoch 39/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1191 - accuracy: 0.9574\n", "Epoch 40/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1490 - accuracy: 0.9787\n", "Epoch 41/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.2177 - accuracy: 0.9574\n", "Epoch 42/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.1596 - accuracy: 0.9574\n", "Epoch 43/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1574 - accuracy: 0.9574\n", "Epoch 44/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.2133 - accuracy: 0.9149\n", "Epoch 45/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.1228 - accuracy: 0.9787\n", "Epoch 46/200\n", "10/10 [==============================] - 0s 7ms/step - loss: 0.1345 - accuracy: 0.9574\n", "Epoch 47/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1022 - accuracy: 0.9787\n", "Epoch 48/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1116 - accuracy: 0.9574\n", "Epoch 49/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1366 - accuracy: 0.9362\n", "Epoch 50/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1418 - accuracy: 0.9574\n", "Epoch 51/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1272 - accuracy: 1.0000\n", "Epoch 52/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0773 - accuracy: 1.0000\n", "Epoch 53/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0499 - accuracy: 1.0000\n", "Epoch 54/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1199 - accuracy: 0.9574\n", "Epoch 55/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.1400 - accuracy: 1.0000\n", "Epoch 56/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.0842 - accuracy: 0.9787\n", "Epoch 57/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1037 - accuracy: 0.9787\n", "Epoch 58/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.1494 - accuracy: 0.9362\n", "Epoch 59/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0432 - accuracy: 1.0000\n", "Epoch 60/200\n", "10/10 [==============================] - 0s 6ms/step - loss: 0.0823 - accuracy: 0.9787\n", "Epoch 61/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0534 - accuracy: 1.0000\n", "Epoch 62/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0671 - accuracy: 1.0000\n", "Epoch 63/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0628 - accuracy: 1.0000\n", "Epoch 64/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0229 - accuracy: 1.0000\n", "Epoch 65/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0617 - accuracy: 1.0000\n", "Epoch 66/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0603 - accuracy: 0.9787\n", "Epoch 67/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0239 - accuracy: 1.0000\n", "Epoch 68/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1004 - accuracy: 0.9574\n", "Epoch 69/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0582 - accuracy: 0.9787\n", "Epoch 70/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1214 - accuracy: 0.9362\n", "Epoch 71/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0270 - accuracy: 1.0000\n", "Epoch 72/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0916 - accuracy: 0.9787\n", "Epoch 73/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0413 - accuracy: 1.0000\n", "Epoch 74/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0502 - accuracy: 1.0000\n", "Epoch 75/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0618 - accuracy: 0.9787\n", "Epoch 76/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0723 - accuracy: 1.0000\n", "Epoch 77/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.1292 - accuracy: 0.9574\n", "Epoch 78/200\n", "10/10 [==============================] - ETA: 0s - loss: 0.0038 - accuracy: 1.00 - 0s 1ms/step - loss: 0.0298 - accuracy: 1.0000\n", "Epoch 79/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0176 - accuracy: 1.0000\n", "Epoch 80/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1068 - accuracy: 0.9574\n", "Epoch 81/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0200 - accuracy: 1.0000\n", "Epoch 82/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0183 - accuracy: 1.0000\n", "Epoch 83/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0467 - accuracy: 1.0000\n", "Epoch 84/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0539 - accuracy: 1.0000\n", "Epoch 85/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.0998 - accuracy: 0.9574\n", "Epoch 86/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.1305 - accuracy: 0.9574\n", "Epoch 87/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0236 - accuracy: 1.0000\n", "Epoch 88/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0365 - accuracy: 1.0000\n", "Epoch 89/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0752 - accuracy: 0.9787\n", "Epoch 90/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0443 - accuracy: 1.0000\n", "Epoch 91/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0955 - accuracy: 0.9787\n", "Epoch 92/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0447 - accuracy: 1.0000\n", "Epoch 93/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0775 - accuracy: 0.9787\n", "Epoch 94/200\n", "10/10 [==============================] - 0s 8ms/step - loss: 0.0479 - accuracy: 1.0000\n", "Epoch 95/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0529 - accuracy: 1.0000\n", "Epoch 96/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0087 - accuracy: 1.0000\n", "Epoch 97/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0415 - accuracy: 1.0000\n", "Epoch 98/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0348 - accuracy: 1.0000\n", "Epoch 99/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0130 - accuracy: 1.0000\n", "Epoch 100/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0250 - accuracy: 1.0000\n", "Epoch 101/200\n", "10/10 [==============================] - 0s 6ms/step - loss: 0.0513 - accuracy: 0.9787\n", "Epoch 102/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0326 - accuracy: 0.9787\n", "Epoch 103/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0516 - accuracy: 0.9787\n", "Epoch 104/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0376 - accuracy: 1.0000\n", "Epoch 105/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.0236 - accuracy: 1.0000\n", "Epoch 106/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0146 - accuracy: 1.0000\n", "Epoch 107/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0327 - accuracy: 1.0000\n", "Epoch 108/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0333 - accuracy: 1.0000\n", "Epoch 109/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0046 - accuracy: 1.0000\n", "Epoch 110/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0920 - accuracy: 0.9574\n", "Epoch 111/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0155 - accuracy: 1.0000\n", "Epoch 112/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0148 - accuracy: 1.0000\n", "Epoch 113/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0248 - accuracy: 1.0000\n", "Epoch 114/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0260 - accuracy: 1.0000\n", "Epoch 115/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0162 - accuracy: 1.0000\n", "Epoch 116/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0659 - accuracy: 0.9787\n", "Epoch 117/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0618 - accuracy: 0.9787\n", "Epoch 118/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0301 - accuracy: 1.0000\n", "Epoch 119/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0334 - accuracy: 1.0000\n", "Epoch 120/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0224 - accuracy: 1.0000\n", "Epoch 121/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.1810 - accuracy: 0.9574\n", "Epoch 122/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0677 - accuracy: 1.0000\n", "Epoch 123/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0693 - accuracy: 0.9787\n", "Epoch 124/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0523 - accuracy: 0.9787\n", "Epoch 125/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0281 - accuracy: 1.0000\n", "Epoch 126/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0209 - accuracy: 1.0000\n", "Epoch 127/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0405 - accuracy: 0.9787\n", "Epoch 128/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0093 - accuracy: 1.0000\n", "Epoch 129/200\n", "10/10 [==============================] - ETA: 0s - loss: 0.0834 - accuracy: 1.00 - 0s 2ms/step - loss: 0.0413 - accuracy: 1.0000\n", "Epoch 130/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0122 - accuracy: 1.0000\n", "Epoch 131/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0125 - accuracy: 1.0000\n", "Epoch 132/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0099 - accuracy: 1.0000\n", "Epoch 133/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0281 - accuracy: 1.0000\n", "Epoch 134/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0179 - accuracy: 1.0000\n", "Epoch 135/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0070 - accuracy: 1.0000\n", "Epoch 136/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0456 - accuracy: 1.0000\n", "Epoch 137/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0493 - accuracy: 0.9787\n", "Epoch 138/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0211 - accuracy: 1.0000\n", "Epoch 139/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0098 - accuracy: 1.0000\n", "Epoch 140/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0306 - accuracy: 1.0000\n", "Epoch 141/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0076 - accuracy: 1.0000\n", "Epoch 142/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0605 - accuracy: 0.9787\n", "Epoch 143/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0273 - accuracy: 1.0000\n", "Epoch 144/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0450 - accuracy: 1.0000\n", "Epoch 145/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0090 - accuracy: 1.0000\n", "Epoch 146/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0230 - accuracy: 1.0000\n", "Epoch 147/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0096 - accuracy: 1.0000\n", "Epoch 148/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0137 - accuracy: 1.0000\n", "Epoch 149/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0288 - accuracy: 1.0000\n", "Epoch 150/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0313 - accuracy: 1.0000\n", "Epoch 151/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0315 - accuracy: 1.0000\n", "Epoch 152/200\n", "10/10 [==============================] - ETA: 0s - loss: 4.1381e-04 - accuracy: 1.00 - 0s 2ms/step - loss: 0.0146 - accuracy: 1.0000\n", "Epoch 153/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0198 - accuracy: 1.0000\n", "Epoch 154/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0291 - accuracy: 0.9787\n", "Epoch 155/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0294 - accuracy: 0.9787\n", "Epoch 156/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0085 - accuracy: 1.0000\n", "Epoch 157/200\n", "10/10 [==============================] - 0s 998us/step - loss: 0.0434 - accuracy: 0.9787\n", "Epoch 158/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0236 - accuracy: 1.0000\n", "Epoch 159/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0070 - accuracy: 1.0000\n", "Epoch 160/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0170 - accuracy: 1.0000\n", "Epoch 161/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0199 - accuracy: 1.0000\n", "Epoch 162/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0073 - accuracy: 1.0000\n", "Epoch 163/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0289 - accuracy: 1.0000\n", "Epoch 164/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0165 - accuracy: 1.0000\n", "Epoch 165/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0180 - accuracy: 1.0000\n", "Epoch 166/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0083 - accuracy: 1.0000\n", "Epoch 167/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0038 - accuracy: 1.0000\n", "Epoch 168/200\n", "10/10 [==============================] - 0s 6ms/step - loss: 0.0112 - accuracy: 1.0000\n", "Epoch 169/200\n", "10/10 [==============================] - 0s 15ms/step - loss: 0.0166 - accuracy: 1.0000\n", "Epoch 170/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0041 - accuracy: 1.0000\n", "Epoch 171/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.0424 - accuracy: 0.9787\n", "Epoch 172/200\n", "10/10 [==============================] - 0s 5ms/step - loss: 0.0393 - accuracy: 0.9787\n", "Epoch 173/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0543 - accuracy: 0.9787\n", "Epoch 174/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0177 - accuracy: 1.0000\n", "Epoch 175/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0305 - accuracy: 0.9787\n", "Epoch 176/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0069 - accuracy: 1.0000\n", "Epoch 177/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0440 - accuracy: 0.9787\n", "Epoch 178/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0337 - accuracy: 1.0000\n", "Epoch 179/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0526 - accuracy: 0.9787\n", "Epoch 180/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0137 - accuracy: 1.0000\n", "Epoch 181/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0091 - accuracy: 1.0000\n", "Epoch 182/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0177 - accuracy: 1.0000\n", "Epoch 183/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0137 - accuracy: 1.0000\n", "Epoch 184/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0099 - accuracy: 1.0000\n", "Epoch 185/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.1220 - accuracy: 0.9574\n", "Epoch 186/200\n", "10/10 [==============================] - 0s 740us/step - loss: 0.0532 - accuracy: 0.9787\n", "Epoch 187/200\n", "10/10 [==============================] - ETA: 0s - loss: 5.3321e-04 - accuracy: 1.00 - 0s 3ms/step - loss: 0.0055 - accuracy: 1.0000\n", "Epoch 188/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0095 - accuracy: 1.0000\n", "Epoch 189/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0052 - accuracy: 1.0000\n", "Epoch 190/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0429 - accuracy: 1.0000\n", "Epoch 191/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0163 - accuracy: 1.0000\n", "Epoch 192/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0160 - accuracy: 1.0000\n", "Epoch 193/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0227 - accuracy: 1.0000\n", "Epoch 194/200\n", "10/10 [==============================] - 0s 4ms/step - loss: 0.0065 - accuracy: 1.0000\n", "Epoch 195/200\n", "10/10 [==============================] - 0s 3ms/step - loss: 0.0052 - accuracy: 1.0000\n", "Epoch 196/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 9.3289e-04 - accuracy: 1.0000\n", "Epoch 197/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0115 - accuracy: 1.0000\n", "Epoch 198/200\n", "10/10 [==============================] - 0s 1ms/step - loss: 0.0444 - accuracy: 0.9787\n", "Epoch 199/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0101 - accuracy: 1.0000\n", "Epoch 200/200\n", "10/10 [==============================] - 0s 2ms/step - loss: 0.0175 - accuracy: 1.0000\n" ] } ], "source": [ "# Fitting and saving the model\n", "hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)\n", "model.save('model.h5', hist)" ] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "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.6.13" } }, "nbformat": 4, "nbformat_minor": 0 }