Customize Rasa chatbot and Understanding it’s Working Easily <3

0
0

Chatbot chatbot chatbot… Everyone is using chatbot nowadays in either way direct or indirect. We as creators/ Innovators are also getting a part of this crowd and we have to take an initiative and to give a kick start to our career so as not just to be a part of the rat race and to achieve something.

So this is the right time to give a chance to ourselves and to be a part of this amazing and the trending technology.

Don’t wait, Give a Start, Right here, Right now.

OVERVIEW

In this post you will learn how to customize and integrate Rasa X chat bot into your business and Understand it’s actual working. Now let’s move to the main topic.

In our previous post, you may have seen how we have created our first Rasa X chatbot and how it was able to make a simple conversation with the user. Now let’s understand how it had actually worked.

Basic Introduction to Customize Rasa Chatbot

As you have seen in the previous post after creating the initial project you got some files and directories created in the given order

.
├── _init_.py
├── actions.py
├── config.yml
├── credentials.yml
├── data
│   ├── nlu.md
│   └── stories.md
├── domain.yml
├── endpoints.yml
└── models
    └── <timestamp>.tar.gz 

This is the complete architecture of rasa chatbot files that are required by rasa core and Rasa NLU to run the chatbot. The most important files that are required to create a chatbot with the proper working are config.yml, nlu.md, stories.md, domain.yml, actions.py, etc. In this blog, I’ll be elaborate all about the config.yml, nlu.md, stories.md and domain.yml. By default when you run “rasa init –no-prompt” command we have some data as an example in these files.

In config.yml we have:

language: en
pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: "char_wb"
 min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
policies:
- name: MemoizationPolicy
- name: FormPolicy
- name: TEDPolicy
  max_history: 5
  epochs: 100
- name: MappingPolicy

In nlu.md we have:

## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there
## intent:goodbye
- bye
- goodbye
- see you around
- see you later
## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really
## intent:mood_great
- perfect
- very good
- great
- amazing
- wonderful
- I am feeling very good
- I am great
- I'm good
## intent:mood_unhappy
- sad
- very sad
- unhappy
- bad
- very bad
- awful
- terrible
- not very good
- extremely sad
- so sad
## intent:bot_challenge
- are you a bot?
- are you a human?
- am I talking to a bot?
- am I talking to a human?

In domain.yml we have:

intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge

templates:
utter_greet:
- text: Hey! How are you?
utter_cheer_up:
- text: 'Here is something to cheer you up:'
image: https://i.imgur.com/nGF1K8f.jpg
utter_did_that_help:
- text: Did that help you?
utter_happy:
- text: Great, carry on!
utter_goodbye:
- text: Bye
utter_iamabot:
- text: I am a bot, powered by Rasa.
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
- utter_iamabot

In stories.md we have:

## happy path
* greet
- utter_greet
* mood_great
- utter_happy
## sad path 1
* greet
- utter_greet
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* affirm
- utter_happy
## sad path 2
* greet
- utter_greet
* mood_unhappy
- utter_cheer_up
- utter_did_that_help
* deny
- utter_goodbye
## say goodbye
* goodbye
- utter_goodbye
## bot challenge
* bot_challenge
- utter_iamabot

Working of Rasa X

Now when we start rasa chat bot and send a text to chabot at that time what happens is rasa NLU checks your text and classifies it as per the intent name what ever you have given in the nlu.md and the domain.yml file so that rasa core will check the stories.md file with the intent name and according to the flow of the story it will check for the response that the bot will give you with respect to the intent that the user has passed. Now from the stories.md file bot will get the template name(utter_<name>) and with respect to that template name the text will be passed to the chat bot that will be displayed to the user so that the user can reply to it and this process repeats for the conversation flow. In this way Rasa chatbot works internally and so that we have a very good converstion with the bot.

To give a proper explaination, let’s understand it with an example:

Suppose you as a customer are in a restauarnt and you had a conversation with the waiter to order the food. Here is a short conversation that you’ll make with the chatbot to place the order.

User: Hi

Bot: How may I help you?

User: What can i get here for the lunch?

