0% found this document useful (0 votes)
434 views9 pages

Rasa Project Report

Rasa is an open-source machine learning framework for building conversational agents. It allows integrating chatbot workflows and automatically classifying user messages. Rasa is built using Rasa NLU for classification and Rasa Core for dialog management. The key components are pipelines for processing user messages, a tracker to maintain conversation state, policies for selecting agent responses, and templates/actions for generating outputs. Custom components and actions can be created to extend Rasa's capabilities. Training data like stories and a domain file are used to train Rasa Core's dialog model.

Uploaded by

Ashner Novilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
434 views9 pages

Rasa Project Report

Rasa is an open-source machine learning framework for building conversational agents. It allows integrating chatbot workflows and automatically classifying user messages. Rasa is built using Rasa NLU for classification and Rasa Core for dialog management. The key components are pipelines for processing user messages, a tracker to maintain conversation state, policies for selecting agent responses, and templates/actions for generating outputs. Custom components and actions can be created to extend Rasa's capabilities. Training data like stories and a domain file are used to train Rasa Core's dialog model.

Uploaded by

Ashner Novilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Rasa Project Report 

Made By: Mayank Shinde

Introduction
Rasa is a open source machine learning framework for python, to automate text and
voice message based conversations. We can integrate chatbot workflow and automatically
classify the end user messages to the intents and entities. Then by using rasa dialog flow
pipeline dialogs, responses(templates) and actions are executed through with the chatbot
generate some output. Rasa is built on the top of Rasa NLU and Rasa Core combinedly called
Rasa Stack.

Rasa Installation:
We can use pip to install rasa by a single enter.

For Windows Users:


pip install rasa
For ubuntu and mac users:
pip3 install rasa

We will also need to download spacy language models to deal with incoming user messages
and classify them to intents and extract entities from them. To do so we will need to execute the
below command in Terminal/Command Prompt

python -m spacy download en_core_web_md

Then link it to our current language model

python -m spacy link en_core_web_md en

The above procedure is to setup the rasa stack. If we use tensorflow embeddings instead of
spacy we need not to install spacy language model. It will automatically look for tensorflow word
embeddings and use those for classification.
Rasa CLI Commands:
rasa init : It initializes the current directory for rasa, by creating some required
configuration files and folders and setup an in memory database.

rasa shell: It is used for testing purposes so that we can ensure whole NLU model and
Core model are working fine.

rasa run: It is use to start/run the rasa core server(without arguments). When the
argument “actions” is specified it runs the action server (like a business logic layer) that is the
custom python code to do something.

rasa train: It is used to train both nlu and core model.

rasa interactive: It is used to start interactive learning session

Rasa Architecture
Rasa architecture is as follows
The message is received and passed to an Interpreter, which converts it into a dictionary
including the original text, the intent, and any entities that were found. This part is handled by
NLU.

The Tracker is the object which keeps track of conversation state. It receives the info
that a new message has come in.

The policy receives the current state of the tracker.

The policy chooses which action to take next.

The chosen action is logged by the tracker.

A response is sent to the user.

Training the Rasa NLU:


As the rasa stack is built by combining the NLU and Core, Rasa NLU(Text Classification
) need to be trained to handle the unknown messages from user. To do so we will need a node
js server, or Rasa X either will do the work.

If we choose the node we will need an application to create the training dataset.
Note:​ This will create training data in json format.

npm i -g rasa-nlu-trainer
Pipeline in Rasa

Pipeline is like a sequence of procedures (in rasa known as Component) those are
executed one by one in a Queue. To specify the pipeline we need to change the current working
directory to our project directory and edit the config.yml file.

To specify the Pipeline for rasa we can append the Components i.e.

pipeline:

- name: "SpacyNLP"
- name: "SpacyTokenizer"
- name: "SpacyFeaturizer"
- name: "RegexFeaturizer"
- name: "CRFEntityExtractor"
- name: "EntitySynonymMapper"
- name: "SklearnIntentClassifier"

