Do We Need to be AI Masters to Create a Chat Bot?
With the emergence of AI and machine learning, development of software is changing quickly. One of the new pushes is digital assistants. Whether it is a robust assistant like Amazon’s Alexa or Microsoft’s Cortana, or more simplistic like a chat window on a website the world is slowly starting to expect a more personal and human interaction with machines. The problem with the development of these systems is the steep learning curve required to get into AI development and machine learning. Resources are not mature enough for everyone to quickly start down the path of neural networks and classification, so this begs the question is AI really required to create a chat system with human interaction?
Natural Language Processing
Before we dive into if we need AI to create a chatbot, we first must understand Natural Language Processing or NLP. Computers cannot understand English or any other language, so we must convert this into something the computer can recognize. Natural language processing is a very complicated subject and goes way beyond this blog, but it is essential to understand some of the basic concepts to determine if a machine learning algorithm is needed to create our chatbot or can we continue to use standard practices to achieve the same results.
Stop words are words or phrases that have very little meaning. While they are important in natural language, they do not provide any information that is relevant to processing text. Important words fall into categories like “nouns, verbs, adverbs, etc.” Stop words would be the others like “is, an, a, the, etc.” By preprocessing the text and removing the stop words, we can extract important words and phrases making it easier to determine what is being asked of the chatbot.
Stemming a word is simplifying or modifying the word down to the root word. For example, words like “running, ran, runs” become “run.” Stemming is vital to language processing, so we do not need to create a series of features to represent the same item. By keeping our data model simple, we're able to focus on the outcome, not syntax.
Advanced NLP Practices
Now that we know about stop words and stemming our NLP knowledge is strong enough to begin creating a chatbot. There are more concepts out there for processing language, but they go beyond this blog. Pairing of common words or phrases or categorizing the word as a noun, verb, adjective are just some of these techniques. The goal is the same - to create a set of features to represent relevant data in our model to process the text.
Chatbot NLP Processing
Now that we understand some of the concepts of NLP, we can now try to prove if machine learning is required for our chatbot. To do this, let's come up with a concept for the bot like a password manager. The next step is to determine what it will need to do. Each task will be assigned a numeric variable, this is just to represent our action later and has no real value.
Now that we know our actions, let's look at some phrases that a user might input to execute these actions.
At first glance, it looks like nothing is in common with these phrases. The first thing we might think is we need to train a neural network to guess what these phrases are representing. Before we jump to this conclusion, let's apply some of the NLP techniques starting with removing the stop words.
Stop Words Pass 1
After removing the stop words we start to see some other words that create noise, like proper nouns or the function word "please." We can now make another pass removing these words.
Stop Words Pass 2
The second pass has now given us a pattern. It might be feasible to change “cannot” to “No” or “update” to “change” or use another synonym to represent it, but for this blog, we will leave it the way it is since our feature list is small. Machines do not understand text; therefore we must then assign a value it does recognize. There are various ways of doing this like binary features, assigning a 1 or 0 if the word exists, the bag of words method, counting how many times a word appears, or just converting the word to a number. In this example, I will be using a binary representation for each phrase. We will indicate a "1" if the word appears in our phrase and a "0" if it does not.
We now have a feature model that represents our data. We can now feed this into a machine learning algorithm if we wanted, but if you notice "change password" was a very common phrase and we can reduce the model even more.
We now have a matrix of only five entries, and by using a binary matrix, we have a representation of each entry meaning we do not need a machine learning algorithm to process this. We can quickly try to fit our phrases into this model by comparing it to our matrix, showing that a chatbot can be created without knowing any AI or machine learning techniques.
Why use AI?
Our example has shown us that we do not need AI to create a natural language processor for our chatbot, so why is it such a big deal to incorporate machine learning into a chatbot? We built our features from some common phrases, but there are many combinations we did not consider. Managing a feature set like this can become very daunting as your bot grows and becomes more complex. By feeding the feature set into a machine learning algorithm, the algorithm will take its best guess at what needs to be done as opposed to a hard yes/no option. For example, the phrase “change my login” does not fit into our current feature model, and without a machine learning algorithm, we would return 0 results. If we used a neural network, we would have two results returned both assigned a value. We can then return the result with the higher value in hopes it is the correct choice.
The Power of Feedback
Another advantage to using a machine learning algorithm is it can self-learn. Using the example phrase above “change my login,” we would need to update our feature set manually for it to return the desired result of changing the password. Using machine learning, we can ask for feedback like “did we complete your task?” If the answer is yes, then we can backward propagate our algorithm with the original phrase thereby updating the model to incorporate the phrase into its knowledge base. Next time someone asks the same question instead of a 60/40 guess it can be a 90/10 guess, all without any intervention thus keeping our algorithm relevant without any manual updates.
In our example, our data set was relatively small, and our phrases could be broken down into a small feature set. In a broader more complex chat system this might not always be the case. Our features could be thousands of words with hundreds of entries making our feature set near impossible to manage by a person. Automation of the manipulation of the data and producing a model is ideal in a situation like this as each entry does not need to be hand fed, we can just rely on the machine and its training to deduce and categorize the new phrase, as well as make its best guess with any new phrase introduced.
So while I have shown that machine learning is not necessary to process natural language in your bot, it is a good idea to think about and incorporate into your project. The way the data is presented in the matrix gives way to easily converting the back-end system to a machine learning algorithm. We have already created our feature set; the next steps would be to use this feature set to train your classification system. When designing a chatbot, continuous development principles can help as we can a static data set and then slowly introduce machine learning concepts.
Information and material in our blog posts are provided "as is" with no warranties either expressed or implied. Each post is an individual expression of our Sparkies. Should you identify any such content that is harmful, malicious, sensitive or unnecessary, please contact firstname.lastname@example.org