Build a chatbot using Rasa
Rasa is an open-source machine learning framework to automate text-and voice-based conversations. Building contextual assistants & chatbots that help customers is hard. Rasa provides infrastructure & tools necessary for high-performing, resilient, proprietary contextual assistants that work. With Rasa, all developers can create better text- and voice-based assistants.
Rasa Open Source includes
- NLU: determines what the user wants and captures key contextual information
- Core: selects the next best response or action based on conversation history
- Channels and integrations: connect assistant to users and backend systems
Rasa X is a toolset that helps you leverage conversations to improve your assistant.
Now, Let’s dive into coding.
Well, if you know nothing about coding, still you can do it. Have Patience!!
Step 1: Create & Activate Virtual environment
Before Installing Rasa, it’s highly recommended to use a Virtual Environment, to keep the installations clean and together at one place.
cd <your project directory>
sudo apt-get install python3-venv
python3 -m venv env
source env/bin/activate
Step 2: Install Rasa
If you are having TensorFlow errors, then use these to install the addons.
pip install --upgrade pip
pip3 install --upgrade tensorflow-addons rasa
To install Rasa, use these commands. I have used rasa version 1.5.0.
pip install rasapip install rasa_nlu
pip install rasa_nlu[spacy]
python -m spacy download en_core_web_md
python -m spacy link en_core_web_md en –force
This will take some time to finish. Make sure, that there are no dependency errors.
Step 3: Initialise rasa
rasa init
After 100 epochs, you will get a prompt saying “Do you want to speak to the trained assistant on the command line?”. Please select ‘No’.
← After Initialisation, the directory structure should look like this.
Step 4: Customise your model
To customise your model, you need to modify these files.
nlu.md
stories.md
domain.yml
credentials.yml
To modify the files, you need to know these terms.
- Intents: What Does the User Say. Rasa uses the concept of intents to describe how user messages should be categorized.
- Response: How the bot replies to the query. If you want your bot to respond to user messages, you need to manage the bot’s responses.
- Story: It is a representation of a conversation between a user and an AI assistant, converted into a specific format where user inputs are expressed as corresponding intents while the responses of an assistant are expressed as corresponding action names.
nlu.md
In nlu.md file, we save the intents. Rasa uses this concept to describe how the user will interact with the bot. You must mention the different ways to trigger a particular intent. Like hey, hello, hi, etc. all will trigger the greet intent.
domain.yml
In domain.yml, we save the responses and actions (the initial model don’t have any actions). Rasa uses this concept to describe how the bot will respond to the user.
stories.md
Finally in stories.md, we will describe the flow of conversation. You don’t need to mention every possible path. Rasa will pick the most suitable path, based on confidence value.
credentials.yml
If you want to deploy the bot on various apps like messenger and slack, then create a developer account for that app. Then save the tokens in credentials.yml .
You can also explore the other files like config.yml, and change it as per requirements,
Step 5: Train your new model
After all the modifications, it’s time to train your new model.
rasa train
Step 6: Test your Bot
Let’s say Hello to the new chatbot. Now you can deploy it on various apps, or you can also run in your terminal. To run it on your Linux terminal,
rasa shell
It’s time to develop your new chatbot..
Happy Learning!!
For any queries, contact me at LinkedIn