Adding contextually relevant sub-intents is one of the important elements in building conversational bots. Contextually relevant intents could be required for various purposes like taking a different path in the dialog flow, amending previously provided entity values, etc.
We have seen how to use the contextual data in combination with the interruption handling to achieve a more natural and human-like interaction with the bot in How to Manage Context Switching. This feature primarily aims to let you define the interruption behavior across any two intents. Defining behavior for contextual relevant intents with custom fulfillment behavior can be difficult using this feature.
With the objective of simplifying the contextual NLU, the Group node functionality has been enhanced with intent scoping, training, and fulfillment configuration, refer here for details.
In this How-To, we will explore a scenario in a Flight Booking Bot which includes digressions, amending input values, and contextual follow-ups queries. We will be using the Group Node to achieve all this easily and from a single place.
Problem Statement
During the course of booking a flight ticket:
- the user might change their mind regarding the destination, and/or the travel date;
- the user might want to check for weather information, that is not part of the book flight task, before confirming the booking;
- the user might have a follow-up question regarding their booking;
- the user may choose to cancel the task.
Prerequisites
In this how-to, we are using a Flight Details bot with the following dialog tasks
- Book Flight dialog which
- prompts the user for source, destination, date of travel, and web check-in options;
- display a booking confirmation message (for simplicity we have not added the service call to do the actual booking);
- check if the user needs any further assistance;
- end the conversation.
- Weather Report dialog which
- prompts the user for the location they want the weather report;
- display the weather report message (for simplicity we have not added the service call to do the actual weather lookup);
Implementation
Amend Entities
Let us look at the case where the user might want to change the destination and/or travel date.
Following are the steps to achieve the same:
Step 1: Group the nodes for sub-intent scoping:
The first step would be to define the scope for the sub-intent which would trigger changes to the destination and travel date.
Step 2a: Define sub-intents, train and set behavior properties for destination and travel date changes
Next, we need to define the sub-intents, add training and optionally set the conditions when the sub-intent should be identified, and the bot behavior in such a case.
Let us first consider the case of enabling changes to destination and travel date:
- From the Entity Group window, click the Add Intent button
- Create Intent for allowing a change in travel date and destination
- Enter a name for the intent, say Change Date and Destination
- Enter a description
- Using the Machine Learning option under Training, let us train with user utterance that would identify this intent
- Add an utterance, say “Let’s try a different date and destination“
- Optionally add another utterance, say “I have changed my mind, let’s start over again“
- Train the sub-intent for this utterance
- Reset the destination and travel date values:
- In the Set Context Variables option under Fulfillment reset the destination city and the travel date using the following key-value pairing:
Key Value context.entities.To null context.entities.When null
- In the Set Context Variables option under Fulfillment reset the destination city and the travel date using the following key-value pairing:
- Optionally Present a Message to the user regarding the changes, say “Alright, starting all over again”
- Under Transition Flow, take the flow back to the From entity node using the Jump To A Node option. Since the From entity value is not changed, the flow would go to the next entity To and When
- Create Intent for allowing a change in travel date and destination
Step 2b: Define sub-intents, train and set behavior properties for destination changes along with NER training
Continuing with the above use case of changing original entity values, chances are users would be specifying the changes in their utterance. Consider the case where the user indicates the change in the destination in their utterance.
- Click the Add Intent button to add a new sub-intent
- Create Intent for allowing a change in destination
- Enter a name for the intent, say Change Destination
- Enter a description
- Using the Machine Learning option under Training, let us train with user utterance that would identify this intent
- Add an utterance, say “Instead let’s go to Chicago“
- Using the NER approach, annotate the To entity in the utterance.
- Train the sub-intent for this utterance
- Set the destination values to the captured value. This value is stored as an identifiedSubIntents array in the context object. Note that the latest identified sub-intent is always stored at the 0th index of the array.
- In the Set Context Variables option under Fulfillment set the destination city using the following key-value pairing:
Key Value context.entities.To context.identifiedSubIntents[0].entities.To
- In the Set Context Variables option under Fulfillment set the destination city using the following key-value pairing:
- Optionally Present a Message to the user, say “Changing destination to {{context.identifiedSubIntents[0].entities.To}}”
- Under Transition Flow, take the flow back to the From entity node using the Jump To A Node option.
- Create Intent for allowing a change in destination
Contextual Digression
Conversations never happen in a linear fashion. Users might digress from the main intent and then come back to it.
Let us look at the steps in achieving this using Group.
While booking a flight, users might want to check the weather at the destination city before committing to the date of travel. They might ask “What is the weather like at XYZ city tomorrow” while the bot is waiting on the travel date input. In such a case, the user should be presented with the weather information before being re-prompted for the date.
Same as the above Amend Entity case, the steps would be to set the scope for the Weather Report dialog, train, and set the behavior.
- Since the scope for a query related to Weather Report would be anytime before the actual booking, we will go with the same Entity Group used for the Amend Entity use case.
- Add a Dialog Task node to run the Weather Report dialog from the current dialog.
Tip: Add Weather Report Dialog task to an existing node and then remove it from the connection, making it a floating node – not connected to any other node. - This task needs location as input and in our case, it can be set to the destination city entered by the user.
- The connection rule for this dialog should loop back to the From entity. This would ensure that the user resumes from where he left in the original conversation flow.
- From the Entity Group settings dialog
- Add New intent
- Select Weather Report from the Choose Intent drop-down
- Training is populated from the Weather Report dialog training utterances, patterns, and rules. You can add to this list, but be aware that this would be common training data and would affect all the instances where Weather Report is used.
- Ensure that the Transition Flow is set to Jump to a Node and the Weather_Report node is selected
- Using Talk to Bot test the scenario
Contextual FAQ
Group nodes can also be used to answer contextual queries.
A user might have a query regarding the check-in process after completing the booking.
Let us see how that can be achieved, the steps are the same as amending input values, contextual digression – scoping, training and behavior definition:
- Since the scope now would be after booking confirmation, we will group the nodes post-booking formalities
- Name the group, say Query Group
- Enter a Description
- From the Query Group settings dialog, Add New intent
- Create Intent for allowing a query from user
- Enter a name for the intent, say Checkin Query
- Enter a description
- Using the Machine Learning option under Training, let us train with user utterance that would identify this intent
- Add an utterance, say “What time should I report at the airport?“
- Optionally add another utterance, say “What is the check in time?“
- Train the sub-intent for this utterance
- Use the Present a Message entry to answer the user, say “Since you have opted for web-check-in, you need to report 30mins before flight take-off”
- Ensure that the Transition Flow is set to Resume the Dialog
- Create Intent for allowing a query from user
- Using Talk to Bot option, test for the scenario.