What is Rasa?
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.
Install & Create Virtual Environment in Python
Install Virtual Environment
If you don’t have virtual environment, you can install it using following command :
sudo apt install virtualenv
Create and activate Virtual Environment
Before creating virtual environment, create a new directory/folder :
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 :
You can install Rasa using the below command :
pip install rasa
Create RASA Project
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:
- __init__.py ⇒ an empty file that helps python find your actions
- Actions.py ⇒ code for your custom actions
- config.yml ‘*’ ⇒ configuration of your NLU and Core models
- Credentials.yml ⇒ details for connecting to other services
- data/nlu.md ‘*’ ⇒ your NLU training data
- data/stories.md ‘*’ ⇒ 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
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.
This is how nlu.md file look like
## 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.
This is how stories look like :
## 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.
This is how the domain look like :
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!"
Train a Model
Anytime we made changes in the project we can train the model using the below command.
Talk to your Assistant
Once the model is trained successfully, we can test it using the below command.
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 email@example.com. We would be happy to offer our expert services.