AI for Business: Developing Chatbots
AI for Business: Developing Chatbots
How can you use an AI chatbot for business and why should you? Look at an example of a virtual assistant.
Join the DZone community and get the full member experience.Join For Free
Oracle reports that 36 percent of companies have already implemented chatbots to service customers, and 44 percent are going to follow their example. Chatbots seem to be everywhere: they arrange pizza delivery, schedule doctor’s appointments, book plane tickets, find available hotel rooms, and so on. They not only reply to customer’s requests 24/7 but also grab the target audience’s attention. By using chatbots, businesses gain a competitive advantage faster than their competitors who use human-only chat.
How can you use an AI chatbot for business and why should you? Look at an example of a virtual assistant that we developed for our HR department.
How a Smart Chatbot Works
Natural language processing technologies allow a chatbot to recognize preloaded words and consider the context, form, and parts of speech of the sentence simultaneously. For example, you can train a chatbot to identify several questions in one message and get the same meaning of “How can I pay for the order?” and “Could you please tell me the possible payment methods?” Also, smart chatbots can ask follow-up questions to acquire additional context and provide even better results.
Benefits for Businesses
- Automate repetitive processes
- Provide rapid feedback to customers 24/7
- Reduce call center costs
- Remove the human factor
- Integrate with information systems
Banks, online shops, HoReCa, travel agencies, telecom companies, and courier and transportation services all choose to integrate AI chatbots as part of their customer service team.
How We Developed a Chatbot for our HR Department
Typical questions from colleagues like “Could you please tell me how to get holiday pay?” or “How can I get compensation for sport?” are a pain point that HR professionals experience every single day. They distract from focusing on crucial tasks. So we came up with an idea of how to achieve a win-win result: to lift the burden of routine processes from the HR department and provide quick answers to coworkers. The decision was to develop a smart chatbot that would take over repetitive consulting activities.
The Project Stages
1. Develop an Architecture of a Chatbot That Doesn’t Ask Questions
First, we defined the requirements for our chatbot:
- The Chatbot has to respond to user requests.
- The Chatbot has to give a natural conversational experience.
Before development, we created a chatbot architecture that couldn’t ask questions in response but still managed to fulfill user requests.
The request processing algorithm turned out to be quite simple:
- Convert a user’s phrase from text to numeric vector.
- Process a numeric vector with a User Intent Classifier.
- Choose a phrase that fulfills the user request from a list of prepared phrases corresponding to User Intent.
The simplest chatbot architecture
2. Define User Intent Using a Decision Tree Approach
We chose a decision tree model to define User Intent. To process phrases, we converted it into a numeric vector using a bag-of-words algorithm. A numeric vector is an array of numbers where each number shows how many times a word appeared in a sentence.
As you can see, the word “inquiry” is repeated in a sentence twice, so it corresponds to number 2. And there is no “analysis” in the sentence, so it corresponds to 0.
An example of how we converted a sentence into a numeric vector using the bag-of-words algorithm
Before transforming a sentence into the numeric vector, we did preprocessing — removed the most frequently used words: conjunctions, prepositions, etc. In this vector, we consider all the words that can occur in the user’s message.
The final scheme of a chatbot and user communication based on the decision tree
We used DecisionTreeClassifier from the scikit-learn library to classify users intentions. The bag-of-words algorithm performed very well even when there were unfamiliar words.
A dialog with a smart chatbot based on the bag-of-words algorithm
3. Develop an Architecture of a Chatbot That Asks Questions and Executes Queries
We changed the chatbot architecture so that our virtual assistant can ask questions to users.
We added a new entity action that defines what should be done to perform a user request. Imagine this situation: web-developer, Pete, asks a chatbot to find out his coworker, Maria's, phone number. The bot sends a request to the database with the coworkers' contacts to provide Pete with the required phone number. To fulfill such a request, all the actions need to be performed. Thus, the chatbot not only answers a user with a predefined phrase but also takes actions to create a new phrase in response to the user’s question.
We also created an entity: DataEntity. It shows data that needs to be required from a user.
If a chatbot doesn’t understand what a user wants, it expects an input phrase. When a user says something, the chatbot tries to understand the intent. In this case, there are three possible situations:
- If the chatbot manages to do it, it tries to perform an action to satisfy the user request.
- If there is enough data to perform the request, the chatbot performs an action and forgets about the user request as it thinks that already did it.
- If there isn’t enough data to perform an action, the chatbot asks the user for missing information.
This is how a chatbot and a user interact with each other:
The architecture of interaction between a user and a chatbot
4. Change the Model in Favor of Neural Networks
The decision tree based on bag-of-words showed quite good results in text recognition. But the more intentions a chatbot recognizes, the bigger its vocabulary. That means the number of elements in bag-of-words vectors that are processed gets bigger. So, training the chatbot with a decision tree took more and more time.
We decided to carry out an experiment: to train neural networks to determine users' intention and see how this would work out.
To convert phrases into a numeric vector, we used the already trained word2vec model from the open Facebook AI repository. This model defines the corresponding vector of every word.
We tried a multilayer perceptron architecture for this purpose. Numeric vectors of words formed a numeric vector of a phrase. But this model turned out to be unstable to new words that are familiar to the word2vec model but were not mentioned during training.
We chose a neural network model with a bi-directional LSTM layer.
The architecture of the recurrent neural network with a bi-directional LSTM
The neural network analyzed each word separately and considered neighboring words. Based on that, it correlated a phrase with an intention. The model managed to recognize what the user wants very well.
As a result, we:
- used the new neural network model to classify phrases in accordance with intentions
- got a chatbot that replies to user’s questions and asks questions if needed
Example of a conversation with a neural network-based chatbot
5. The Result
We created a chatbot in several steps:
- Created a neural networks model that classifies user’s intent by input phrase.
- Figured out that to convert words to numeric vectors, it’s better to use the word2vec model instead of the bag-of-words algorithm.
The model showed good results with 99.9 percent accuracy in understanding natural language during a conversation.
We’re going to continue the research: add new user intentions and implement data search in user’s phrases.
Why Your Business Needs a Smart Chatbot
Chatbots save you time and money and enhance client loyalty. The smarter and more helpful a chatbot is, the more your clients will like it. Virtual assistants are especially beneficial for B2C businesses, where employees spend a lot of time on routine tasks.
Now, it’s not enough to have a simple chatbot. Virtual assistants should recognize natural language, understand dialog context, and analyze interaction with users. According to Global Market Insights, the global chatbot market is expected to reach $1.34 billion by 2024. AI will broaden their functions. It’s time to think of developing a smart chatbot for your business before your competitors!
Opinions expressed by DZone contributors are their own.