Make Your Chatbot Look Even Smarter! Hidden Features of Watson Assistant.
IBM Watson Assistant and its tooling support have been continuously improved for more than four years based on comments and feedback from users and customers alike.
The portfolio of various supported use-cases and features is therefore constantly growing and it is increasingly difficult to cover all of them in the documentation. This article will discuss some of these features that you may have been unaware of.
Let me ask you the following three questions about Watson Assistant:
- Did you know that British customers can enter dates in their native date time format and that one can change the locale during the very same conversation?
- Did you know that date (
@sys-date
) and time (@sys-time
) entities can have alternative values, such as “at five hours” meaning 5 am or 5 pm? - Do you know how to collect multiple e-mails or phone numbers in dialog skill?
If you have answered “no” to at least one of these questions then reading this article can bring some benefits to your chatbots.
Use New System Entities!
Here are some examples and tips on how to benefit from using new system entities in Watson Assistant, which were introduced for all 13 languages supported by Watson Assistant in January and May 2020.
Currently, all newly created dialog skills will have new system entities turned on by default. For older or imported skills one needs to enable new system entities manually.
Here’s how to make sure the dialog skill uses new system entities:
Now, let’s make sure system entities are enabled in the Entities tab:
Locale Specific Formatting of Dates
If the Assistant is to be used mainly in the United Kingdom (or in Europe in general), the users might be confused by the system recognizing the dates in the U.S. format which is the default for English language (English (US)
).
The first possible solution to this problem is to set system.locale
to en-gb
directly in the Welcome node.
en-gb)
in the Welcome nodeFor a simple “What day it was?” game one may create the following dialog node, which would output day of the week for a recognized @sys-date
entity:
With locale being set to en-gb
the user input “5/6/2020” would be recognized in the British English date format as June, 5, 2020.
It is possible to set the locale during the course of the conversation. The dialog node below asks the user to specify a locale when their timezone is Europe/London
. The user is given an option to choose from three different locales using the user-defined entity @locale
.
In the example below, the user has selected Canadian English locale possibly to be able to find out what was the date of the last Canadian Thanksgiving:
Note that the supported locales are listed in the Watson Assistant API reference for v2 API.
Date and Time Entities Value Alternatives
Let’s look at a restaurant booking scenario. In this scenario, the customer wants to book a table in a restaurant for a specific time. The customer might say “We will appear at 6”. Now, “at 6” is a bit ambiguous. The customer might have meant 6 am or 6 pm — 6 pm is the more probable one in this case.
The example below will show how to elegantly solve this kind of scenario with Watson Assistant and the slot filling capability with new system entities alternatives.
The first dialog node with slots presented below collects the day of the reservation, the time of reservation, and how many guests are to come:
Using the dialog node above, the user utterance “I want to book a table for 5 people today at 6” would be captured by this node as follows: “OK, reservation made for 2020–06–15 at 06:00:00 for 5 people”. The reservation time at 6 am is probably wrong.
Below, a solution to this problem is presented using a time entity alternative in found handler of the $time slot:
This works as follows. First, the system checks if the @sys-time
has alternatives (@sys-time.alternatives
) and then makes additional checks on the time frame. Let's say that the probable reservation time is from 11 am (inclusive) to 23 pm (exclusive). If the alternative is within this range, the system will use the alternative (6 pm) instead of the default value (6 am in our example). As a side effect, the chatbot may also state something like “I suppose you meant 18:00:00”. Then the conversation would look like this:
In practice, the formatting of the response would not be so technical and the .reformatDateTime(String format)
method could be used to make the output more appealing — such as “OK, reservation made for Monday at 6 pm for 5 people”. Please note that this approach still allows us to enforce the default values. For example, if the customer really wants to appear at 10 am:
Let’s look at another example of alternatives helping to disambiguate user input when the user enters “next Tuesday” (and today is Monday). The question is if the user means tomorrow or Tuesday next week. The following dialog node options would help to disambiguate this situation:
The conversation would then look like this (providing clickable options to choose from):
Alternatives of Last/This/Next Wednesday
The way how Watson Assistant’s @sys-date
entity works with alternatives for days of weeks is as follows:
When today is 2020-06-15
(Monday)
last Wednesday
-2020-06-10
, no alternativeWednesday
-2020-06-17
, alternative2020-06-10
this Wednesday
-2020-06-17
, no alternativenext Wednesday
-2020-06-17
, alternative2020-06-24
When today is 2020-06-17
(Wednesday)
last Wednesday
-2020-06–10
, no alternativeWednesday
-2020-06-24
, alternative2020-06-17
this Wednesday
-2020-06-24
alternative2020-06-17
next Wednesday
-2020-06-24
, no alternative
When today is 2020-06-18
(Thursday)
last Wednesday
-2020-06-17
, alternative2020-06-10
Wednesday
-2020-06-24
, alternative2020-06-17
this Wednesday
-2020-06-24
, alternative2020-06-17
next Wednesday
-2020-06-24
, no alternative
Alternatives are used also in other situations. Let’s say that it is June 2020. For example “in May” would be then by default recognized as the future May 2021 with an alternative of May 2020, but “in August” (given the fact that it is June 2020) will be only August 2020 with no alternatives.
Collect Multiple Values of an Entity
In some use cases, it is useful to be able to collect multiple values of the same entity. Here are a few examples of how to do that easily.
To collect an array of numbers using an optional slot, use the following specification of a dialog node:
The conversation would then look like this:
But what if the user wants to collect literals (the exact text matched by an entity) of the recognized entities? A good example of this might be a task to collect multiple e-mail addresses. Pattern entity type might be used to find an e-mail address in the user input.
This is how the user-defined pattern entity looks like in our case (the pattern is \b([a-zA-Z0–9._-]+@([a-zA-Z0–9_-]+\.)+[a-zA-Z0–9_-]+)\b
):
The dialog node with an optional slot looks like the previous example collecting multiple numbers:
However, in this case, @email.value
cannot be used. When using the pattern entity one needs to collect the value using literals (@email.literal
). The trick here is to open $emails slot details, open advanced JSON editor for that slot and use a special syntax to access attribute literal
of the entities['email']
array using the following assignment: "emails": "<? entities['email'].![literal] ?>"
This is how it looks like in the Try it out panel:
Moreover, one can use the same ![literal]
trick to collect one or multiple pattern-based phone numbers, room numbers, or user-defined entities where the intention is to collect the exact wording provided by the user.
If you’re interested in learning more, please check out the IBM Watson Assistant page at https://www.ibm.com/cloud/watson-assistant/.