Chatbots
Build A Chatbot
1. Prepare Data
The first step of any machine learning related process is that of preparing data. You need to have thousands of existing interactions between customers and your support staff to train your chatbot.
These should be as detailed and varied as possible so that there are ample data points for your deep learning chatbot. This particular process is called the creation of an ontology. Your sole goal in this stage should be to collect as many interactions as possible.
2. Data Reshaping
Depending on your data source, you may or may not need this step. If your data isn’t segregated well, you will need to reshape your data into single rows of observations.
These observations can be called message-response pairs that will be added to the classifier.
The goal of this step is to put one speaker as the response in a conversation. All of the incoming dialogue will then be used as textual indicators that can help predict the response.
3. Pre-Processing
The next step in building a deep learning chatbot is that of pre-processing. In this step, you need to add grammar into the machine learning so that your chatbot can understand spelling errors correctly.
The processes involved in this step are tokenizing, stemming, and lemmatizing of the chats. This makes the chats readable for the deep learning chatbot. You can use the NTLK tool for this, which is available for free.
In the final step of pre-processing, you create parse trees of the chats as a reference for your deep learning chatbot.
4. Select the Type of Chatbot
Once you’re done with the ontology and pre-processing, you need to select the type of chatbot that you’re going to create.
The two major types of chatbots that you can make are:
* Generative – In the generative model, the chatbot doesn’t use any sort of predefined repository. This is an advanced form of chatbot that uses deep learning to respond to queries.
* Retrieval-Based – In this form, the chatbot has a repository of responses that it uses to solve the queries. You need to choose an appropriate response based on the questions, and the chatbot will comply.
The retrieval model seldom makes mistakes as it’s completely based on retrieving data. However, it has its own set of limitations such that it can seem too rigid and the responses may not seem “human.”
On the other hand, a deep learning chatbot can easily adapt its style to the questions and demands from its customers. However, even this type of chatbot can’t imitate human interactions without mistakes.
The generative model of chatbots is also harder to perfect as the knowledge in this field is fairly limited. In fact, the deep learning chatbots still haven’t been able to clear the Turing test.
While retrieval-based chatbots are extremely helpful when your queries are simple, generative ones are needed for complex queries. This is especially true in cases where the chatbot needs to keep track of what was said in previous messages as well. Retrieval-based chatbots can only answer inquiries that are straightforward and easy to answer.
5. Generate Word Vectors
Word vectors are needed when you have frequent usage of words such as LOL, LMAO, etc. They are common words that are used on social media but aren’t part of many datasets.
While it’s easier to use pre-trained vectors, you need to create your own word vectors when there are such words that aren’t there in other word vector lists.
How do you do this?
To generate your own word vectors, take the approach of a Word2Vec model. In this, the word vectors are created by the model by looking at how these words appear in sentences.
Those words that have similar contexts will be placed closer in the vector space. You can use a Python script to train your Word2Vec model. Alternatively, you can use TensorFlow Seq2Seq function for the same.
6. Create a Seq2Seq Model
To create the Seq2Seq model, you can use TensorFlow. For this, you’ll need to use a Python script that looks like the one here.
All you need to do is follow the code and try to develop the Python script for your deep learning chatbot. The most important part of this model is the embedding_rnn_seq2seq() function on TensorFlow.
HANDPICKED RELATED CONTENT:
* What is a Chatbot and How Can It Help Your Business?
7. Track the Process
Now that you’ve created your Seq2Seq model, you need to track the training process. This is a fun part in the sense that you can see how your deep learning chatbot gets trained.
You should test the chatbot at different points in the loop through an input string. You’ll get non-pad and non-EOS tokens back in the output.
Initially, most of your responses will be blank as the chatbot will only output the padding and EOS tokens. Eventually, your chatbot will start answering with small output strings such as LOL, which are used frequently.
Slowly, the chatbot will begin developing its responses and come up with longer and more complete sentences. You will find that the answers will have a better structure and grammar over time.
8. Add it to an Application
Now that your Seq2Seq model is ready and tested, you need to launch it in a place where people can interact with it. For the sake of explanation, I’m going to limit this to Facebook Messenger as it’s one of the simplest methods of adding a chatbot.