Let's build AI powered contextual chatbots with RASA: part-1
Ever wondered how those AI assistants like Alexa, Cortana work? Ever wanted to make your own AI powered chatbots but didn't know where to start?
You have reached the right blog post π.
WHO AM I ?
I am a professional python developer working with W3sols (A web and mobile App development company)
These days I am experimenting with AI and ML related tech stack.
I will share with you the easiest and quite interesting way of building AI powered chatbots using an emerging AI powered open sourced chatbot framework RASA.
I recently built a restaurant search chatbot with RASA in 2 days and trust me it was fantastic experience !!!π€©.
But first lets have a look at some pre requisites for building a chatbot with RASA.
- Experience with Python3 (A must have)
- Experience with ML algorithms (Although not necessary but its good to have to relate with stuff you will learn in this blog post)
- Some NLP jargon (Not necessary but good to have)
This chatbot will be covered in four parts:
- Basic terminologies to build chatbot with RASA
- What is RASA NLU and RASA Core
- Setting Up a basic RASA chatbot
- Restaurant search chatbot
That is it !!!
Let's start
with understanding some NLP jargon necessary to understand RASA framework ππ»
Intent - It refers to what a person is trying to say. What is the context of what the person has said. What is the topic of sentence said by the person.
for example: find a restaurant in delhi.
- here the intent is restaurant search
Entity Type - It refers to the things being talked about in a given sentence. What are the different category of things a person is talking about.
for example: find a restaurant in delhi.
- delhi here belongs to entity type location
Entity - It refers to the instance of entity type.
for example: find a restaurant in delhi.
- delhi here is entity (instance of entity type location)
Actions - Declarations of functions that will be called when the intents, entities and entity types in a sentence are identified.
Stories - The flow of conversation is defined by a story.
for example: when the bot starts .....
- user will say Hii
then
- bot will say Hi, How may I help?
This is a flow defined by stories.
Responses - Definition of some not all actions. The actions that require functionality such as API hits are defined in a separate document called actions.py
Domain - It is the universe for your chatbot. It is stored as domain.yml in your chatbot's code. This is where we will define what all things our chatbot knows. for example: In a restaurant search chatbot your bot should know different functions which will be called in the whole conversation with user for example if a user says:
user: Hi !!!
Bot : Hi, How may I help ?
How does the bot know it has to perform this task?
The answer can be explained as follows:
When we talk to a person we try to understand what that person is saying that is we try to understand the intent of person's sentences.
Once we know what the person is trying to say we try to find out if the intent is about something or is the person saying that sentence for some thing. So here we are trying to find out what is the entity type and entity being talked about by the person in the sentence.
Now, we know what is the sentence all about. Now what we do?
We respond. How? With help of universe of knowledge which we have in our brains due to extensive past experiences and all the things around us.
This is how this process works in our brains in so...... little time.
So using the above analogy we can make our bot understand stuff better and make it respond correctly
HOW do we achieve this in RASA? (Wait for code, understand concepts first π)
We have a set of different documents in RASA project structure. The most important ones and the ones in which we will work in the bot building part are:
- domain.yml
- yml is extension for YAML and it's full form is "YAML Ain't Markup Language" recursive π .
- domain.yml is a document that acts as the universe for a RASA chatbot. We define what a bot should know that is "How to decide an intent for sentence", "What entities and entity types can possibly be present in a sentence, "How a chatbot should respond" and for that we need some responses that are stored in domain.yml as a declaration unders actions section and as definitions under responses section.
- Structure of domain.yml
action:
- utter_hi
- utter_ask_location
entities:
- affirm
- location
intents:
- affirm
- restaurant_search
responses:
utter_hi
- text: Hi, How may I help you?
utter_ask_location
- text: Please enter a location
slots:
location:
type: text
-
nlu.md
- nlu.md refers to "Natural Language Unit" document where we define in what different ways elements of natural language (for us english) can occur in user's sentence for different kinds of intents and further what could be the synonyms for those elements and what regex can we define for them. Let's see the structure of nlu.md to better understand it.
- Structure of nlu.md
## intent: affirm - yes - sure - why not - indeed - that's right - ok - Thank You - great - right, thank you - correct ## intent: restaurant_search - i'm looking for a place to eat - I want to grab lunch - I am searching for a dinner spot - I am looking for some restaurants in [Delhi](location). - I am looking for some restaurants in [Bangalore](location) ## synonym:Delhi - New Delhi - delhi - Dilli ## synonym:bangalore - Bengaluru - bangloor ## regex:location - [a-zA-Z]* ## regex:affirm - ((ye)|(Ye)|(YE))[^\\s]*
-
stories.md
- stories.md is where you define the flow of user's conversation with the bot. There could be n number of possible stories as there can be n number of flows for a particular conversation as well.(I will explain how to write stories in one of the next blog post in this series, so just keep this in mind right now π.)
-
actions.py
- actions.py is the document where you will put all your code for actions that require complex logics like API hits. We will work on it soon when we will build a chatbotππ»
For now I think that's a lot to digestπ
, but worry not we have covered a lot of the conceptual basics of RASA and if you understood it well then it will be easy for you to further create a chatbot that I will help you create in the second part of this RASA chatbot blog post. We will build and learn about two parts of RASA- RASA Core and RASA NLU.
Don't forget to like and comment if you find this helpful, and if you have any ideas to further improve do share in comments.
Till then, Happy Learning π
please contact me at nicoletansimin@gmail.com
hi can you teach me RASA? i am having trouble with starting RASA, developing chatbot . what i would like to do is to develop an AI chatbot with rasa and fine tune the conversation