Rasa Open Source: Basic Name Bot

UTSAV VORA
5 min readJun 8, 2021

Introduction

Rasa is an open-source framework for developing chatbots. It has several usages such as understand messages, hold conversations, and connect to messaging channels and APIs. It is incredibly powerful and even used for developing AI-powered, industry-grade chatbots. Today we will learn about the basics of RASA and see how we can build a basic name-bot.

If anyone wants to have a look at the code then here is my Github repo.

How to download RASA?

Rasa can be used in any code editor that supports Python 3.6 or higher versions. In this blog, I have used PyCharm Editor. The following steps are to be used for installing it:

At first, let’s install rasa: pip3 install rasa

Second, create a new project: rasa init

Then choose whether to keep the entire rasa project in the same directory or, some other directory and press enter. Finally, a basic chatbot will be trained and the directory will look like this:

The initial structure of the project

This indicates that rasa is successfully downloaded and now we can make changes that we require.

Intents

Rasa Intents usually include the user’s intent and any entities their message contains. All the intents should be inside the nlu.yml file with proper syntax, a suitable name, and at least 2–3 examples. For our NameBot, the nlu.yml file content is:

nlu.yml file

Here, “ask_name”, and “tell_name” intents are added along with the already available intents in the nlu.yml file. Here, “name” indicates an entity. The Entities are structured pieces of information inside a user message that can be used further in the conversation. We will see how they are declared in the domain section.

Lookups

One can use lookup tables to help extract entities that have a known set of possible values. Keep your lookup tables as specific as possible. Here, we have used a lookup table for our Name Bot to get familiar with some names.

name.yml

Note: The name of the lookup table should be the entity name for which you want the lookup table. The lookups should always be maintained in different yml files, this in return helps in doing various other operations using custom actions and forms. The way they should be saved is:

structure to save lookups

Stories

Stories are representations of a conversation between a user and an AI assistant. All the stories must be saved in the stories.yml file. Let us see the simple story for our Name Bot:

stories.yml

A story should always have a unique name and the syntax of writing should always be maintained properly.

Domain

The domain.yml file in rasa contains all the intents, entities, responses, or any other functionality used. Whenever we create any intent or entity then we must always add it here. Let me show you the content of my domain file:

domain.yml (1st part)

As it can be seen we have added the entity and intents used in the previous sections, here. We have also used slots. Slots are also called as bot’s memory. They act as a key-value store that can be used to store information the user provided (e.g name) as well as information gathered about the outside world.

Note: If the slot name is similar to that of the entity name then the value stored in the slot is automatically stored in the entity.

domain.yml (2nd part)

The above picture contains the response section of domain.yml. The actions in the story section are responses. Responses are messages that your assistant sends to the user. A response is usually only text, but can also include content like images and buttons.

Note: The name of responses should always start with utter_(the name you want to keep). In case of asking for a specific entity or slot, the response name should start with utter_ask_(entity/slot name). Well, one can put a custom format under a response.

How to Run?

To run the assistant, you may go through the following steps:

Step1: rasa train — This will train your model on the NLU Training Data provided by you.

Step2: rasa shell — This will run your assistant in the terminal and you will be able to talk with your assistant.

Note: Using debug mode(--debug) gives us a lot of understanding about how our assistant is working and is it able to predict correct action to perform and intents.

rasa shell — having a convo with Name Bot

Conclusion

We learned about how to work with simple intents and stories in Rasa, however, there is more than that obviously that Rasa can do but it would have made this blog a newspaper. Therefore, I will be coming up with another blog on Rasa where we will learn about Custom Actions, Forms, Rules, and even how to connect it to Postman. So stay tuned !!!!

--

--

UTSAV VORA

I am an aspiring computer science engineer with keen interest to acquire knowledge on emerging technologies.