Building an end-to-end Conversational Chat-bot cum Assistant with Rasa



What is Rasa?

Rasa is an open source machine learning framework for automated text and voice-based conversations. Rasa is helpful in understanding messages, holding conversations and connecting to messaging channels and APIs.

The very good thing about Rasa is you are not tied to any pre-built models or use cases (like Dialogflow, etc). So, due to this very good reason you can customize your usecases which can be a market changer. Rasa is a rule-less framework so, you don’t have to worry about about putting your data on someone’s server or cloud as in Microsoft LUIS, Dialogflow or Amazon Lex.

There are two main components of Rasa: Rasa NLU and Rasa core

Now let’s understand both of them one by one to understand the clean and proper architecture of RASA.

Let’s first understand what is Rasa NLU? Rasa NLU is an open-source natural language processing tool for intent classification and entity extraction in chatbots. Let’s understand is with an example like

I need a taxi for 5 people

and the returned structured data will be like

	  "intent": "taxi_booking",
	  "entities": {
	    "service" : "taxi",
	    "P_COUNT" : 5

Here what’s happening internally is that by default Rasa NLU is using Bag-of-word(BoW) algorithm to find intents and Conditional Random Field(CRF) to find the entities. But you can also use different algorithms to find the intents and the entities using Rasa by the creating a custom pipeline and setting up the algorithms accordingly.

The main reason why open source NLU is used are:

- All your training data is not dependent on Google, Microsoft, Amazon or facebook.

- Machine Learning is not one-size-fits all. You can tweak and customize models for your training data.

- Rasa NLU runs anywhere you want, so you don’t need to make any extra network request for every message.

Now, let’s understand what is Rasa Core? Rasa Core place a major and the most essential part in generating the reply messages for chatbot. It consider the output of Rasa NLU (intents and entities) as an input and applies machine learning models to response with a bot reply.

Fig. Basic step by step working of Rasa Application

Building a Rasa chatbot

Previously if you were using the Rasa to build a chatbot than it was a bit complicated to build a chatbot and also there was no UI(user interface) available to test the working and functionality of your Rasa chatbot. But since after the release of Rasa-X its been very easy and interactive for us to get started with the building of Rasa chatbot with UI to interact with the bot, also we can share our bot with our loved ones to help them in every aspects.

Now let’s get started with the buidling of Rasa chatbot:

Step 1. Install Python Development Environment

Create a directory anywhere on your sytem and the change to that directory while using it on terminal/command prompt.

Check if you already have the configured python environment on your system

$ python3 --version

$ pip3 --version

If the above packages are already installed on your system then it will show you the versions in output. Otherwise,Open terminal or command prompt and try this

For Ubuntu users:

$ sudo apt update

$ sudo apt install python3-dev python3-pip

For macOS users:

$ brew update

$ brew install python

For Windows Users:

Make sure the Microsoft VC++ Compiler is installed, so python can compile any dependencies. You can get the compiler from Visual Studio. Download the installer and select VC++ Build tools in the list.

Install Python 3 (64-bit version) for Windows.

C:\> pip3 install -U pip

Step 2. Creating a Virtual Environment

To create a virtual environment in ubuntu/macOS we have tools like virtualenv and virtualwrapper that provide isolated python environments. To create a virtual environment using them you don’t need any root privileges.

Create a new virtual environment using python interpreter by setting the directory in your current directory as ./venv (you can re set this path as per your project suitability)

For Ubuntu/macOS:

$ python3 -m venv --system-site-packages ./venv

and to activate the environent :

$ source ./venv/bin/activate

For Windows:

C:\> python3 -m venv --system-site-packages ./venv

and to actvate the environment:

C:\> .\venv\Scripts\activate

Step 3.Install dependencies for spacy

Install the dependencies for spacy using the below commands:

$ pip install rasa[spacy]

$ python -m spacy download en_core_web_md

$ python -m spacy link en_core_web_md en

Step 4. Install Rasa X to your system

Use the below command in terminal/command prompt to install Rasa X to your system

$ pip install rasa-x --extra-index-url

Step 5. Building a simple Rasa X chatbot

After your are done with the installation of all the packages and the dependencies for Rasa X in your virtual environment. Now run the following command in the terminal/command prompt to create the example chatbot provided by Rasa to have a basic understanding of how does the Rasa X chatbot works, So that you could further customize the your Rasa X chatbot accordingly.

$ rasa init --no-prompt

When this will be successfully done. It will create different files and directories in your current directory in the format as shown below: an empty file that helps python find your actions code for your custom actions
config.yml ‘*’ configuration of your NLU and Core models
credentials.yml details for connecting to other services
data/ ‘*’ your NLU training data
data/ ‘*’ your stories
domain.yml ‘*’ your assistant’s domain
endpoints.yml details for connecting to channels like fb messenger
models/<timestamp>.tar.gz your initial model

Also when this command will run it will train your model for the first time automatically by using the complete data in the structured format as you can see above. You will have a complete description about all these file in the next blog in brief.

Step 6. Chatting with the Rasa X chatbot

When we are done with all the steps above and it’s time for you to start chatting with our very first chatbot made by you. Now to check the working of your chatbot run the following command in the terminal/command prompt

$ rasa x

this command will open your interactive Rasa X chatbot in the browser and if in case it doesn’t open automatically the copy the link from the terminal and paste it in the address bar of the browser and hit enter to start talking to your bot.


I hope you have enjoyed building your first Rasa X chatbot and you have learned so many new things today. But this is just the beginning. In our next blog you will learn all about the brief description of the all the Rasa NLU and Rasa core files that has been generated during the creating of the project. So stay tuned and for now Happy Learning.



One thought on “Building an end-to-end Conversational Chat-bot cum Assistant with Rasa

Leave a Reply

Your email address will not be published. Required fields are marked *