Codementor Events

Let's build AI powered contextual chatbots with RASA: part-2

Published Apr 30, 2020Last updated May 02, 2020
Let's build AI powered contextual chatbots with RASA: part-2

Hi all !!!
Looking to build some AI powered chatbots? You are at the right blog post😄.

Who am I?

I am a python developer at W3sols (A Web and mobile App development company). I have been working in Python for a long time now and currently I am experimenting with AI and ML related tech stack.

Who is this blog post for?

  • This blog post is second of the three part blog series for building a contextual AI powered chatbot in RASA (an open sourced chatbot framework)
  • In case you haven't read the first blog post in the series please refer to the link- Let's build AI powered contextual chatbots with RASA: part-1. I have explained some jargon related to RASA in detail there.
  • You will understand stuff better if:
    • you have a prior experience with Python3 (A must have)
    • you have some basic knowledge of NLP jargon(not necessary you can refer to this blog post to understand basic jargon.
    • you have a basic knowledge of ML algorithm (not necessary but a plus to have, that way you can relate to stuff in this blog post better).

What we will cover in this blog post?

  • Understand the two parts of RASA framework: RASA Core and RASA NLU.
  • Create an environment for building our Restaurant search chatbot.
  • Install necesaary packages like RASA, spacy etc. that will help us create our chatbot.

So... Let's Start 👍🏻

Screen Shot 2020-04-30 at 10.30.45 PM.png

As in the picture above you can see that a user is in conversation with bot.
But how is this possible for a chatbot to extract the intents, entities and entity types from a sentence that user entered and how does that bot decide on what action to take next in the conversation?
Let's recreate the above illustration at base level.

user: Book a table at ABC restaurant.
--------------------------------------
                 |
    RASA NLU ---------> RASA Core <-----------> DB and API
                 |				 				
                 V
______________________________________
bot: For how many people?

Did you notice two components in between?
Exactly, RASA NLU and RASA Core. What are these and what do they do with the data that made the bot utter a perfectly correct message to user? Let's see.

RASA NLU :

  • Seems familiar since we read about nlu.md in previous post of the series. NLU is the Natural Language Unit of the RASA framework. It extracts intents, entity types and entities from the sentence based on what training data was provided when NLU was trained (We will soon train the NLU, don't worry 😄).

Wait a minute "training data" what's this?
Remember the "nlu.md" and "stories.md" docs from the first post? That is it !!!. These are the docs where your NLU training data resides. Since we are building a contextual chatbot we will provide a lot of training data so that our NLU after being trained is able to classify intents, entities and entity types in the sentence at its best.

RASA Core :

  • Now we have an engine (RASA NLU) that detects the correct intents, entities and entity types in the sentence now we need something that can decide on "what next in conversation?"
    I mean, what will be the next sntence in the conversation when a user has entered certain response. This is where RASA Core comes into play. We train RASA Core after RASA NLU and training data for RASA Core is domain.yml because this is the universe of our chatbot whatever our core needs to decide regarding actions and response exist within "domain.yml". Now this us the Core that calls appropriate action at appropriate times to respond to user based on input it gets from NLU. Now, there are certain actions that require API calls and DB operations. Such actions are also called by Core by looking into actions.py script.

😅 Tired? Worry not we are done with concepts. It's time to start building Restaurant search chatbot. So let's fire up a text editor and terminal for macbook or cmd prompt in windows.

In terminal/cmd prompt

$ cd desktop && mkdir RestoBot && cd RestoBot

I would recommend doing the RASA installations in a virtual environment since it's a big library and has a lot of dependencies.

In terminal/cmd prompt install virtual environment

$ pip install virtualenv

You may already have it installed if not above cmd will do it for you.

In terminal/cmd prompt

$ python -m venv restoEnv

Above cmd will create a virtual environment named restoEnv in RestoBot directory(created in first cmd above).

This step is different for macOS and windows
In terminal

$ source restoEnv/bin/activate

In cmd prompt

>> ./restoEnv/Scripts/activate

Above cmd will activate the virtual env and the cmd propmt/terminal will have a prompt starting with the name of the env activated:

(restoEnv)

ALL SET👍🏻 Let's install rasa

In terminal/cmd prompt

$ pip install rasa 

In terminal/cmd prompt

$ pip install rasa[spacy]

$ python -m spacy download en_core_web_md

$ python -m spacy link en_core_web_
md en 

Above cmds will install spacy, download dependencies and link them to spacy.

Phew!!! covered a lot but the best part about this is, in the next blog post we will be all set to build our Restaurant Search chatbot🤩.
Excited?
Well that feeling is obvious. We have covered really a lot of stuff in these two blog posts and now we are at last ready with almost all basic concepts required to build a chatbot with RASA.
There are few high level concepts like pipelines, policies, lookup tables but these will be covered in my other blog posts. For now, we will be building the chatbot so that you are better able to relate the concepts which we covered in these two blog posts with chatbot building process and that will be covered in the third and last post of this "Let's build AI powered contextual chatbots with RASA" blog post series.
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 😄.

Discover and read more posts from Dharvi
get started
post commentsBe the first to share your opinion
ARIES Tushar
4 years ago

excellent post :)…im a business analyst and trying to create a rasa bot with advanced features slowly…would surely seek your help for the same :)

Dharvi
4 years ago

Thanks for liking the post I have a whole four-part series on it please check
Happy Learning !!
and yeah any help required just ask in the comments will help for sure

ARIES Tushar
4 years ago

Thnx a ton…hope we get to know more advanced concepts like generating API calls from backend DBs (MySQL, SQL) or other cognitive APIs like speech recognition, Image recognition, OCR, etc :)

Show more replies