Providing Suggestions to Users along with Original Intent Answer

January 06, 2023

In the age of chatbots, it is hard to anticipate the various pathways that a user may take while conversing with a chatbot, making it difficult to create a chatbot that can answer every enquiry from the user. 

To make sure the user has something to ask about and that lies in the scope of the chatbot we can give suggestions to the user in the form of buttons on which different queries are written. Users can click on any of the provided buttons or can type their own questions.

This helps in two ways:

Example Scenario

There is a chatbot that is trained in such a way that it can handle user queries related to the general concepts of machine learning. The goal of this chatbot is to provide definitions of different concepts that are there in machine learning like “what is mean square error?” or “what is linear regression?” etc.

Suppose a user comes and asks “What is linear regression?” and the chatbot will provide an answer for it and that’s it, now it’s up to the user whether he/she wants to ask something else or not.

Now, consider another scenario where the user asks the same question “what is linear regression?” but this time along with the answer to the user’s query chatbot provides a list of suggestions that are similar to the user’s query. This would give rise to curiosity in users’ minds and tempt them to click on one of the suggested buttons leading to a longer and better engagement with the user.

Before starting with implementation let’s first set up RASA on our system

The very first thing that you need to do is create a virtual python environment for which you can use one of the following

I will be using miniconda to create the virtual environment (Anaconda will be used in a similar manner).

Steps to follow:

Once rasa is installed we are ready to initialize a new project using rasa.
Following are the steps –

Let’s make the required changes to the files and train the model.

Letā€™s discuss the approach that will be used for providing suggestions to the user.

Implementation

  1. Firstly we need to create a global dictionary that will have the intent name as the key and the value would be an example query for that intent.

     
  2. We will implement the run method of custom action
    1. Firstly, we need to return an answer for the userā€™s query. In this example, I will be returning the intent name to which the query is classified. To do so we can use the tracker as follows
      tracker.get_intent_of_latest_message() – this will return the intent name
    2. Now, to show this to the user we can use the dispatcher as follows
    3. Now we need to loop over all the intent classifications based on the ranking and create buttons that will be shown to the user as suggestions. We also need to make sure the buttons generated are only from the dictionary that we have defined in step one this will help us in making sure that the intents like ā€œgreetā€, ā€œout of scopeā€, ā€œgoodbyeā€ etc. are not shown to the user as the suggestions (because intent ranking would be having these intents too).

      In the end we have also placed a check to make sure we can control the max number of suggestions shown to the user.

Training model and having a conversation with it


References: https://rasa.com/docs/rasa/

Contributors: Mr. Bavalpreet Singh and Lovepreet Singh