Rasa Project Report
Rasa Project Report
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.
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
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 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.
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.
if typing.TYPE_CHECKING:
from rasa.nlu.model import Metadata
class MyComponent(Component):
provides = [] # Attributes that the component provide
language_list = [‘en’]
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.
Domain: It stores all the information for the Rasa Core Model, listing from intents to
actions.
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]]:
return [SlotSet("matches", result if result is not None else [])]