Reader small image

You're reading from  Conversational AI with Rasa

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801077057
Edition1st Edition
Tools
Right arrow
Authors (2):
Xiaoquan Kong
Xiaoquan Kong
author image
Xiaoquan Kong

Xiaoquan is a machine learning expert specializing in NLP applications. He has extensive experience in leading teams to build NLP platforms in several Fortune Global 500 companies. He is a Google developer expert in Machine Learning and has been actively involved in contributions to TensorFlow for many years. He also has actively contributed to the development of the Rasa framework since the early stage and became a Rasa Superhero in 2018. He manages the Rasa Chinese community and has also participated in the Chinese localization of TensorFlow documents as a technical reviewer.
Read more about Xiaoquan Kong

Guan Wang
Guan Wang
author image
Guan Wang

Guan is currently working on Al applications and research for the insurance industry. Prior to that, he was a machine learning researcher at several industry Al labs. He was raised and educated in Mainland China, lived in Hong Kong for 10 years before relocating to Singapore in 2020. Guan holds BSc degrees in Physics and Computer Science from Peking University, and an MPhil degree in Physics from HKUST. Guan is an active tech blogger and community contributor to open source projects including Rasa, receiving more than10,000 stars for his own projects on Github.
Read more about Guan Wang

View More author details
Right arrow

Chapter 5: Working with Response Selector to Handle Chitchat and FAQs

Most chatbots have simple FAQ and chitchat functions. Both types of functions involve knowing how to choose an appropriate response to a user's request. These functions sound simple, but in reality, they actually involve a lot of work. If we use one intent to represent an FAQ or chitchat intent from the user and pair it with an action, the story will become both complicated and inefficient. Rasa offers the Natural Language Understanding (NLU) ResponseSelector component, which is specifically used for FAQ and chitchat tasks.

In this chapter, you will learn how to define a question and find its corresponding answer. Additionally, you will learn how to configure Rasa to automatically identify a query (by finding a question that is semantically closest to the query) and give the corresponding answer. Finally, you will develop a practical understanding of these concepts with the help of the hands-on exercise...

Technical requirements

You can find all of the code-related files for this chapter in a directory named ch05 at the following GitHub repository: https://github.com/PacktPublishing/Conversational-AI-with-RASA.

Defining retrieval intents – the questions users want to ask

First, we need to define the question and its corresponding intent. Note that the intent name for the training data of ResponseSelector is different from the ordinary intent names that we have discussed in Chapter 2, Natural Language Understanding in Rasa. ResponseSelector needs to follow the <group>/<intent> format in order to name the intents. This also explains why even ordinary intents should not have / as part of their name.

Here is an example:

nlu:
  - intent: chitchat/ask_name
    examples: |
      - What is your name?
    - Who are you?
    - How can I call you?
  - intent: chitchat/ask_weather
    examples: |
      - What's the weather like on your side?
    - It's sunny and clear here on my side, what...

Defining responses – the answers to the questions

First, we put the data of the answers inside the responses field in domain.yml.

Here is an example:

responses:
  utter_chitchat/ask_name
    - text: My name is Sarah, a Rasa documentation bot.
  utter_chitchat/ask_weather
    - text: My place is always sunny and clear.

In Rasa, every intent with the name of <intent_name> has a response called utter_<intent_name> as the answer. In this way, there is a connection between the question and the answer. Although in this example, we use plain text responses, you can respond with richer formats. Because these answers are defined using Rasa's responses, you can use any features supported by the responses (including but not limited to pictures as a reply, a channel-specific reply, or custom reply content).

Now that the question and the corresponding answer are ready, in the next section, we will discuss...

Updating the configuration to use ResponseSelector

In order to perform an intelligent categorization of the questions, we need to use the ResponseSelector NLU component to train a model with existing training data. We need to add the ResponseSelector component to the pipeline. The ResponseSelector component depends on the featurizer and intent classifier, so make sure you place it after these components in your pipeline, as follows:

pipeline:
  - name: XXXFeaturizer # replace this with a real Featurizer
  - name: XXXClassifier # replace this with a real Classifier
  - name: ResponseSelector

In order to get the right answer based on the result from ResponseSelector, we need to initiate RulePolicy and implement a rule to do the mapping. Here is an example:

rules:
  - rule: map to chitchat
    steps:
    - intent: chitchat
    - action: utter_chitchat

Here, we create a rule...

Learning by doing – building an FAQ bot

In this section, the practical example has been designed to develop your practical understanding with regard to the concepts covered in the preceding sections.

We will create an FAQ bot based on a homemade toy-level dataset. This FAQ bot will answer questions for fresh graduates about participating in an interview at The Acme Corporation (a fictitious company from https://en.wikipedia.org/wiki/Acme_Corporation).

What are the features of our bot?

In this section, we will list all the functions this exercise project should provide. Let's start with the greeting and goodbye messages.

Handling greetings and goodbyes

Example #1: The bot responds to the user's greetings and provides a description of its own functions:

User: Hello!
Bot: Hello, I am Silly. I am a Rasa-based FAQ bot. I can help you with answering questions about the recruitment of fresh graduates for The Silly Company.

Example #2: The bot echoes...

Summary

In this chapter, you learned to use ResponseSelector to handle chitchat and FAQs. This usually requires three steps. First, you need to define retrieval intents, given enough samples about the questions that users might ask. Note that the retrieval intents are slightly different from ordinary intents (if you do not remember the differences, please try to review this chapter). Second, you need to define your responses, that is, the answers to the questions. Remember that there is a rule about how to pair the answers with the questions. Third, you need to update the configuration (both in the pipeline field and the polices field) to use ResponseSelector and RulePolicy to make the bot work correctly.

In the next chapter, we will examine how to use knowledge base actions to handle knowledge base question answering.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Conversational AI with Rasa
Published in: Oct 2021Publisher: PacktISBN-13: 9781801077057
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Xiaoquan Kong

Xiaoquan is a machine learning expert specializing in NLP applications. He has extensive experience in leading teams to build NLP platforms in several Fortune Global 500 companies. He is a Google developer expert in Machine Learning and has been actively involved in contributions to TensorFlow for many years. He also has actively contributed to the development of the Rasa framework since the early stage and became a Rasa Superhero in 2018. He manages the Rasa Chinese community and has also participated in the Chinese localization of TensorFlow documents as a technical reviewer.
Read more about Xiaoquan Kong

author image
Guan Wang

Guan is currently working on Al applications and research for the insurance industry. Prior to that, he was a machine learning researcher at several industry Al labs. He was raised and educated in Mainland China, lived in Hong Kong for 10 years before relocating to Singapore in 2020. Guan holds BSc degrees in Physics and Computer Science from Peking University, and an MPhil degree in Physics from HKUST. Guan is an active tech blogger and community contributor to open source projects including Rasa, receiving more than10,000 stars for his own projects on Github.
Read more about Guan Wang