Rasa AI Framework

Murat Çelik
6 min readOct 19, 2023

--

Today we will talk about Rasa Chatbot, which is the Conversational AI framework.

A creative Rasa logo

What is Rasa?

  1. Rasa Chatbot is a task oriented dialog systems that can be used as Open Source.
  2. With Rasa, we can easily build customized chatbots.
  3. The main purpose here is to be able to do the tasks that the other person wants with a two-way conversation.

Build Your Assistant

Let’s take a quick look at Rasa’s development architecture.

These are the important keywords in RASA. These keywords include the plans that we often use when setting up the chatbot architecture.

  • NLU Data
  • Responses
  • Stories
  • Forms
  • Rules
  • Entities
  • Slots

While examining these keywords in detail, we should also see the usage purposes here.

1) NLU Data

Code example for nlu.yml

> What do users want to say?

> Can users express what they want to say in different ways?

√ For an assistant to recognize what a user is saying no matter how the user phrases their message, we need to provide example messages the assistant can learn from.

√ The more samples, the more accurate the prediction.

The first and most important task of chatbot algorithms is to understand the message from the user. The image above is how Rasa handled the problem. Each sentence must match a user’s intent.

This brings us the intent classification problem. The information received from the user is evaluated and then classified as an intent. In the code seen in the image, we see how we write intents.

Another important detail here is that there is more than one sentence under the title of intent. Rasa trains a model after these details are determined. If we want the model to produce more accurate results, the sentences here should be increased.

2) Responses

> How can we return the user’s response?

> Can we return to the user with different sentences?

√ Answers are important for a good user experience.

√ The answers we will give to the user may have more than one option. Random selection can be made among them.

Dialogue is a mutual activity. The chatbot structure should generate meaningful information after receiving the message from the user. Once the intent of the message received from the user has been determined, a pre-planned response will return.

We see an example of this structure in the code. Since an answer can be given in different ways, we can specify more than one sentence. From here, Rasa chooses randomly and returns the answer.

We’ll talk about it later, but let me give you some information here. We can give the given answer not only in this way, but also with customized python functions.

3) Stories

> How do we know which reply to give after the user’s message?

> Can we create a conversation flow?

√ We can prepare a speech path. This path can also be prepared with different options.

√ Dialogue is full of possibilities that we may not know where it might lead.

Each conversation includes a specific scenario. Identifying and diversifying these scenarios gives us a good experience for the chatbot. Stories are structures used for this purpose. It provides information about which action or responses will be given after which intent.

4) Forms, Slots, Entitites

> Can we extract information from the user’s message?

> Can we keep this information throughout the conversation?

> Can we create a flow to get the required information from the user?

√ During the dialogue, information must be stored for later use. This operation is called “Fill Slot”.

√ There are also different options for this filling process.

Another issue is to receive information from the user and maintain the direction of speaking in line with this information. There are 3 main keywords here. Forms, slots and entities.

Entities are meaningful pieces of information that pass between users’ sentences. We can extract these pieces of information from sentences by following certain rules.

Slots are variables that we store information obtained from entities or in different ways for later use.

We can use entities and slots in different ways. The one we use most often is with forms. Forms are structures that allow us to receive information from the user in a sequential manner. In this way, the information received helps us in the flow of speech.

5) Rules

> Is there a rule for dialogues that will always proceed the same?

> What is the difference between Stories and Rules?

√ The rules contain short and clear conversational dialogues that are always the same.

Rules are where we define conversations that always go the same way in a dialogue. Rules should be defined concisely and clearly.

Setting up your environment

Rasa is extremely easy to install. It is easy after following the relevant steps.

# Python Environment Setup
python3 --version
pip3 --version

# Virtual Environment Setup
python3 -m venv ./venv
.\venv\Scripts\activate

# Install Rasa Open Source
pip3 install rasa

Command Line Interface

Rasa has certain command line commands.

rasa init
# Creates a new project with example training data, actions, and config files.

rasa train
# Trains a model using your NLU data and stories, saves trained model in ./models

rasa run [rasa run --enable-api --cors "*"]
# Starts a server with your trained model.

rasa run actions
# Starts an action server using the Rasa SDK.

rasa interactive
# Starts an interactive learning session to create new training data by chatting to your assistant.

# many more ...

Language & Policies

There are pre-train models integrated with many languages in the Rasa architecture. By fine-tuning these models, you can continue chatbot operations easily and in a short time. If you want to add your own model, that is also possible.

A model in Rasa has some rules in terms of structure. It is possible to change these rules under policies. This may include details such as the epoch value of the trained model or how many previous messages it should take into account when estimating.

Pipeline

Language models contain many algorithms. These algorithms can also be algorithms that preprocess sentences before the prediction model. The choices here also affect the complexity and success of the model. Having many different techniques and being integrated with Spacy makes Rasa valuable.

--

--