How to build a conversational AI assistant with Rasa

KARTHIK
5 min readJul 18, 2023

--

This blog post will walk through the steps involved in building a conversational AI assistant using Rasa.

SYNOPSIS OF TODAY’S AGENDA

  1. INTRODUCTION TO CHATBOTS
  2. WHAT IS RASA FRAMEWORK
  3. RASA ARCHITECTURE
  4. RASA INSTALLATION
  5. RASA FILE STRUCTURE
  6. ENDING NOTES

INTRODUCTION TO CHATBOTS:

A chatbot is a computer program that will respond to human conversation. Chatbots are often used in customer service applications, where they can answer questions, resolve issues, and support customers 24/7. Chatbots can also be used for other purposes, such as providing information, booking appointments, or selling products.

How do chatbots work?

Chatbots use natural language processing (NLP) to understand human language. NLP is a field of computer science that deals with the interaction between computers and human (natural) languages. Chatbots use NLP to analyze the words and phrases a user types or speaks, generating a response relevant to the user’s query.

Types of Chatbots:

There are two main types of chatbots:

Rule-based chatbots and Machine Learning chatbots.

Rule-based chatbots are programmed with a set of rules that define how they should respond to specific inputs. This rule-based chatbot cannot explore many perspectives.

Machine learning chatbots, on the other hand, are trained on a dataset of human conversations. This allows them to learn how to respond to new inputs more naturally and engagingly.

RASA FRAMEWORK:

RASA is an open source Machine learning framework that is used to create AI chatbots using Python and NLU(Natural Language Understanding).

Why RASA Framework?

  1. Open Source
  2. 24/7 Availability
  3. Large Scale
  4. Powerful Functions

Before getting inside RASA there are a few basic terms that you need to understand

UTTERANCE

INTENT

ENTITY

Utterance is simply the input given by the user, that is when the conversation is initiated by the user to the chatbot, the input given by the user is called as Utterance.

Intent is the intention or the context of the user message. Once the utterance is received by the chatbot it has to react according to the user's utterance. So RASA uses Machine Learning(SVM) to classify the text and the intention is found out.

Entity is the additional information that is present in the user utterance.

for example, if the user query is: “ Book me a table for tonight’s dinner.”

Utterance: Book me a table for tonight’s dinner.

Intent: Booking a table.

Entity: Tonight for dinner

RASA has Three main components:

  1. RASA NLU
  2. RASA CORE
  3. Channels

RASA NLU:

RASA NLU is a RASA Natural Language Understanding which is used to get the utterance from the user and to find the intent and the entity from the user utterance.

RASA CORE:

RASA CORE gets input from the RASA NLU and based on the information that is classified on the RASA NLU the immediate and related actions are taken by the RASA CORE.

CHANNEL:

Channels will allow the user to connect the chatbot connect to the backend like databases.

RASA ARCHITECTURE:

Message-In is the user utterance given to the chatbot.

Once the utterance is received by the chatbot the Interpreter will get the utterance, classifies the intent, and extracts the entity from the utterance. (RASA NLU)

Tracker will always keep track of the user and chatbot conversation.

After the user intent is known the chatbot has to take decisions based on the conversation; which is done by the policy. (RASA CORE)

Then the real action of how to respond to the utterance is taken care of by the actions part and the resulting response is given to the user as a reply.(RASA CORE)

RASA INSTALLATION:

Up until now, we have discussed the main concepts involving the RASA chatbot creation, now let’s get our hands dirty.

INSTALLATION

To install RASA on your local PC, follow the commands specified below

pip install rasa

once the installation is done we have to set up the rasa.

rasa init

rasa init will set an environment and creates a sample chatbot with which we can interact.

Once you have developed your custom chatbot we can use the below command to train and work on our chatbot.

rasa train

RASA FILE STRUCTURE:

Once the installation is done, it will as you to set up an environment in a directory, after you have set up an environment this is what it looks like.

nlu.yml

nlu.yml file is used to train the basic conversation to the chatbot, this is the file also where how a user might initially interact is stored. It stores intent, synonym, regex, and lookup.

stories.yml

stories.yml is the file that contains the intents topic and the topic of response. It is the file that will help the chatbot to have a short conversation with the user,i.e. if the intent is identified what action has to be done.

domain.yml

domain.yml file is where the responses to all intent entity stories slots are present. It is the master file that contains all information.

User utterance is given intent is known by nlu.yml file and the stories.yml will define what should be the response and domain.yml file has the response command to the related user utterance.

actions.py

actions.py file is used to perform custom actions that the chatbot is supposed to perform based on the requirement/domain-specific actions eg. API calls, fetching data from databases, etc.

ENDING NOTES:

The future of chatbots is bright. As technology continues to evolve, chatbots will become more sophisticated and able to handle more complex tasks. Chatbots are also becoming more integrated with other technologies, such as artificial intelligence (AI) and machine learning. This will allow chatbots to learn and adapt in real-time, which will further improve the customer experience.

I hope this introduction to chatbots was helpful. If you have any further questions, please do not hesitate to ask.

--

--

KARTHIK
KARTHIK

Written by KARTHIK

“I do not fear this new challenge. Rather like a true warrior I will rise to meet it.”

No responses yet