Day 5 of 100DaysofML

Charan Soneji
100DaysofMLcode
Published in
4 min readJun 21, 2020

Rasa, its a platform which is used by almost all companies that try to deploy chatbots on their websites in order to guide customers and help them around with FAQ’s.

What exactly is RASA?
Let’s take a look at a picture in order to identify what RASA based chatbots are capable of doing.

RASA chatbot example

RASA helps us build intent based classifiers with ease. But, you may ask, HOW ARE THESE CHATBOTS BETTER THAN OTHER CHATBOTS?
We may build other intent based chatbots and train them but the thing that is different is the way in which they are trained. RASA allows us to define the intent and the types of texts/inputs that the chatbot may obtain from it and how to respond to those queries. It is all made easy for the user building or training the chatbot. Even the process of training the chatbot is made easy after the intents and responses have been added using simple commands.

A little about RASA Architecture.
I’m going to start by displaying a message flow diagram.

Taken from RASA documentation

For any message that comes in, it is first taken to the interpreter which is part of the RASA NLU (will come to this in a bit) to try and understand the message. It then moves onto the tracker which tries to maintain a sort of session with the user or the session state with the user. From the tracker, it moves onto the Policy whereby the intent is checked and the next action or response is noted. Once this is done, the chatbot gives back a response which is shown in the diagram as Message Out.

RASA X
This is another important tool that can help us with visualization of RASA based architecture. Great conversational AI can only be developed with proper training based on real-life assistants. RASA X is a toolset that helps you leverage conversations to improve your assistant. As soon as you have built a minimum viable assistant, one that can handle the most important happy path stories, RASA X helps take it to the next level.
NOTE: RASA and RASA X are different in terms of the interface. RASA helps us in interacting with the chatbot through the CLI unlike RASA X which gives us additional functionality and it usually runs on a local server.

RASA Stack

Components of RASA stack

The main components of RASA are demonstrated above.
1. RASA NLU: Rasa NLU is an open-source natural language processing tool for intent classification, response retrieval and entity extraction in chatbots. For example, taking a sentence like

"I am looking for a Chinese restaurant in the center of Bangalore"

The intent after classification is obtained as:

{
"intent": "search_restaurant",
"entities": {
"cuisine" : "Mexican",
"location" : "center"
}
}

That's just a gist about RASA NLU.

2. RASA Core: RASA core is the dialogue engine for building AI assistants. Rather than a bunch of if/else statements, it uses a machine learning model trained on example conversations to decide what to do next.
With Rasa Core, you manually specify all of the things your bot can say and do. We call these actions. One action might be to greet the user, another might be to call an API, or query a database. Then you train a probabilistic model to predict which action to take given the history of a conversation.

One of the key things to note is that these models use RL or Reinforcement Learning which is Data Hungry. It requires a large amount of data to be trained. This is one of the reasons, RASA based chatbots give a pretty good response.

Installation of RASA
This is something that took me quite some time to figure out myself. So if you have anaconda installed on your machine, I would recommend it. It made things very easy for me too. Once you open Anaconda, create your own environment in order to run your own RASA environment.
Some of the precautions that you should make sure to take are to check your Python Version. RASA does not support Python 3.8. So make sure you have any version below that (I personally used Python 3.6). Navigate to the folder inside visual studio which contains the buildtools and run the following command:

pip install rasa #To install rasa
pip install rasa-x — extra-index-url
https://pypi.rasa.com

Once this is done, you can go to the folder where you want to create the RASA based bot and run the command rasa init which will create all the files required for rasa to run. Some of the other commands that you can use from your conda terminal to run features on your conda bot are:

rasa train #command used for training
rasa shell
#chat with chatbot in command prompt
rasa interactive
#chat and correct the bot in command prompt
rasa run actions -vv
#To be run if new actions have been initialized(logically)
rasa run -m models — enable-api — cors “*” 5021
#Command used to start rasa API

I hope I could be of some help and pass on some information. That's it for today. Keep Learning.

Cheers.

--

--