Improving Flow of Chatbots with RASA Events

Mohit Bansal | 18th November 2019

The conversational skills of artificial intelligence are breaking new grounds with rapid algorithmic advancements and sophisticated frameworks. One such open-source chatbot framework, RASA, is gaining momentum with its contextual and human-like interaction abilities. Development of chatbots with RASA’s natural language understanding (NLU) and dialogue engine, RASA Core, enable businesses to resolve complex user queries. Today, global businesses are exploring chatbot development services backed by RASA’s machine learning algorithms for enhancing user experiences across digital platforms.

This blog post guides developers and businesses through RASA events, a functionality that sequences conversation to streamline user conversations.

 

Understanding RASA events

Every conversation in RASA is represented as a sequence of events. These events cover important user tasks and queries that are categorized as-

1) General Purpose events- It envelopes setting up of slot, restarting, pausing, and resuming a conversation, forcing a follow-up action, and more.

2) Automatically Tracked Events- It entails a user’s conversation with the interface, with the functionality to undo a message and log an executed action.

To create a chatbot with human-like capabilities, it is very important to have the availability of context and flexibility to manage certain events. This functionality is assured while building chatbots with RASA events and hence improves the power of a chatbot.

Also, RASA’s underlying Python language enables real-time modification and bug detection supported by rich libraries of tools. Its pre-defined environments enable developers to analyze data and build natural language processing (NLP) solutions and chatbots with RASA efficiently.

Also Read- Business Benefits of Using Python for AI Projects

 

General Purpose Events

General-purpose events are related to the context (which can be managed with the help of slots) and the flow of the conversation.

In RASA, the context of a conversation can be handled by using slot values and it helps to decide the flow of chat. Slot values can be used in the user stories to provide context to the conversation and decide the next action.

Events provide flexibility to control the context by manually setting or resetting the slot values from custom actions.

Chatbot development services with RASA

                                                        RASA bot assistant built by Oodles AI in action.

For instance, consider a case where a pet shop has a chatbot on its website and it provides the list of cats or the list of dogs on request of the user. If the user writes “Show me dogs’ list,’‘ the bot will run a custom function to fetch a list of dogs. If the user writes “Show me cats’ list,” the bot will run a custom function to fetch the list of cats. The list contains the pet names in both cases. In order to listen to the sound of a pet, the user can write – ‘My hello to “pet_name” ‘. This will, in turn, run a custom action “say_hello_to_pet” which will search the list of dogs or list of cats, match the pet name and play sound corresponding to that animal.

Following is the code.

nlu.md:

## intent:dog_list

– show me list of dogs

– show me dog list

– dog list

– list of dogs

– available dogs

## intent:cat_list

– show me list of cats

– show me cat list

– cat list

– list of cats

– available cats

## intent: hello_to_pet

– hello to [“kitty’] (pet_name)

– hello to [“carry’] (pet_name)

– hello to [“tommy”] (pet_name)

stories.md: 

## dog list path

*dog_list

– action_get_dog_list

## cat list path

*cat_list

– action_get_cat_list

## hello to pet

* hello_to_pet

– action_hello_to_pet

actions.py: 

class ActionGetDogList(Action):

    def name(self) -> Text:

          return “action_get_dog_list”

    def run(self, dispatcher, tracker, domain):

          # code to fetch list of dogs and return it to UI

          return []    

 

class ActionGetCatList(Action):

    def name(self) -> Text:

          return “action_get_cat_list”

    def run(self, dispatcher, tracker, domain):

          # code to fetch list of cats and return it to UI

          return []     

 

class HelloToPet(Action):

    def name(self) -> Text:

          return “action_hello_to_pet”

    def run(self, dispatcher, tracker, domain):

          pet_name = tracker.getslot(“pet_name”)

          # conflict. search dog list or cat list?

          return []  

 

In action HelloToPet, it is visible that there is confusion about whether to search the dog list or cat list to match pet_name. Even if both lists are searched for matching, a problem will occur in a scenario like if “carry” is a name available in both cat and dog list. Here we can use the SlotSet event as a part of list search actions to set an entity “animal”. We can use the value of this slot to get a context of which animal the user is interested in. The following is the updated action file.

actions.py: 

class ActionGetDogList(Action):

    def name(self) -> Text:

          return “action_get_dog_list”

    def run(self, dispatcher, tracker, domain):

          # code to fetch the list of dogs and return it to UI

          return [SlotSet(“animal”,”dog”)]     

 

class ActionGetCatList(Action):

    def name(self) -> Text:

          return “action_get_cat_list”

    def run(self, dispatcher, tracker, domain):

         # code to fetch the list of cats and return it to UI

          return [SlotSet(“animal”,”cat”)]     

 

class HelloToPet(Action):

    def name(self) -> Text:

          return “action_hello_to_pet”

    def run(self, dispatcher, tracker, domain):

          pet_name = tracker.getslot(“pet_name”)

          animal = tracker.getslot(“animal”)

          if animal == “dog”:

              #match from dog list

         if animal == “cat”:

              #match from cat list

         return []  

To clear a particular slot, use SlotSet(“slot_name”, “None”) in the return statement of the function. To clear all context and reset all slots, use AllSlotsReset() in the return statement of the function. Slot values can also be used in user stories to decide the prediction of the next function based on slot values.

Events also provide the functionality to pause or resume a conversation. Returning ConversationPaused() event from action will pause the conversation and bot will stop taking user input. Similarly, ConversationResumed() event will resume the conversation. ReminderScheduler() event allows the asynchronous execution of a custom function at any specified time.

Also Read- Deploying TensorFlow and Keras for Deep Learning Models

 

Automatically Tracked Events

Automatically tracked events are related to the actions and utterances. In some situations, the bot needs to assume some default inputs from the user to automatically call an intent to run a function. Consider a case in which there are two custom actions ActionShowList and ActionUpdateList which are called independently when corresponding two different intents are classified.

Following is the stories code:

stories.md: 

## show list 

*show_list

 – action_show_list

 ## update list

*update_list

 – action_update_list

If there is a scenario that you want to change the functionality to automatically call ActionShowList after ActionUpdateList, events can be used. The following code shows the usage of the UserUttered event.

actions.py:

class ActionUpdateList(Action):

    def name(self) -> Text:

          return “action_update_list”

    def run(self, dispatcher, tracker, domain):

          # code to update the list.

          return [UserUttered(text=”/show_list”, intent = {“name”:”show_list”, “confidence”:1}, entities=[])]     

As soon as the first function completes, the UserUttered event will create an input on behalf of the user which directly classifies the required intent and the corresponding action is called.

Similarly, BotUttered is an event that represents the utterance of a response from the bot. We can also undo an action or a user message using UserUtteranceReverted and ActionReverted respectively.

Also Read- Automating Business Interactions with Whatsapp Chatbots

 

Developing Intelligent Chatbots with RASA and Oodles AI

We, at Oodles, have experiential knowledge in using Python for building chatbots with RASA, virtual assistants, and conversation AI models. Our AI development team deploys comprehensive neural networks to build machine learning models for manufacturing, retail, eCommerce, healthcare, and other global businesses. We combine AI’s NLP and computer vision technologies to build intelligent chatbot interfaces that fulfill the customer service requirements of businesses.

Talk to our AI team to know more about our Chatbot and AI app development services.

About Author

Mohit Bansal

I am a tech enthusiast and always ready to learn new things. I have good skill in Python language.

No Comments Yet.


Leave a Comment

Name is required

Comment is required




Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us