Best practices to handle FAQ’s and Chitchat in a chatbot powered by Rasa
In the 3rd piece of my series of making production-level chatbots.
Today we’ll be covering the Best practices to adopt while handling
FAQs and Chitchats ( casual questions ) and yes if you haven’t gone through the first 2 pieces. Please have a look at them as well.
1. Your first AI-powered chatbot in 2 lines: https://medium.com/analytics-vidhya/rasa-chat-bot-voyage-1-a73b6e8e4947
2. What is Rasa and how it all works: https://medium.com/analytics-vidhya/rasa-chatbot-voyage-2-198e633e8c0e
FAQs and Chitchats are special cases in the life cycle of a chatbot.
When your assistant would respond with a fixed set of responses.
No matter what has happened previously in the conversation
or
You can say
FAQ’s and Chitchats are those questions which always have a static answer.
As you can see in the example below:-
Step by Step guide on how to define FAQs and Chitchats in your Chatbot:-
1. Updating Config file
For our FAQs, we want that our chatbot answers with a fixed set of answers. So to take care of this thing Rasa has something called Rules. To use rules, then you need to add the RulePolicy to your policies in your configuration file:-
Next, include the ResponseSelector in your NLU pipeline in your configuration file. The ResponseSelector requires a featurizer and intent classifier ( DIETClassifier here ) to work. So it should come after these components in your pipeline, for example :
By default, Rasa will only make one Retrieval Intent. To retrieve responses for FAQs and chitchat separately, use multiple ResponseSelector components and specify the retrieval_intent
key:
Now say you have 500 different FAQ questions for your website so instead of writing 500 intents. We will divide them into chunks of 50.
Now to handle the first 50 FAQs we will use single-action i.e utter_faq.So with a single rule by grouping them under a single retrieval intent called e.g. faq our work is done. Continuing this way we will have to write only 10 rules for 500 FAQ questions.
2. Defining Rules
You need to write only one rule for each retrieval intent. All intents grouped under that retrieval intent will then be handled the same way. The action name starts with utter_ and ends with the retrieval intent’s name. Write rules for responding to FAQs :
The actions utter_faq
and utter_faq2
will use the ResponseSelector's prediction to return the actual response message.
3. Making changes to NLU data
Now we will add NLU data for our retrieval intent.
Syntax of defining retrieval intent:-
< intent >/< retrieval intent>
In the above image, we have defined 2 retrieves for each retrieval intent.
Be sure to update domain.yml
this way in case of retrieval intents:-
4. Updating Responses
The response also follows the same convention when it comes to defining them.utter_<intent>/<retreival_intent>
.
Below we have defined responses for 2 retrieves of each retrieval intent.
Now train your model by typing rasa train
and talk to it with rasa shell
Perfect you have done great work!
Important Points to Remember
- Do not make more than 60–70 retrieves for each retrieval as it can decrease your classification confidence ( Personally experienced ).
- Always define more than or equal to 2 retrievals under one retrieval intent otherwise your Response selector won’t train
- Make sure you don’t have Rule policy alone in your config file other Policies like
MemoizationPolicy
andTEDPolicy
are also included.
Link for code: https://github.com/sahibpreetsingh12/travel-bot
HOPE YOU WILL LIKE MY WORK
If you did a clap 👏 would be awesome but
Combination of clap ,follow and share would be AMAZINGLY AWESOME 🔥 🔥 🔥