How to Make a Simple Deep Learning Chatbot

Original article was published on Deep Learning on Medium

Now its time to start programming. Let’s start by making our data for the chatbot. Because this is a simple chatbot we don’t need to have any massive data so we will program it ourselves. To make this properly this needs to be a .json and needs to be the same format below. I called my file “dataset.json

I’m going to explain how this works so you know how you can make your own. So make one just like this and if you want to make a new category if the user said something the tag is the meaning and the pattern is what the user would say. The response is as you can imagine is the responses that the chatbot will say and will pick one of the responses to say. The more data you give it the better it will be at responses.

Now create a new project and that is the program that will run your chatbot so you can name it whatever. For this example, I will be naming my project name jarvis.py. We need to create a code that will let the project connect to your dataset. Copy the code below and below I will explain more about it.

If your dataset is a different name from mine change it to the name you have it as on line 11 and make sure it is connected to the code so run the program and if there are no errors then it is working.

Now it is time to make the list have value and to also have the json data extract the data to our program.

Now it’s time to make something called word stemming. For example, if the user typed in waited, or waiting or waits then it would go under wait. the code below does all the word stemming

Now that we have located where all of our data is, now we need to create a vocabulary that is called word lists. Below is the code to the word list.

And now we will take the data and put it into output and arrays

Now it is finally time to start training the chatbot. So we will make a standard neural network with 2 hidden layers.

Now that we had the neural network done it’s time to make training the model and saving it after the training. In the photo below you see the number 1000 and that means that you are telling it to train and go over the data 1000 times.

Now it is time where the chatbot makes predictions when you put in the input.

Congratulations you have now made a deep learning chatbot! spend more time putting data in it and keep on training it and you will have a perfect chatbot for your needs. Thank you for following the instructions all the way and good luck on your project!

Written by Titus Petersen

credit to: techwithtim