Skip to main content

Know the rasa ecosystem and train your model effectively


Hope you have read the previous blog to create chatbot using Rasa. I would recommend to read it before starting this blog.

This blog will help you understand insights of rasa ecosystem and explain how to train your model effectively.

Rasa is an open source framework for creating chatbot with natural language undertsanding. There are few important files of rasa project -

✪ domain.yml
This file contain information about intent and respective actions. For instance- basis on intent of a user, appropriate action gets triggered and response is sent back to user. '-utter' is plain text without any logic behind it, however we can create custom action which we will discuss further in the blog.
intents:
- greet
- goodbye
- affirm

actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help

responses:
utter_greet:
- text: Hey! How are you?
utter_cheer_up:
- text: 'Great, carry on!'
utter_did_that_help:
- text: Did that help you?

✪ endpoints.yml
Custom action can be triggered by exposing it on some URL which you define in this file. One such example of action endpoint is shown here. This file also contains information about connecting to channels like facebook

action_endpoint:
url: "http://localhost:5055/webhook"


✪ config.yml
This file contains information about nlu and core models.

✪ credentials.yml
Here details about connecting to other services is defined. For instance - slack, facebook and so on. For exposing chatbot as API, we have to uncomment 'rest' based settings. Read the previous blog to know more about how to expose chatbot as API and integrate it with website.

✪ stories.md
This file is used for defining user stories. One can define happy path or sad and link the appropriate action which needes to be triggered. We can define our own stories as well in this file.
## 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

✪ nlu.md
This file help to train your bot. If any response is incorrectly tagged, you can put it in right intent and retrain the model by using > rasa train command.
## intent:greet
- hey
- hello
- hi
- good morning
- good evening
- hey there

## intent:goodbye
- bye
- goodbye
- see you around
- see you later
- i love you

## intent:affirm
- yes
- indeed
- of course
- that sounds good
- correct

✪ action.py
Custom action is defined in this file. You can put the logic to decide what response should be returned. Infact, you can call an API in this file, perform action and return appropriate response.
#!/usr/bin/python3
from typing import Any, Text, Dict, List

#import the rasa dependencies
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionFetchForm(Action):
def name(self) -> Text:
return "action_fetch_form"

Flow of chatbot messages and model training

If you are comfortable using commands, you can open the file on local machin, make the modifications, retrain the model and test it using CLI. If thats not the case, Rasa X library can make your life easy by providing a nice user interface.

How to install Rasa X?
1. Goto rasa_project directory
    > pip install rasa-x --extra-index-url https://pypi.rasa.com/simple
2. Once installed, run this command -
    > rasa x
It will open a nice website on local browser, see screenshot -
You can modify all required files(described above) and train the model as per your requirement using Rasa X user interface.

Hope the above blog helped you understande Rasa ecosystem and easy way to train the model. 

Comments

Popular posts from this blog

Nutch crawler and integration with Solr

Before moving ahead with this article, I assume you have Solr installed and running. If you would like to install Solr on windows, mac or via docker, please read Setup a Solr instance . There are several ways to install nutch which you can read from Nutch tutorial , however I have written this article for those who would like to install nutch using docker. I tried finding help on google but could not find any help for nutch installation using docker and spent good amount of time fixing issues specific to it. Therefore I have written this article to help and save time of other developers. Install nutch using docker- 1. Pull docker image of nutch using below command,      > docker pull apache/nutch 2. Once image is pulled, run the container,      > docker run -t -i -d --name nutchcontainer apache/nutch /bin/bash 3. You should be able to enter in the container and see bash prompt,      > bash-5.1#  Let's setup few important setting...

AJAX Progrraming

Ajax , shorthand for Asynchronous JavaScript and XML , is a web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user requests a change. This is meant to increase the web page's interactivity, speed, and usability. The Ajax technique uses a combination of: XHTML (or HTML) and CSS, for marking up and styling information. The DOM accessed with a client-side scripting language, especially JavaScript and JScript, to dynamically display and interact with the information presented. The XMLHttpRequest object is used to exchange data asynchronously with the web server. In some Ajax frameworks and in certain situations, an IFrame object is used instead of the XMLHttpRequest object to exchange data with the web server, and in other implementations, dynamically added tags may be used. ...

Call a custom Script from Excel

  It is quite common that we receive the data in Excel and several times we have to remove unwanted characters from columns or modify the data as per the requirement. To avoid manual fixes of these kind of requirements, we may use Macro to automate the process which not only increase productivity but also avoid manual errors. We can easily create Macro to quickly fix it. Here are the steps to create Macro and run it. Open Excel Goto View tab on Main menu Click on 'View Macros'. This should open a Macro popup. Enter Macro Name and click on + icon. Clicking on + icon should open Macro Coding screen(as shown below). Add your code in the function. Click on Save icon to save the file with Macro. Click on Run icon to run the Macro code. The above code should remove additional line breaks from columns. Reference Code(to remove line breaks from columns): Sub MyCustomMacro () Dim MyRange As Range Application . ScreenUpdating = False Application . Calculation = xlCa...