What is Rasa?
Rasa is an open-source machine learning framework for automated text and voice-based conversations. Rasa(chatbot) 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 use cases which can be a market changer. Rasa is a rule-less framework so, you don’t have to worry about putting your data on someone’s server or cloud as in Microsoft LUIS, Dialogflow, or Amazon aLexa.
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
"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 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 places a major and the most essential part of generating the reply messages for a chatbot. It considers the output of Rasa NLU (intents and entities) as an input and applies machine learning models to respond with a bot reply.
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 aspect.
Now let’s get started with the building of Rasa chatbot:
Step 1. Install Python Development Environment
Create a directory anywhere on your system and the change to that directory while using it on the 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 reset this path as per your project suitability)
$ python3 -m venv --system-site-packages ./venv
and to activate the environment :
$ source ./venv/bin/activate
C:> python3 -m venv --system-site-packages ./venv
and to activate the environment:
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 https://pypi.rasa.com/simple
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:
__init__.pyan empty file that helps python find your actions
actions.pycode for your custom actions
config.yml‘*’ configuration of your NLU and Core models
credentials.ymldetails for connecting to other services
data/nlu.md‘*’ your NLU training data
data/stories.md‘*’ your stories
domain.yml‘*’ your assistant’s domain
endpoints.ymldetails for connecting to channels like FB messenger
models/<timestamp>.tar.gzyour 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.
Check out this link for details and clarification,
Time to wrap up now. Hope you liked our content on How to build an end-to-end conversational chatbot with Rasa. See you in our next blog, thanks for reading our blog and do leave a comment below to help us improve the content to serve you all of our experience with you. Stay tuned with us for more Rasa Chatbot contents.
So stay tuned and for now Happy Learning.