Chatbot from basic to custom classification 1.0 | RASA
INTRODUCTION
With Advancement in NLP and open source framework available various organizations are trying to implement automated reply based bot.
In this article i will talk briefly about,
- What is RASA?
- Its architecture,
- How to implement it,
- How to implement custom intent and custom reply with rasa.
First let us understand what chatbot actually is.
A Chatbot is an application which can initiate a conversation on behalf of a human with some input(text/audio) from the user. It can be a simple rule based bot or an intelligent application using NLP understanding. Different use cases of Chatbot can be:
Customer Care
FAQ,S
Companies Query
Custom made for internal application
RASA
Rasa is a NLU powered engine which is capable of making text or speech based interaction. It’s incredibly powerful and is used by developers worldwide to create chatbots and contextual assistants. You can build, deploy, and host the implementation internally which makes the chatbot and the related data more secure.
Implementing Chatbot:
- Create a new folder for the chatbot Project.
- It is always good practise to create a new environment for any of the projects based on python.
- Create a new environment from conda.
conda create — name rasa
- Then activate environment with command
activate rasa
- Run command pip install rasa for all dependency.
In that terminal , type:
rasa init
- Then you will end up with predefined structure which rasa would have build.
actions.py code for your action implementation. In case you want RASA to call an external API or Rest API. you can define custom actions here.
Nlu.yml here you can define intents and training data for the model .
domain.yml here you can combine different intent with custom replies.
Source Code:
Add following lines to nlu.yml:
- intent: document_statusexamples: |- [GMO](document)- where is gmo crawler?(document:gmo crawler)- [CDI](document)- who worked on cdi?(document:cdi)- who have knowledge about chatbot?[chatbot]- chatbot(document:chatbot)- [chatbot](document)
Add following code lines to stories.yml
- story: document spacesteps:- intent: document_status- action: action_custom_doc
Now we will create a custom reply in the actions.py method. You can use the following code lines to make the basic understanding .
class ActionCustomdoc(Action):def name(self) -> Text:return “action_custom_doc”def run(self, dispatcher: CollectingDispatcher,tracker: Tracker,domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:slot_name = tracker.get_slot(“document”)print(“slotname”, slot_name)dispatcher.utter_message(text=”your document is created by Mr.X “)return []
In the domain.yml file we will add entities and slots to define custom intent and entities.
intents:- greet- goodbye- affirm- deny- mood_great- mood_unhappy- bot_challenge- document_statusactions:- action_custom_docentities:- documentslots:document:type: unfeaturized
In actions.yml we will have to uncomment the following piece of code to start our custom reply method:
action_endpoint:url: “http://localhost:5055/webhook"
Rasa Model Training and Testing
Next step is to train our model:
In conda terminal enter:
rasa train
This will train the model and save the file at location model.
In conda terminal enter:
rasa shell
This will trigger the bot .
Pros :
Easy To Understand and Implement
Chatbots Can be easily deployed or integrated over a wide range of channels.
Custom Actions Can be implemented very easily, which enables a developer to code desirable operations from a chatbot.
Supports a wide range of external policies and other open-source pipelines and frameworks like spacy, duckling, etc
Provides Interactive ways of deploying and testing, with single-lined commands.
Cons :
It might take some time to train your model, which is a bit annoying.
If the proper format or indentation is not followed, it won’t train the whole model. You have to manually evaluate the errors in every single line of model files.
You Need to have a proper environment set up with all prerequisites and appropriate pipelines and packages installed in that specific environment. Else, it won’t support the Extraction of entities and intents properly.
You Need to have a certain knowledge of Dockers and Kubernetes in order to deploy your chatbot online permanently.
Conclusion:
The Rasa framework is very flexible to support external pipelines and packages. This in turn makes it very easy for the developers to add custom stories, intent, slots, entities. Also being the open framework, a lot of contributions from developers make this framework updated.
Next thing is the custom actions that make our chatbot work easier, since it will make our desired operations come out in a very useful way, we can add custom actions with API and JSONS to fetch data from the database. Which makes customer engagement better.