How To Create A Domain_6 Bot With Python
One Easy Way to Develop Your Own Chatbot
A step-by-step tutorial on how to build a chatbot with RASA
How often that phrase came out of your mind when you have a chat with "someone" in your favorite app or messenger?
I believe almost all of us have had the experience of interacting with a chatbot. Sometimes we could immediately know that it's a bot, but sometimes we couldn't since it replied to our messages in a very natural way.
Here, in Bukalapak, we have also developed chatbots for several use-cases. And yes, just like what we usually think, building such a full-fledged chatbot required a complex system that needs a massive effort which is not very suitable for our individual needs.
Fortunately, thanks to this open-source era and the advancement of Artificial Intelligence,
you can now build your own chatbot easily without even have to think about that complex system anymore!
Without wasting any more time, let's take a deep breath, make a cup of tea, and I will guide you on how to build a chatbot easily with the RASA framework!
Chatbot Types and Use-Cases
First of all, we will discuss a bit about types of chatbots and some use-cases that can be tackled by them. In general, there are three types of chatbots:
- Transactional: specifically designed to only provide a fixed set of response choices, and are usually presented in the form of buttons.
- Conversational: arguably "smarter" than transactional chatbot because it is able to receive responses and replies from and to humans using natural language. This type of chatbot uses AI or Artificial Intelligence as its backbone.
- Hybrid: a combination of transactional and conversational chatbot.
As for the use-cases, there are numerous use-cases that can be tackled by using the power of chatbot.
We at Bukalapak employ chatbot for several use cases. Perhaps, one prominent use case is utilizing chatbots to help Customer Service agents in doing their job. Moreover, there are tons of use cases of chatbots in our daily lives that you might never think of, and I will list some of them in this article.
Mental Health Assistant
What? A mental health chatbot that asks people how they're feeling and what is going on in their lives in the format of brief daily conversations.
Impact? Woebot led to significant reductions in anxiety and depression among people aged 18–28 years old.
Personal AI Assistant
What? An AI assistant that can be embedded in your portfolio. The assistant can answer anything about you.
Impact? Helps to answer FAQ and personal branding.
Virtual Restaurant Waiter
What? A virtual waiter that answers customers' questions and takes orders
Impact? Reduce cost and supports health protocol especially in this pandemic situation.
In this article, I will give a tutorial on how to build a chatbot related to the latest use case I mentioned above. But first, let's get familiarized with the framework we are going to use, RASA.
RASA Framework
Most of the bots from previous examples were developed by companies that focus on chatbots and are already professional in this regard. The question is:
Is it really that difficult to develop our own bot?
Fortunately, the answer is NO. Thanks to RASA, developing a chatbot is much easier now.
From the above image, we can see all the important things you need to know about RASA at a high level. One other point, RASA is the type of hybrid chatbot which is the combination of transactional and conversational chatbot.
Now, we will go into more details about all of the components available in RASA.
As you can see, there are only 7 components in RASA that needed to be adjusted in your chatbot development. The remaining tasks are handled by the environment that has been developed by the RASA team!
Step-by-Step Tutorial
1. RASA Installation
First thing first, we have to install RASA. We can do it simply by using pip install. Here, I use the RASA 2.x version.
2. Next, we can directly initialize a default project.
3. We will first focus on the stories.yml
component.
Let me give you an example of one story.
Suppose a user is talking to a bot and asks, "Hey, are you a bot?".
Getting a message like that, the first thing the bot will do, especially for bots developed using this RASA, is to classify the intent or purpose of the message given by the user.
Suppose the bot has successfully classified its intent as an intent called 'bot_challenge'.
Then, of course, the bot must respond to the message.
Maybe he answered with "Yes, I am a bot, but no need to worry, you can chat with me as you chat with a human".
But the question is, how can we train our bot to respond appropriately like that?
This is where stories come in. A story consists of the story name and steps of the story. In short, these stories contain information on how bots need to react to messages received from users.
And remember the reaction given is of course not just once because it is possible that the user will respond again to the reaction our bot gives. We can manage all these things in this stories.yml
file.
Of course, there are lots of possible stories that we need to tackle. And we may not specify one by one each of these possibilities. Because if we use that approach, then we don't need to use AI here.
Then, how can RASA exploit these limited stories as training data from its model?
During the training phase, we can combine several stories as a unit. With this approach, the bot can learn from more data which is a combination of stories that have been created by us.
How to combine?
We only need to specify how many stories we want to combine with the augmentation
parameter. The rest will be handled by the RASA system.
4. Next, we have to provide the training data in the nlu.yml
component.
Previously in stories.yml
, we put information in the form of any flows that are within the scope of our bot domain. There is also a section where the bot needs to classify the intent of the message given by the user.
How do bots know the intent? Surely the bot must have some prior knowledge, right?
In this nlu.yml
component, we can provide some examples of sentences for each intent that our bot is expected able to detect. These examples are used as the training data for our bot so that it is able to learn to recognize what's the intent of each sentence.
Apart from that, we can also provide additional information in the form of entities that the bots can detect. An entity is an object that the user is talking about.
5. Next, we will focus on the domain.yml component.
From the previous 2 components, stories.yml
and nlu.yml
, we've set up what possible stories our bot can handle along with the training data for intent classification.
Now, we will discuss the next component which is domain.yml
. Basically, this component acts as a bridge between the components of our bot. Almost all important information needs to be noted in the domain.yml
, such as:
- List of intents that can be handled by bots, basically just copy and paste the intent title from all intents in the
nlu.yml
file - List of entities, just like intents, we only need to copy and paste the entities title from the
nlu.yml
file - Slots, is a variable that stores information from other sources
- Response, is the set of predefined responses our bot is capable of answering. So, the bot here doesn't generate its own response, but we have given it a case-by-case pre-defined set of responses.
- Actions, is simply the action the bot could do. Actions can be in the form of replying to messages or finding information on the web using the API or connecting to the recommender system as in our case for this virtual assistant waiter.
One thing to keep in mind, these three files need to be synced because they contain overlapping information, where nlu.yml
and stories.yml
contain more detailed information, while domain.yml
acts as the master of our bot.
6. Next, we have to list all of our custom actions in the actions.py component.
As mentioned earlier, actions can be either reply to messages from predefined responses or pulling information from other sources. If we choose to pull information from another source, then we need this actions.py
component.
Basically, we can do almost everything that is feasible in Python using this component.
7. Turn on the action endpoint in the endpoint.yml component.
8. The last component we have to deal with is the config.yml.
Of course, we have to configure the settings for how the entire model should be trained, what are data cleaning methods to be used, what model do we want to use, and what parameters do we want to choose.
All of that can be done using only the
config.yml
component!
RASA has also provided the default settings so that we don't have to be overwhelmed by all of these setups.
9. Finally, we can train our bot using a very simple command.
10. Further development using RASA X.
RASA X is the GUI provided by RASA to support further development and analysis of our developed chatbot.
We can activate RASA X by simply using the below command.
Here's an example of what RASA X looks like.
RASA X can be used as a UI for testing our bot results, then it can also be used to share the link from our bot and give it to users before deploying it.
It is important to get feedback from users so that we can improve our training data.
It will be difficult if we only use assumptions such as stories that need to be handled, or intents, etc. It could be that our assumptions are not quite right or maybe we also need to add other stories. Therefore, getting feedback from users is very important.
We can share the link to our bot with the user, then we can live to monitor on the RASA X dashboard. We are also able to directly edit all of the seven components via RASA X.
11. The result.
Final Words
Congratulations for keeping up to this point! Hopefully, you now can appreciate the complexity of building a chatbot from scratch. That said, thanks to open source development, we can build our own chatbot with ease, as I demonstrated in this article.
If you love this type of content, please kindly follow my Medium account and also the Bukalapak Data Medium account to get the notifications for other future posts.
About the Author
Louis Owen is a Data Science enthusiast who always hungry for new knowledge. He pursued a Mathematics major at one of the top universities in Indonesia, Institut Teknologi Bandung, under the full final-year scholarship. Recently, in July 2020, he was just graduated from his study with honors.
Currently, Louis is an AI Research Engineer at Bukalapak , where he helps to deliver various ML-based solutions related to Investment & Financing as well as Natural Language Processing use-cases.
References
How To Create A Domain_6 Bot With Python
Source: https://medium.com/bukalapak-data/one-easy-way-to-develop-your-own-chatbot-dacdb231957c
Posted by: moultrieheadee.blogspot.com
0 Response to "How To Create A Domain_6 Bot With Python"
Post a Comment