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

Cannot alter the login 'sa', because it does not exist or you do not have permission.

Working on projects, it can happen that 'sa' account gets locked. If it is on local machine OR development boxes, onus would be on you to fix it. If scripts and SQL steps are not working, this might help you fixing the issue. Steps to unlock 'sa' account and resetting the password. 1. Open SQL Server Configuration Manager 2. Select SQL Server Services -> 'SQL Server' service. 3. Right click on 'SQL Server' service and click on "Startup Parameters". For 2008, server "Startup Parameters" are inside Advanced tab.   4. Add '-m' in startup parameters as shown above and click on 'Add'. This will put SQL server into 'Single User Mode' and local admin will have 'Super User' rights. For 2008, server you have to add ':-m' in the last of the existing query. 5. Save the settings and Restart the service. 6. Now open the SQL Server Management Studio and connect to database using 'Windows A

Could not load file or assembly 'Microsoft.Web.Infrastructure'

Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. What 'Micorosoft.Web.Infrastructure' does? This dll lets HTTP modules register at run time. Solution to above problem: Copy 'Micorosoft.Web.Infrastructure' dll in bin folder of your project and this problem should be resolved. If you have .Net framework installed on machine, this dll should be present on it. You can search for this dll and copy it in your active project folder.   Alternatively,  you can install this dll using nuget package manager PM> Install-Package Microsoft.Web.Infrastructure -Version 1.0.0 Happy coding!!

Dockerize a dotnet core application with SQL connectivity

Before reading this article, I am assuming that you know Docker, Dotnet core and have a dotnet core application which is trying to connect to SQL server. Read how to build aspnet core app, docker and run the docker container. If docker container is running and you are not able to connect to database, this blog should help you fix it.  Prerequisite -  Make sure code is working via running aspnet core locally via visual studio or command line. Port 1433 is opened for connecting to SQL server. Solution If you have Docker file ready, it should somewhat look like below file -  FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY /SampleAPI/*.csproj ./ RUN dotnet restore # Copy everything else and build COPY . . WORKDIR /app/SampleAPI RUN dotnet publish -c Production -o publish # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app/SampleAPI COPY --from=build-env /app/SampleAPI . WORK