Creating a live chatbot for your website (Part 1): Setting up Rasa chatbot locally on your system

Obianuju Okafor
5 min readApr 20, 2021
Screen capture from my website

Hello! This is the first part of a 3-part series involving creating and deploying a chatbot for your business or personal website using Docker and Heroku. The conversational AI platform I would be using is Rasa. Rasa is an open source machine learning framework that helps you create chatbots; it also happens to be my favorite chatbot platform for several reasons, such as it being open sourced, widely used and well documented.

In this post, I will be talking about how to setup Rasa locally on your computer. Although my OS is Windows, this entire process can be replicated for any system.

Prerequisite:

  1. Download Anaconda Prompt from here.
  2. Download Microsoft build tools here.
  3. Create a directory on your system where your would like to store your Rasa project.

Once all of that has been done, open the Anaconda Prompt application and ‘cd’ into the directory you created, mine is called ‘Rasa Project’.

Anaconda Prompt Terminal

Then run the following commands in Anaconda Prompt:

  1. Create a virtual environment using the command below.
conda create -n rasavirtualenv python=3.6

2. Activate your environment using the command

conda activate rasavirtualenv

3. Install Ujson

conda install ujson==1.35

4. Install Tensorflow

conda install tensorflow

5. Install Rasa Open Source.

pip install rasa

6. Create a new rasa project in your project directory

rasa init
Anaconda Prompt running the command ‘rasa init’

Looking at the last part of the screen above, when asked to enter path you would like to create project, enter the period sign (.), this signifies that you would like to create project in the current directory. When asked if you would like to train model, you can either choose ‘y’ or ‘n’.

After the command above finishes executing and the new project has been created, you will be asked if you would like to speak with the chatbot in the terminal. If you answer yes, a dialogue will begin between you and the newly created chatbot.

Sample Dialogue

Now that the project has been created, if you check your project directory, you will see that several files have been added to it. I will quickly discuss 3 files that I feel you need to understand their content; the file domain.yml in the main directory, and the files nlu.yml and stories.yml in the data folder.

Main Directory Files
Data Folder Files

The nlu.yml file is where all the training data is stored. The training data are sample messages that users can send to your chatbot. In this file, the messages are categorized according to intent. An excerpt from the file can be seen below. As you can see, intent : greet has several examples e.g. ‘hi’, ‘hello’, ‘hey’ etc. Intent: goodbye has examples ‘bye’, ‘goodbye’, ‘cu’ etc.

nlu:
- intent: greet
examples: |
— hey
— hello
— hi
— hello there
— good morning
— good evening
— hey there
— let’s go
— hey dude
— goodmorning
— goodevening
— good afternoon
— Hi there
- intent: goodbye
examples: |
— good afternoon
— cu
— good by
— cee you later
— good night
— bye
— goodbye
— have a nice day
— see you around
— bye bye
— see you later
— Adios

The domain.yml file defines the scope of your project. It contains salient information about your project, such as intents, entities, slots, actions, and most especially, the sample responses that the bot should send back to the user when it receives a message. Similar to nlu.yml, bot responses are categorized according to intent. For example, the response: utter_greet is sent whenever the bot wants to send back a greeting to the user. This is shown in the code segment below.

intents:
- greet:
use_entities: true
- goodbye:
use_entities: true
- affirm:
use_entities: true
- deny:
use_entities: true
- mood_great:
use_entities: true
- mood_unhappy:
use_entities: true
- bot_challenge:
use_entities: true
entities: []
slots: {}
responses:
utter_greet:
— text: Hey! How are you?
— text: Hi! How are you doing today?
utter_cheer_up:
— image: https://i.imgur.com/nGF1K8f.jpg
text: ‘Here is something to cheer you up:’
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: []
forms: {}
e2e_actions: []

The stories.yml file brings the user’s messages and bot responses together. It creates a storyline or a plot of the several interactions that can occur between the bot and the user. It specifies what response the chatbot should give based on the intent of the message sent by the user. This helps teach the chatbot what to do in different scenarios. For example, looking at the code segment below, if the chatbot receives a message with intent ‘greet’, it has to perform the action which sends the response ‘utter_greet’ back to the user.

stories:- story: happy path
steps:
— intent: greet
— action: utter_greet
— intent: mood_great
— action: utter_happy

At this point your chatbot is only able to handle very basic and generic conversation. In order to fit your personal or business needs you need to make some changes to the default chatbot. You can do this by modifying the content of the nlu.yml, story.yml, domain.yml files mentioned above using a text editor. However, the best way to make these changes is through the platform Rasa X.

In the next part of this three part series, I will be talking about how to modify, train and test your chatbot using Rasa X. You can find the post here!

If you like this post, HIT Buy me a coffee! Thanks for reading.

Your contribution will encourage me to create more content like this.

Don’t forget to 👏 !

--

--

Obianuju Okafor

Computer Science PhD Candidate. Research areas: Human Computer Interaction, Software Engineering, Accessibility, Machine Learning & Natural Language Processing.