We can also specify the Custom Pipelines to this, the above pipeline is inbuilt in rasa
nlu model that is:

pipeline: "pretrained_embeddings_spacy"

Both of the above pipelines are the same, in case we need to add a custom component
then the upper one can be used so that it would not disturb the other components.

Custom Pipelines in Rasa:

To implement the custom pipelines in rasa,first we need to know the life


cycle of the component.
Above is the workflow diagram for Rasa NLU Pipeline, as the context flows
through the pipeline we also needs to know where to place our custom
components depending on the this that we need to used prior and after there
execution each pipeline.

from rasa.nlu.components import Component


import typing
from typing import Any, Optional, Text, Dict

if typing.TYPE_CHECKING:
from rasa.nlu.model import Metadata

class MyComponent(Component):
provides = [] # Attributes that the component provide

requires = []# Attributes that component requires


defaults = {}

language_list = [‘en’]

def __init__(self, component_config=None):


super(MyComponent, self).__init__(component_config)

def train(self, training_data, cfg, **kwargs):


"""Train this component.

This is the components chance to train itself provided


with the training data. The component can rely on
any context attribute to be present, that gets created
by a call to :meth:`components.Component.pipeline_init`
of ANY component and
on any context attributes created by a call to
:meth:`components.Component.train`
of components previous to this one."""
pass

def process(self, message, **kwargs):


“Processing of the component”
pass

def persist(self, file_name: Text, model_dir: Text) -> Optional[Dict[Text, Any]]:


"""Persist this component to disk for future loading."""

pass

@classmethod
def load(
cls,
meta: Dict[Text, Any],
model_dir: Optional[Text] = None,
model_metadata: Optional["Metadata"] = None,
cached_component: Optional["Component"] = None,
**kwargs: Any
) -> "Component":
"""Load this component from file."""
if cached_component:
return cached_component
else:
return cls(meta)

Rasa Core
Rasa core is the dialog flow model in rasa it manages conversations and there
flow. To do so we also need to train the Core model of rasa. For which we have some
training data files.

Stories: Stories are the path that a chatbot follow on every conversation, based on the
intent extracted.

## test_story <!-- name of the story -->


* greet
- action_ask_howcanhelp
* inform{"location": "rome", "price": "cheap"} <!-- user utterance, in format intent{entities}
-->
- action_on_it
- action_ask_cuisine
* inform{"cuisine": "spanish"}
- action_ask_numpeople <!-- action that the bot should execute -->
* inform{"people": "six"}
- action_ack_dosearch

Domain: It stores all the information for the Rasa Core Model, listing from intents to
actions.

Intents: <!-- Intents Declaration -->


- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy

Actions: <!-- Actions Declaration -->


- utter_greet

Templates: <!-- Templates Declaration -->


utter_greet:
- text: "Hey! How are you?"

Actions in Rasa:

Actions are python code that is executed when they are called, Templates are
also actions but all actions are not templates. Before going further here are some inbuilt
actions that rasa core offers

1. action_listen
2. action_default_falllback
3. action_restart

Utterance Actions are the static response and starts with utter_ as prefix
Example: utter_greet

Custom Actions: This are the actions that run on developer python script. Custom
actions can be very useful in writing our own python code. We can integrate third
party APIs and other logic. Below is the custom action for a restaurant,
​ asa_sdk​ ​import​ Action
from​ r
from​ r​ asa_sdk.events​ ​import​ SlotSet

class​ ​ActionCheckRestaurants​(Action):
​def​ ​name​(​self​) ​->​ Text:
​return​ ​"action_check_restaurants"

​def​ ​run​(​self​,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) ​->​ List[Dict[Text, Any]]:

cuisine ​=​ tracker​.​get_slot(​'cuisine'​)


q ​=​ ​"select * from restaurants where cuisine='{0}' limit
1"​.​format(cuisine)
result ​=​ db​.​query(q)

​return​ [SlotSet(​"matches"​, result ​if​ result ​is​ ​not​ ​None​ ​else​ [])]

You might also like