{"id":54048,"date":"2021-11-30T14:16:18","date_gmt":"2021-11-30T08:46:18","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=54048"},"modified":"2022-01-06T17:58:17","modified_gmt":"2022-01-06T12:28:17","slug":"smart-chatbot-implementation-using-rasa","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/smart-chatbot-implementation-using-rasa\/","title":{"rendered":"Smart Chatbot Implementation using RASA"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In the era of chatbots, besides imitating humans they can also perform complex tasks like booking tickets for movies etc. Out of various implementations,<strong> Rasa <\/strong>is an open-source implementation for <\/span><strong><i>Natural Language Understanding (NLU)<\/i><\/strong><span style=\"font-weight: 400;\"> and <\/span><strong><i>Dual Intent and Entity Transformer (DIET)<\/i><\/strong><span style=\"font-weight: 400;\"> models. It can interact with databases, APIs, conversational flows for interactive learning with reinforcement Neural network.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this study, various features of Rasa core are studied and up to much extent, it can perform complex tasks. Implementation details are studied like interaction with the database and API. Tracker Store has been examined by modifying the socket.io core file adding metadata to the user message data so that user IP and Port can be captured. Furthermore, the action, interactive learning and implementation details are tested on Pycharm IDE.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Rasa Conversational AI assistant is quite different from earlier traditional FAQ interactions as it is based on natural conversations means like how humans interact with each other by considering what earlier the context was sent and what actions are to be taken in reference to the contexts and gracefully handling the unexpected conversation and driving the conversation when the user drifts from normal conversation path and also improve over time thus it&#8217;s far beyond the FAQ Interactions.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">Rasa Conversational AI assistant normally consists of two components and they are <\/span><em><b>Rasa NLU<\/b><\/em><span style=\"font-weight: 400;\"> and <\/span><em><b>Rasa Core<\/b><\/em><span style=\"font-weight: 400;\">. Rasa NLU can be just treated like an ear that is taking inputs from users and Rasa Core is just like the brain which will take decisions based on user input.<\/span><\/p>\n<h4><b>Applications of Chatbot<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Chatbots today are being deployed across industries to assist customers (customer service), or engage with customers (sales and marketing), or do both. However, there are a few chatbot applications that are unique to each industry. Some key industries where chatbots are deployed are <\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Retail and eCommerce<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Travel and hospitality<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Banking, finance, and fintech<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Healthcare<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Media and entertainment<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Education<\/span><\/li>\n<\/ol>\n<h4><b>Why Rasa?<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Out of the different approaches tried, we went ahead with the RASA chatbot for implementation for HAWK (an internal platform). The main advantages of RASA over other chatbots are as below <\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Free and open source<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Easy to Use<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Highly customizable<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">On-premise, deploy on own server\/compatible with all cloud platforms<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">A growing community<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Can be integrated with popular messaging platforms<\/span><\/li>\n<\/ol>\n<h4><b>Features of Rasa<\/b><\/h4>\n<ul>\n<li>Extract meaning from messages<br \/>\n<span style=\"font-weight: 400;\">Turn free-form text in the English language into structured data. Supports multiple intents and both pre-trained and custom entities. Fully customizable NLU for any domain, industry, or use case.<\/span><\/li>\n<li>Hold complex conversations<br \/>\n<span style=\"font-weight: 400;\">Retain important context and hold back-and-forth conversations using machine learning-based dialogue management. Smoothly handle topic changes and seamlessly integrate business logic into conversation flows.<\/span><\/li>\n<li>Interactive learning<br \/>\n<span style=\"font-weight: 400;\">Generate training data by talking to your assistant, and provide feedback when it makes an error. Easily share your assistant with test users.<\/span><\/li>\n<li>Connect to commonly-used messaging channels<br \/>\n<span style=\"font-weight: 400;\">Run your assistant on Slack, Facebook, Google Home, IVR, custom channels, and more. Serve multiple channels with a single assistant.<\/span><\/li>\n<li>Integrate API calls<br \/>\n<span style=\"font-weight: 400;\">Use Rasa&#8217;s custom actions to interact with APIs, databases, and other systems. Connect with knowledge bases, content management systems, and CRMs.<\/span><\/li>\n<li>Leverage conversation-driven development<br \/>\n<span style=\"font-weight: 400;\">Build customer-centred virtual assistants by incorporating user insights and engineering best practices into every part of your team\u2019s workflow.<\/span><\/li>\n<li>Version and manage models<br \/>\n<span style=\"font-weight: 400;\">Track and manage your models promote to production or easily rollback. Integrate with automated testing and CI\/CD.<\/span><\/li>\n<li>Deploy anywhere<br \/>\n<span style=\"font-weight: 400;\">Ready-to-deploy Docker containers and orchestration to run Rasa on-prem, or via a preferred cloud provider.<\/span><\/li>\n<\/ul>\n<h4><b>Rasa Component<\/b><\/h4>\n<ul>\n<li>Rasa NLU<br \/>\n<span style=\"font-weight: 400;\">At this place, rasa tries to understand User messages to detect Intent and Entity in your message. Rasa NLU has different components for recognizing intents and entities of user messages, most of which have some additional dependencies.\u00a0<\/span><\/li>\n<li>Rasa Core<br \/>\n<span style=\"font-weight: 400;\">This is the place where Rasa tries to help you with contextual message flow. It can predict dialogue as a reply based on User messages and can trigger Rasa Action Server.<\/span><\/li>\n<li>Rasa X<br \/>\n<span style=\"font-weight: 400;\">It is a tool for Conversation-Driven Development (CDD), the method of listening to your user\u2019s requirements or queries and then further using those insights to reinforce your AI assistant. It\u2019s a browser-based GUI tool that will allow you to train a Machine Learning model by using GUI-based interactive mode. Rasa X is the latest release from Rasa that helps you build, improve, and deploy AI Assistants that are powered by the Rasa framework.\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\">It layers on top of Rasa Open Source and helps you build a better chatbot assistant as per your specific requirements is a free, closed source tool available to all developers and can be deployed easily anywhere.<\/span><\/li>\n<\/ul>\n<h4><b>Project Scope<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">The Scope of the project is to gather the data from the <\/span><b>Fresh Service knowledge base<\/b> <b>articles<\/b><span style=\"font-weight: 400;\"> which contains almost all the issues faced by the different clients till now and then based on those knowledge articles to build\/design a chatbot that can incorporate all the mentioned queries or issues. Hence, whenever a user or IT support team member needs to know the steps for the resolution of any query, they can directly chat with the bot instead of reaching out to any customer care or support executive.<\/span><\/p>\n<h4><b>Flow Chart<\/b><\/h4>\n<ul>\n<li style=\"list-style: none;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54410 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-1-1.jpg\" alt=\"\" width=\"826\" height=\"356\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-1-1.jpg 826w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-1-1-300x129.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-1-1-768x331.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-1-1-624x269.jpg 624w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/li>\n<li><span style=\"font-weight: 400;\">The message from the end-user is fed to the Rasa NLU (Interpreter) whose output is structured output containing the original text, the intent and entities if any.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> The tracker maintains the conversation state and receives the structured output from the interpreter.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> The output from the tracker is fed to the Policy, which acts on the current state of the tracker.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> The policy decides which appropriate next action is to be performed.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> The log of selected actions is maintained by a tracker.<\/span><\/li>\n<li>The appropriate response is provided to the user, using intents defined in nlu.md, like utter_response.<\/li>\n<\/ul>\n<h4><b>Rasa Architecture<\/b><\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54411 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-2-1.jpg\" alt=\"\" width=\"826\" height=\"612\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-2-1.jpg 826w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-2-1-300x222.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-2-1-768x569.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-2-1-624x462.jpg 624w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/p>\n<h4><b>Chatbot Workflow<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">The<\/span> <span style=\"font-weight: 400;\">working of the bot at the backend whenever a user enters any query is shown in the diagram below :<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-54412 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-3-1.jpg\" alt=\"\" width=\"826\" height=\"442\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-3-1.jpg 826w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-3-1-300x161.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-3-1-768x411.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2021\/11\/13-3-1-624x334.jpg 624w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><span style=\"font-weight: 400;\">The steps are :<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The user writes a query to the chatbot.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The chatbot looks into the NLU file to search for the intents and the entities (if any) found in the user\u2019s query.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The bot tries to find the relevant story in the Stories file on the basis of the intents found from the NLU file.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The bot finds the correct response corresponding to the intent referred to in the query and searches that response in the Domain file.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The bot finds from the Domain file if any custom action is defined for that particular story\/intent.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If any custom response is written then the bot refers to the Actions file and utters a response to the user-defined in the Actions file.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If any custom response is not written then the bot utters a response to the user from the Domain file.<\/span><\/li>\n<\/ol>\n<h4><b>Additional Features in Implementation<\/b><\/h4>\n<ul>\n<li>Addition of intents<br \/>\n<span style=\"font-weight: 400;\"> Added the account info and the intents for each query for a particular account and also configured the possible examples for each intent which the user can ask the chatbot. For example, I want to create new VPN users for production systems.<\/span><\/li>\n<\/ul>\n<ul>\n<li>Addition of stories<br \/>\n<span style=\"font-weight: 400;\">Added the stories in a way that possible multiple queries could be handled by the chatbot in a single conversation as well as individual queries.<\/span><\/li>\n<\/ul>\n<ul>\n<li>Enabled the fallback policy for chatbot<br \/>\n<span style=\"font-weight: 400;\">Fallback policy means what message the bot should utter to the user in case the user enters any unrelated or irrelevant query. For example, if a user asks \u201cWhat is 2+2?\u201d then the bot should utter \u201cI didn&#8217;t understand that, kindly rephrase your query\u201d.<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"font-weight: 400;\">Account Security:<br \/>\n<span style=\"font-weight: 400;\"> Added a custom feature where a user of one account can only use the chatbot for queries configured in chatbot for that particular account. If the user tries to enter any query of another account then the response would not be visible to the user, hence making it more secure.<\/span><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<ul>\n<li>User\u2019s Satisfaction:<br \/>\n<span style=\"font-weight: 400;\">Once the query of the user is answered, the bot should pop up a message with YES\/NO buttons asking whether the user\u2019s query was resolved by the response given by the chatbot or not.\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For example, If yes, then utter a message \u201cGreat! Goodbye. Have a nice day!\u201d\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If the user is not satisfied with the query&#8217;s response the bot should reply \u201cPlease contact a support executive for more help.\u201d<\/span><\/p>\n<ul>\n<li>Handling of wrong account name being entered<br \/>\n<span style=\"font-weight: 400;\">If the user by mistake or intentionally provides the wrong account name then the bot must give a reply that the user has entered the wrong account name and request to enter the correct name. Once the correct account name is entered, the bot will utter the correct account name and will ask \u201chow may I help you\u201d.<\/span><\/li>\n<\/ul>\n<ul>\n<li>Handling queries that are exactly not relevant<br \/>\n<span style=\"font-weight: 400;\"> Handling the query which is exactly not relevant (i.e. somewhat related to the configured queries in the chatbot but don&#8217;t have any response added for that) and provide the response for those queries.\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For example, query configured is \u201chow to create a database backup\u201d and instead\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">the user asks \u201cI want to create a database\u201d, then the bot should ask\/confirm whether the user wants to create a new database or to create a database backup. If the query response is configured then provide the correct response else utter that this query cannot be handled at that point of time or ask the user to be more precise.<\/span><\/p>\n<ul>\n<li>Added the welcome message<br \/>\n<span style=\"font-weight: 400;\">Whenever the user login into the HAWK portal and opens a chatbot window, he will be greeted by the bot with a welcome message.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\">Integration with frontend<br \/>\n<span style=\"font-weight: 400;\"> Integrated RASA backend code with Webchat widget (a React.js component for frontend) and modified the graphic user interface as per the HAWK&#8217;s theme.<\/span><\/li>\n<\/ul>\n<h4><b>Conclusion &amp; Future Scope<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">From the study, it is concluded that rasa core features like slots, forms, supervised interactive learning, API integration, and database makes it a complete framework that can be used to perform highly complex tasks. The chatbot based on rasa has more capabilities than any open-source alternative. Further, in this paper, the internals of rasa has been modified to carry out custom data logging of client IP and port. All internals and custom action have been studied which further states that rasa is a completely open-source framework for the development of chatbots and for the developers who don\u2019t want to dig into the internals of natural language processing.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the future scope of this study, voice and face recognition engines can be integrated for more complex tasks like ATM cash withdrawal. Performance may be enhanced with the use of various learning procedures of machine learning.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>In the era of chatbots, besides imitating humans they can also perform complex tasks like booking tickets for movies etc. Out of various implementations, Rasa is an open-source implementation for Natural Language Understanding (NLU) and Dual Intent and Entity Transformer (DIET) models. It can interact with databases, APIs, conversational flows for interactive learning with reinforcement [&hellip;]<\/p>\n","protected":false},"author":1418,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":63},"categories":[4831,1],"tags":[1397,4904,3387,4905],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54048"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1418"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=54048"}],"version-history":[{"count":11,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54048\/revisions"}],"predecessor-version":[{"id":54415,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/54048\/revisions\/54415"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=54048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=54048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=54048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}