Learn how to Build and Deploy a Chatbot in Minutes using Rasa (IPL Case Study!)

Check out a high-level overview of our IPL chatbot below: Let’s break down this architecture (keep referring to the image to understand this): As soon as Rasa receives a message from the end user, it tries to predict or extract the “intent” and “entities” present in the message.

This part is handled by Rasa NLU Once the user’s intent is identified, the Rasa Stack performs an action called action_match_news to get the updates from the latest IPL match Rasa then tries to predict what it should do next.

This decision is taken considering multiple factors and is handled by Rasa Core In our example, Rasa is showing the result of the most recent match to the user.

It has also predicted the next action that our model should take – to check with the user whether the chatbot was able to solve his/her query   Setting up the IPL Chatbot I have created two versions of the project on GitHub: Complete Version – This is a complete chatbot that you can deploy right away in Slack and start using Practice Version – Use this version when you’re going through this article.

It will help you understand how the code works So, go ahead and clone the ‘Practice Version’ project from GitHub: git clone https://github.


git && cd iplbot And cd into the practice_version: cd practice_version A quick note on a couple of things you should be aware of before proceeding further: Rasa currently only supports Python version <= 3.


If you have a higher version of Python, you can set up a new environment in conda using the following command: conda create -n rasa python=3.

6 conda activate rasa You will need a text editor to work with the multiple files of our project.

My personal favorite is Sublime Text which you can download here   Installing Rasa and its Dependencies You can use the code below to install all the dependencies of the Rasa Stack: pip install -r requirements.

txt This step might take a few minutes because there are quite a few files to install.

You will also need to install a spaCy English language model: python -m spacy download en Let’s move on!.  Extracting User Intent from a Message The first thing we want to do is figure out the intent of the user.

What does he or she want to accomplish?.Let’s utilize Rasa and build an NLU model to identify user intent and its related entities.

Look into the practice_version folder you downloaded earlier: The two files we will be using are highlighted above.


md – This is the file where you will save your training data for extracting the user intent.

There is some data already present in the file: As you can see, the format of training data for ‘intent’ is quite simple in Rasa.

You just have to: Start the line with “## intent:intent_name” Supply all the examples in the following lines Let’s write some intent examples in Python for the scenario when the user wants to get IPL updates: View the code on Gist.

You can include as many examples as you want for each intent.

In fact, make sure to include slangs and short forms that you use while texting.

The idea is to make the chatbot understand the way we type text.

Feel free to refer to the complete version where I have given plenty of examples for each intent type.


yml – This file lets us create a text processing pipeline in Rasa.

Luckily for us, Rasa comes with two default settings based on the amount of training data we have: “spacy_sklearn” pipeline if you have less than 1000 training examples “tensorflow_embedding” if you have a large amount of data Let’s choose the former as it suits our example:   Training the NLU classifier If you have made it this far, you have already done most of the work for the intent extraction model.

Let’s train it and see it in action!.You can train the classifier by simply following the command below: make train-nlu Using Windows?.You can run the following python code: python -m rasa_nlu.

train -c nlu_config.

yml –data data/nlu_data.

md -o models –fixed_model_name nlu –project current –verbose   Predicting the Intent Let’s test how good our model is performing by giving it a sample text that it hasn’t been trained on for extracting intent.

You can open an iPython/Python shell and follow the following steps: >>> from rasa_nlu.

model import Interpreter >>> nlu_model = Interpreter.


/models/current/nlu) >>> nlu_model.

parse(what is happening in the cricket world these days?) Here is what the output looks like: View the code on Gist.

Not only does our NLU model perform well on intent extraction, but it also ranks the other intents based on their confidence scores.

This is a nifty little feature that can be really useful when the classifier is confused between multiple intents.

  Making Interactive Conversations One of the most important aspects of a chatbot application is its ability to be interactive.

Think back to a chatbot you’ve used before.

Our interest naturally piques if the chatbot is able to hold a conversation, right?.The chatbot is expected to extract all the necessary information needed to perform a particular task using the back and forth conversation it has with the end user.

  Designing the conversational flow Take a moment to think of the simplest conversation our chatbot can have with a user.

What would be the flow of such a conversation?.Let’s write it in the form of a story!.Me: Hi Iplbot: Hey!.How may I help you?.Me: What was the result of the last match?.Iplbot: Here are some IPL quick info: 1.

The match between Rajasthan Royals and Delhi Capitals was recently held and Delhi Capitals won.


The next match is Warriors vs Titans on 22 April 2019 Iplbot: Did that help you?.Me: yes, thank you!. More details

Leave a Reply