Voyage-2- Explaining the file structure for your chatbot

Sahib Singh
Analytics Vidhya
Published in
6 min readMay 17, 2021

--

Hey, Welcome to part2 of this Chat-bot using Rasa Series. I am hoping you have seen the first part where I explained.
How you can set up a Virtual environment and Make an initial Bot. If you have not seen that part click on this

Agenda for Today’s Blog:-

  1. What are Intents and Entities in rasa?
  2. The file structure in Rasa ( files you got after Rasa Init ) makes some custom intents.
  3. Train the model after changes and talk to it
credits: blog.spg.ai

What are Intents and Entities

I will explain intents by example say we have 5 sentences

  1. Can I get some pizza
  2. Last week when I was in New York I had a very tasty smoothie
  3. It’s been such a long time I had that Yummy chocolate cake.
  4. Baby, shall we go out for a dinner today
  5. where is my Protein shake?

Now try to analyze these 5 sentences carefully what do you observe
They all are somehow related to food-query

So what we will do in rasa is we will make one intent named as food-query and we will put all those 5 sentences under it and train our Rasa model.

Ok, Sahib Nice I got the Idea of Intent’s but what are Entities.
All the highlighted words are called entities and they will be marked as
Entity food.
They can be either made in Training Data or can be made using the help of Regular expressions

The file structure in RASA

files after rasa init

Data:-

This folder contains all NLU and RULES and STORIES files.

But Sahib What are these files what do they mean?

NLU files: -

NLU stands for Natural language Understanding this file in Naive language contains your Natural language Data on which Rasa will train. NLU file ( nlu.yml) contains categories such as Intents and Entities which I have explained above. And under each intent, there are training examples that are actually your training data.
Important Points to keep in Mind while making Training Data.

  • Add augmentations to examples that come under each intent, but the examples should not be so different than your intent gets mixed.
  • Add a minimum of 5 examples under each intent.
  • Intents should convey the feeling that users can ask from chatbot because not every question is considered intent.
  • Add some wrong examples in each intent because no training data is never perfect

Rules file:-

Rules are great to handle small specific conversation patterns. They are basically hard restrictions that get followed once rasa recognizes the user’s Intent.
Say Rasa has recognized the User’s Message as Intent: goodbye ( as seen in the example image above)
So by defining the rule I have made sure now Rasa will respond with utter_goodbye ( It is the response of Intent: goodbye ) or we can say we are ignoring the responses RASA makes using Machine learning at the back-end on behalf of the pipeline defined in config.yml.
Two things here:-

  1. we define these utter’s in domain.yml.
  2. Rasa makes responses using pipeline defined in config.yml

Don’t get Worried I will explain the Domain file and Utter’s Below in this blog :)

And How Rasa makes responses using ML with help of pipeline defined in config.yml in coming blogs

Important points to keep in Mind While defining Rules:-

  1. Don’t Overuse rules ( Most important because our goal is to make a contextual chatbot )
  2. Uncomment Rule Policy in config.yml ( Mandatory to use rules in your project )

Stories file:-

whenever you talk to a bot. There can be 2 cases

  • Either your conversation is going well ( Happy Path ).
  • Or it’s not ( Sad Path )

A story is a representation of a conversation between a user and an AI assistant, converted into a specific format where user inputs are expressed as intents (and entities when necessary), while the assistant’s responses and actions are expressed as action names.

Important tip:-

  • Good stories help to Reduce False Positives in Chatbots ( I have seen from my experience).
  • Remember you cannot make a story for each Intent and you cannot cover each happy path in stories.yml.

Domain.yml

Domain file this is the universe of your chatbot. It contains all the intent’s you want to train on and all the utters ( responses ) for each intent.

Rules to keep in mind while defining utters:-

Say your Intent’s name is goodbye so in domain.yml we will define its response with the name utter_goodbye ( It is mandatory ) to define responses in this particular fashion.

  1. We have to define each intent we are using for a chatbot in the domain file
  2. We can Make multiple domain files if we have a big project for this project we will make multiple domain files.

Config.yml

This file contains actual juice the pipeline your chatbot will use to Interpret the user’s message and predict intent for it and then predict correct utter for it.
All these predictions of intents and utters is done with help of policies ( we’ll talk about policies in future blogs )

Actions

This folder contains one very important file that is actions.py
this will is where we will write our custom actions.

WAIT : (

Hey but listen this is the most interesting part ( It’s a python file )
Means you can use it for almost everything from

  1. Hitting an API
  2. To writing custom responses for user’s messages.
  3. To fetching data from databases

Anything means anything.
( Ex for one of my client I wrote a custom spell checker in this action file and used it in our chatbot ) and that was damn Interesting

Lastly Credentials.yml and endpoints.yml
I will explain these files during deployment blogs ( 5–6 ) because they are used then only

Let’s get practical

Here I am making our first custom intent

Carefully see I am making minor spelling mistakes
( Example 4 in the spelling of chatbot )

To define its answer head to Domain.yml

Now let’s train our model

Simple type

rasa train

in your activated virtual environment.
After it’s Trained
you can talk to your TravelBot
By saying

rasa shell

and see if it can answer questions similar to your travel_support intent.
1. If yes you can add more intents.

2. If No add more training data

Good work Folks, you have learned a lot today.
If you like my work
Share and Clap would be Fantastic.
To get notified for other blogs in this series and regarding machine learning and Artificial Intelligence
Follow the author :)

Github Repo for Project https://github.com/sahibpreetsingh12/travel-bot

--

--