NLU Certified Workshop
1. What is Dialogflow
Dialogflow is a natural language understanding platform that makes it easy to design and integrate a conversational user interface into your mobile app, web application, device, bot, interactive voice response system, and so on. Using Dialogflow, you can provide new and engaging ways for users to interact with your product.
Dialogflow can analyze multiple types of input from your customers, including text or audio inputs (like from a phone or voice recording). It can also respond to your customers in a couple of ways, either through text or with synthetic speech.
Dialogflow CX and ES
Dialogflow provides two different virtual agent services, each of which has its own agent type, user interface, API, client libraries, and documentation:
Dialogflow CXProvides an advanced agent type suitable for large or very complex agents.
Dialogflow ESProvides the standard agent type suitable for small and simple agents.
Dialogflow CX and ES provide virtual agent services for chatbots and contact centers. If you have a contact center that employs human agents, you can use Agent Assist to help your human agents. Agent Assist provides real-time suggestions for human agents while they are in conversations with end-user customers.
The Agent Assist API is implemented as an extension of the Dialogflow ES API. When browsing the Dialogflow ES API, you will see these additional types and methods. If you are only using a Dialogflow virtual agent, you can ignore these extensions.
2. Intents & Entities
The best way to think of entities is akin to verbs and nouns in a sentence. Together they communicate what the user wants.
Intents can be a part of small talk, for example, "Hi how are you?" or they can have a business purpose, for example, "I would like to order an extra large pepperoni pizza". In this example, the intent would be an order intent and the entity would be pizza.
For example, you could create a weather agent that recognizes and responds to end-user questions about the weather. You would likely define an intent for questions about the weather forecast. If an end-user says "What's the forecast?", Dialogflow would match that end-user expression to the forecast intent. You can also define your intent to extract useful information from the end-user expression, like a time or location for the desired weather forecast. This extracted data is important for your system to perform a weather query for the end-user.
The following diagram shows the basic flow for intent matching and responding to the end-user:
Training phrases are example phrases for what end-users might type or say, referred to as end-user expressions. For each intent, you create many training phrases. When an end-user expression resembles one of these phrases, Dialogflow matches the intent.
For example, the training phrase "I want pizza" trains your agent to recognize end-user expressions that are similar to that phrase, like "Get a pizza" or "Order pizza".
You don't have to define every possible example, because Dialogflow's built-in machine learning expands on your list with other, similar phrases. You should create at least 10-20 (depending on complexity of intent) training phrases, so your agent can recognize a variety of end-user expressions.
Entity Set Up
To start, you will want to add the relavent entities to your bot. Imagine if you're building a weather bot, you would have to add each city in the word as an entity!
Now, this can be a daunting task and this is where Dialogflow really shines.
Dialogflow already comes with a number of preconfigured entities that have already been categorized for you for. For example, Dialogflow can automatically recognize dates, times, amounts, quantities, locations, phone numbers, emails, etc. You can get a full list here.
Additionally, you can add your own Entity to the existing system entities or even create your own entity types.
Here are some basic terms:
Entity type: Defines the type of information you want to extract from user input. For example, pizza toppings could be the name of an entity type. Clicking Create Entity from the Dialogflow Console creates an entity type. When using the API, the term entity type refers to the EntityType type.
Entity entry: For each entity type, there are many entity entries. Each entity entry provides a set of words or phrases that are considered equivalent. For example, if pizza toppings is an entity type, you could define these three entity entries:
scallion, green onion
bell pepper, sweet pepper
Entity reference value and synonyms: Some entity entries have multiple words or phrases that are considered equivalent, like the scallion example above. For these entity entries, you provide one reference value and one or more synonyms.
Additionally, you can create your own Entity Types and Categories.
You can create custom entities for matching data specific to your agent. For example, you could define a vegetable entity type that can match the types of vegetables available for purchase with a grocery store agent.
Dialogflow contexts are similar to natural language context. If a person says to you "they are orange", you need context in order to understand what "they" is referring to. Similarly, for Dialogflow to handle an end-user expression like that, it needs to be provided with context in order to correctly match an intent.
Using contexts, you can control the flow of a conversation. You can configure contexts for an intent by setting input and output contexts, which are identified by string names. When an intent is matched, any configured output contexts for that intent become active. While any contexts are active, Dialogflow is more likely to match intents that are configured with input contexts that correspond to the currently active contexts.
The following diagram shows an example that uses context for a banking agent
Input and output contexts
Input and output contexts are applied to intents. They work together to control conversation flow:
Output contexts control active contexts. When an intent is matched, any configured output contexts for that intent become active.
Input contexts control intent matching. While contexts are active, Dialogflow is more likely to match intents that are configured with input contexts that are a subset of currently active contexts.
With contexts, you can:
Control the order of intent matching.
Create context-specific intents with the same training phrases.
For example, consider the following intents:
When the end-user says I like dogs:
The pet-select-dogs intent is matched.
The output context is dogs, so it becomes the active context.
When the end-user says I like cats:
The pet-select-cats intent is matched.
The output context is cats, so it becomes the active context.
When the end-user says What do they look like?:
If dogs is the active context:
The dog-show intent is matched.
The end-user is shown a dog picture.
If cats is the active context:
The cat-show intent is matched.
The end-user is shown a cat picture.
If there is no active context:
The pet-init intent is matched.
The end-user is asked what kind of pet they like.
You can use follow-up intents to automatically set contexts for pairs of intents. A follow-up intent is a child of its associated parent intent. When you create a follow-up intent, an output context is automatically added to the parent intent and an input context of the same name is added to the follow-up intent. A follow-up intent is only matched when the parent intent is matched in the previous conversational turn.
You can also create multiple levels of nested follow-up intents.
Dialogflow provides many predefined follow-up intents for common end-user replies like "yes", "no", or "cancel". You can also create your own follow-up intents to handle custom replies.
For example, a hair stylist agent might have the following nested intents.
Intents are normally matched when an end-user expression matches an intent training phrase. However, you can also trigger intents using events. Events can be invoked in many ways.
There are two types of events:
Platform events: These built-in events are provided by platform integrations. They are invoked when platform-specific events occur. For example, the FACEBOOK_LOCATION event is invoked by the Facebook integration when an end-user accepts or rejects a request for the end-user's location.
Custom events: These are events that you define. You can invoke these events using either fulfillment or the API. For example, you might set a timed alert during a conversation, which invokes an event at a certain time. This event could trigger an intent that alerts the end-user about something.
By default, your agent responds to a matched intent with a static response. If you're using one of the integration options, you can provide a more dynamic response by using fulfillment. When you enable fulfillment for an intent, Dialogflow responds to that intent by calling a service that you define. For example, if an end-user wants to schedule a haircut on Friday, your service can check your database and respond to the end-user with availability information for Friday.
Each intent has a setting to enable fulfillment. If an intent requires some action by your system or a dynamic response, you should enable fulfillment for the intent. If an intent without fulfillment enabled is matched, Dialogflow uses the static response you defined for the intent.
When an intent with fulfillment enabled is matched, Dialogflow sends a request to your webhook service with information about the matched intent. Your system can perform any required actions and respond to Dialogflow with information for how to proceed. The following diagram shows the processing flow for fulfillment.