Chatbots- Connecting Artificial Intelligence and Customer Service
By: Heena Rijhwani
Tags: Artificial Intelligence, Chatbots, Cosine Similarity, Customer Service, Count Vectorizer

Every business revolves around customers and interactions carried out with customers. It is said that a customer is the boss of a business and every interaction with him counts! An infallible way of dealing with this pressing subject is the use of Chatbots. Chatbots are used to conduct an online chat conversation via text or text-to-speech and provide direct contact with a live human agent. With rising demands all over the world, they have gained immense popularity and are widely used in a myriad of industries to render a pleasant and uniform customer experience. They can be used to answer FAQs, handle customer queries and grievances, manage bookings, make recommendations, CRM and provide 24*7 customer support. They can be rule-based or have Natural Language Understanding.

Let’s look at some applications of Chatbots:

Accessible anytime

Handling Capacity

Flexible attribute

Customer Satisfaction

Cost Effective

Faster Onboarding

Work Automation

Alternate sales channel

Personal Assistant

Chatbots can be integrated with various platforms such as Google Dialogflow, Microsoft Bot Builder, Amazon Lex, RASA and Wit.ai.

Aim and Scope

Whether it is for placing orders or recommending products, most businesses today use Chatbots to provide an efficacious customer experience and obtain a competitive advantage.

Here we will look at the steps involved in building a chatbot to help customers streamline their orders for a pizzeria. Perusing menus and placing orders can often be a cumbersome and time consuming task. This Chatbot aims to rule out tedious steps of flipping through menus and offers a personalized and customized experience. It will recommend a particular dish to the users based on their choice of ingredients and help provide a smooth user experience.

What type of pizza should you order if you enjoy basil on your pizza? What are you most likely to relish if you love pineapple? Which pizza would be best suited for olive lovers?

The bot will instantaneously answer all these questions are more! It will welcome customers to a pizzeria and recommend them a particular type of pizza they are most likely to devour based on their preferred ingredients and toppings. It will also simply take orders from the user and be a promising expression of efficiency, availability, interactivity and customer loyalty.

Steps

We create the bot using Python and RiveScript. In order to train the bot a dataset needs to be created. For the purpose of demonstration, I will be using a small dataset consisting of 50 records and 2 columns “Pizza name” and “ingredients.”

The first step is to import essential libraries we will need.

RiveScript is a simple and user-friendly scripting language for Chatbots. It is a rule-based engine, where the rules can be created by us. These use a scripting metalanguage (simply called a “script”) as their source code.

The next step is to set up the bot dictionary.

Next, we will use two concepts:

Count Vectorizer

Cosine Similarity

Count Vectorizer is used to transform a given text into an n*n matrix on the basis of the frequency of each word that occurs in the entire text.

For instance,

Data= [‘The’, ‘Bot’, ‘will’, ‘recommend’, ‘pizzas’, ‘for’, ‘the’, ‘customer’]

Cosine Similarity is a concept commonly used in recommendation systems. It is a measure of the similarity between two non-zero vectors of an inner product space. To understand it better, consider two points, P1 and P2, in a multi dimensional space. Mathematically, the lesser the distance between the two points, the more similar they are and as distance increases, the similarity between them decreases. Cosine Similarity depicts how similar the two points are by taking cosine of the angle between them. It ranges from -1 to +1. It compares how similar documents are by considering the arrays containing the word counts of the documents.

The next step is to create a function to get replies from the bot. If the value returned by the previous function is not ‘0’, the bot will recommend a particular type of pizza the user is most likely to enjoy.

The last step is to write a code for the Flask app.

This is what your rivescript will look like:

You can customize it based on preferences or business requirements.

Lastly we must build a User Interface for our bot in order to create a personalized branded experience and enable efficient communication with customers to serve them better.