The Rasa is an open-source Machine learning framework particularly developed for building chatbots. You can build your contextual assistant using Rasa. Rasa has the Machine learning-based approach to learn the conversational data.
In this tutorial we will see, how to install rasa, what are intents, stories and actions in rasa, and how to train and test the rasa model.
If you don’t have virtual environment, you can install it using following command :
sudo apt install virtualenv
Before creating virtual environment, create a new directory/folder :
mkdir rasaDemo
cd rasaDemo
Now create the virtual environment by the given command :
virtualenv env_name --python=python3
Once you have created the virtualenv, activate it using the following command :
source env_name/bin/activate
You can install Rasa using the below command :
pip install rasa
Before creating Rasa Project make sure you are in the directory “rasaDemo”.
To create a rasa project run the following command:
rasa init --no-prompt
This creates the following files:
Note : The files with ‘*’ marked are the important files.
Intent can be understood as labels that are attached based on the overall goal of user’s message. For example, a user input ‘Hello’ or ‘Hi’ may call the intent ‘greet’. Training phrases are the user input, that for greeting users may say: ‘hello’, ‘hi’, ‘hie’, ‘hi there’ etc.
In Rasa, you can create the intent and add the training phrases in the data/nlu.md file. You can see some intents are already there in the nlu.md file.
## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there
## intent:goodbye
- bye
- goodbye
- see you around
- see you later
## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good
Where “greet” & “goodbye” are intent names, and they are defined using the (##) double hash followed by the “intent” keyword, and then below to it are the training phrases.
Stories are written in a specific format and stored in the stories.md file. When we create the rasa project, the stories.md file is automatically created in the data folder, the file has few simple training stories.
You will find a Stories.md the file that contains story data. Stories are example of end-to-end conversations. Story has the structure where we have the user message and how our assistant will respond to those messages. We can also say that stories contain the flow of conversation.
## happy path
* greet
- utter_greet
* mood_great
- utter_happy
Where happy_path is the name of the story, “greet” is the intent name and “utter_greet” is the action. Actions contain the bot responses.
The domain.yml file contains the intent name and the action definition. The action name that we have used in the stories.md file i.e “utter_great” & “utter_happy” we will define that in this file.
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
responses:
utter_greet:
- text: "Hey! How are you?"
utter_happy:
- text: "Great, carry on!"
Anytime we made changes in the project we can train the model using the below command.
rasa train
Once the model is trained successfully, we can test it using the below command.
rasa shell
Using “rasa shell” you can test your assistant through the command line.
In the next tutorial, Chatbot Development Tutorial: Introduction Of Intent, Stories, Actions In Rasa X, we will see how we can use Rasa X to add the intent, responses, and stories using the UI.
Feel free to comment your doubts/questions. We would be glad to help you.
If you are looking for Chatbot Development or Natural Language Processing services then do contact us or send your requirement at letstalk@pragnakalp.com. We would be happy to offer our expert services.