Bot: What would you prefer veg or non-veg?

User: vegetarian

Bot: we have mix veg, paneer butter masala, mushroom masala,etc?

User: get me 1 mix veg and paneer butter masala

Bot: Is there any thing else sir?

User: No

Bot: Thanks. We will get your order shortly.

So this is a short conversation that we will have with the chatbot(as a waiter) to place our order at the restaurant. Now there are two options that a user can be a vegetarian as well as non-vegetarian so we have to offer him/her accordingly to choose. For this, we have to add new intents with the intent names in the nlu.md file that a customer will say to the waiter and also add the responses of the waiter in the domain.yml file that the waiter(bot) will reply with. Also, we will add two stories in the stories.md file for the vegetarian and the non-vegetarian path. Here are the changes that you have to make to the above file

In nlu.md :

## intent:what_do_you_have
- what can i get here?
- what can i have to eat?
- what can i get for the lunch?
- what is this place famous for ?
## intent:vegetarian
- vegetarian
- pure veg
- pure veggie
- i want vegetarian food
## intent:non_veg
- non-veg
- non-vegetarian
- pure non-veg
## intent:order_name_veg
- get me 1 mix veg and paneer butter masala
- i want 1 mix veg and masala mushroom
- i want green salad
## intent:order_name_non_veg
- get me 1 egg curry and chicken butter masala
- i want 1 egg fry and fish curry
- i want 5 boiled eggs
## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there
## intent:goodbye
- bye
- goodbye
- see you around
- see you later
## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct
## intent:deny
- no
- never
- I don't think so
- don't like that
- no way
- not really

In stories.md:
## happy veg path
* greet
- utter_botgreet
* what_do_you_have
- utter_veg_non_veg
* vegetarian
- utter_veg
* order_name_veg
- utter_anthingelse
* deny
- utter_thanks

## happy non vegetarian path
* greet
- utter_botgreet
* what_do_you_have
- utter_veg_non_veg
* non_veg
- utter_non_veg
* order_name_non_veg
- utter_anthingelse
* deny
- utter_thanks

In domain.yml:

intents:
- greet
- goodbye
- affirm
- deny
- what_do_you_have
- vegetarian
- non_veg
- order_name_veg
- order_name_non_veg
templates:
utter_botgreet:
- text: How can i help you sir?
utter_veg_non_veg:
- text: what would you prefer veg or non-veg?
utter_veg:
- text: we have mix veg, paneer butter masala, mushroom masala,etc?
utter_non_veg:
- text: we have egg curry, chicken butter masala, fish curry, boiled eggs, bread
omlette, etc?
utter_anthingelse:
- text: Is there any thing else sir?
utter_thanks:
- text: Thanks. We will get your order shortly.
utter_goodbye:
- text: Bye
actions:
- utter_goodbye
- utter_botgreet
- utter_veg_non_veg
- utter_veg
- utter_non_veg
- utter_anthingelse
- utter_thanks

In config.yml there is no changes.

For better clarity and understanding you can refer to the video:

After all these changes have been made you have to train the model with the changes you have made so as to observe the changes in the chatbot. For training the bot open terminal with the rasa environment activated and being on the project directory, then type:

 rasa train

after the training is done now you can test the bot in the interactive mode by typing the command :

 rasa x
customize rasa chatbot

This is how your chatbot will work what you will run rasa x with your trained model.

Time to wrap up now. Hope you liked our content on How to customize Rasa chatbot. See you in our next blog, thanks for reading our blog and do leave a comment below to help us improve the content to serve you all of our experience with you. Stay tuned with us for more Rasa Chatbot contents.

Also check out our other playlist Rasa Chatbot, Internet of things, Docker, Python Programming, etc.
Become a member of our social family on youtube here.

Till then Stay tuned and Happy learning.

Ashish Saini
Ashish Saini

I am a software developer for Python/Machine Learning. Also, I’m Rasa Hero at Rasa. Also, I’m a youtuber where I regulary uploads the videos to help this generation learn about the technology just like they are playing games.

2 thoughts on “Customize Rasa chatbot and Understanding it’s Working Easily <3

Leave a Reply