06 Dialogflow CX Slot Filling

Lesson: What is slot filling?

What is slot filling?

[00:00] So if you go to my site, you will see this article where I talk about slot filling and you can see the URL is just miningbusinessdata.com slash dialogflow hyphen slot hyphen filling and if you scroll down a little you will see this video here which is about 15 minutes long and I actually provide an overview of slot filling and I also explain sort of how it works under the hood and then I make a case for why I avoid slot filling and remember that I am still talking about Dialogflow ES and finally I talk about whether you really need slot filling for your bot.

Now actually there are more things in that article so I should not have said finally but for this particular course lesson what I am trying to say is that I also have a section in that same article which talks about whether you actually need slot filling that is required parameters because it turns out that a lot of people use slot filling even though they could have avoided slot filling altogether they could have just used follow-up intents or they could have constructed the whole flow just using you know input and output context designing the conversation using just input and output context.

[01:16] So the reason to use slot filling is when there are a few things should happen that is the user could come and say the same thing but they could provide multiple different parameters in the starting phrase and in that case it actually makes a lot of sense to use slot filling so I would say that the best like sort of canonical example for that is when user wants to book a flight and you will see that a lot of people will start the first sentence or like the initial query will be very different sometimes they might say I would like to book a flight sometimes I would say I would like to book a flight from place A to place B or they might say I want to book a flight for n number of people or they might say I would like to book a flight leaving on a certain date right these are all like the same intent that is they are representing the same intention to book a flight but because of the way they finish the sentence where they could provide one or more

[02:15]

parameters all of which are actually necessary to book the flight remember that makes it a slot filling candidate. I mean if this is a good reason this is a good reason to use slot filling okay so assuming that you are in need of a real slot filling bot that is a bot which really needs slot filling I think that in CX you should go for slot filling that is the only qualification as I am pointing out here is that it should have these you know I have a checklist here you know whether can the opening sentence include any of the slots could the opening sentence include all the slots could they be specified in any order they all really required and so on you know if you can go through this list and you are sure that it is a slot filling bot the one you are building then yes it makes sense to build it as a slot filling bot and it actually makes a lot of sense to use Dialogflow CX for this purpose so what I am going to do next is I am going to explain how you can build a simple slot

[03:25]

filling bot for the use case that I presented over here and I will do that in the next lesson.

Lesson: Defining the slots

Defining the slots

[00:00] So now let’s build the flight booking bot using slot filling. So let’s go ahead and add an intent. So I’ll say new intent book.flight and there’s something simple like I would like to book a flight, book a flight and go ahead and save this. And then what we will do is we’ll just create a new page to get all the information and I’ll just call it get info page, okay.

So what happens is I’m going to add something here which is just to indicate enter get info or maybe let’s just, okay, let us get all the information to get you started. Maybe you can say something like, let me get some more information to complete the booking, something like that.

[01:12] This is just a test to see if everything is working. So user comes in and says book a flight and it has to respond with, okay, let us get some information to complete the booking. So till now everything is good, no problem, okay. So what we will do here is we will keep adding all these parameters as required parameters.

So the first one would be say from and this would be a city, this is .geocity. And if the user did not provide this value, the agent should provide like a prompt, right. And the prompt will be where are you flying from, okay.

[02:03] So that’s it. And then let’s add one more, two, which is also going to be a geocity. And remember that this is marked as a required parameter because we want it to be, we want to make sure that this information is collected. Where are you flying to? And let us save that, add one more, leaving on and this would be date and for now let us just keep it as date, okay.

What date do you leave, leaving on or maybe I will just call it return date, when do you want to return.

[03:09] And finally, how many people, passengers. This is just going to be a number, start number integer, how many passengers. So a very simple bot.

Lesson: Demo of simple slot filling bot

Demo of simple slot filling bot

[00:00] So once we collect all this information, what we will do is we will add a transition route and this should be actually based on a condition, match at least one condition and this is a special like formula which you can use to check if all the parameters which are collected in this page, if you have all of them already filled out and you can see an example of this in the car rental prebuilt agent where they say $page.params.status equals final.

So you have to make sure that you have collected all this information and once you do that now you know that you have collected all this information, so you can just give a confirmation message. So you can say okay to confirm, you would like to fly from $session.params.from to $session.params.to $session, leaving on $session.params.leaving-on and returning on $session.params.return-day.

[01:27] Okay, you would like maybe you could add this thing where we can say $session.params.numPassengerTickets, so you would like going from, okay let us save that, maybe this verbiage might be slightly wrong, we will know as we check this.

So we go with book of flight and where are you flying from, from let us say Miami, where you are flying to, let us say I say to New York, what date do you leave, tomorrow, when do you want to return, next Tuesday, how many passengers, let us just say two.

[02:28] So there it says okay to confirm, you would like two tickets going from Miami to New York, leaving on so and so date, returning on so and so date and it looks to be quite right and you can see all these session parameters have already been collected as you are testing this conversation in the simulator and we were able to get to the end of this conversation just as expected, right.

So this is the most basic example of the slot filling where the user just starts with providing this example where they say I want to go to this place or sorry I want to book a ticket and then it is going to collect the information one by one until all the slots have been filled and we can also confirm that by looking at this confirmation message which points out that or indicates that every all the piece of information we provided has been collected properly.

Lesson: Adding phrase variants

Adding phrase variants

[00:00] So now you might remember that when I gave you the motivation for creating a slot filling bot, I mentioned that the user might start the first, like the first question they asked could actually have a lot of variations, right, and this is the set of variations I showed you before, and what we have seen till now is a much simpler bot where I only took the first part of that statement, right, I want to book a flight. Now what we will do is, we will add these other parameters into the first initial query that the user provides, because that will actually give you a very good idea of like where slot filling really shines, okay, so I am going back to this book.flight intent, and what I will do now is I will say book a flight for 2, okay, and you have to sort of help Dialogflow a little here, and you have to select sys.number integer as the annotation, but the most important thing is to make sure that you are going to call this parameter whatever name you gave passengers, I think, whatever name you gave in the other page over here, okay, so you can see that actually it is just num hyphen passenger, so not num hyphen passengers, since I think passengers is better, I am going to

[01:27]

change it here, okay, so this is a list, right, from, to, leaving on, return date and num passengers, so let us just go and do the others, go to book flight, edit intent, book a flight from Seattle to New York, let us say, okay, so this time it did better because it was able to identify the city, but again, remember that you want to change the names of these parameters to match what you already have in your page parameters in the next page, okay, then the last thing that I want to add is book a flight leaving tomorrow and arriving, coming back next Wednesday, something like that, okay, and what should happen, like you expect is you have Dialogflow as annotated tomorrow

[02:27]

and instead of date time, it should be leaving on and then this should be return date, okay, so this is, just make sure that everything matches with everything and just to be sure, let us go back to this get info, so leaving on return date, num passengers from and to, let us go to the intent, edit intent and what you see is leaving on return date from to num passengers, okay, that is good, so now you go and test the agent and this time we are going to try the variants which you saw on the first page, so let us say book a flight for two, like you see, it is already having num passengers set here, what that should mean is even though it asks where are you flying from which is in the sequence which you have specified, okay, it should skip the question where it

[03:26]

asks how many passengers, okay, so where are you flying from, so I might say from Seattle, where are you flying to, to let us say Dallas, what date do you leave, leaving tomorrow, what date do you want to return, coming back on the 20th January, there you go, so you can see that, oh, I see, you can see what happened here because even though this has collected all the information, I had wrong, you know, I had used the reference as num hyphen passenger instead of num hyphen passengers because if I had used num passengers, it would have provided the correct answer and you know that because you can see that on the side, it has collected the correct information into the correct session parameter, so for now, I am just going to suppose

[04:26]

that that worked just as expected but I think that you kind of get the idea here that is you have to make sure that you have to provide that is when you reference the value, you have to be very careful with the name that you are using, so let us just quickly go ahead and fix that, so let us go to get info and transition route and let us change this to num passengers and save it, okay, so now we will test it with a different variant, book of flight from Dallas to Miami, so now remember that it is going to ask where from and where to as the first two questions, so if it got this two pieces of information initially, it should resume asking with the third parameter, okay, so look that is what

[05:26]

happened, right, the parameter from is Dallas, to is Miami and now it is moved directly to the third question which is what date do you leave, right, if you look at the list of parameters that we have over here, you can see that from and to have been filled and it is already moved on to the third parameter, so I can say leaving on Monday, when do you want to return, returning on Friday and how many passengers, I will just say three, so you can see now it is got it all right, okay, to confirm you would like three tickets going from Dallas to Miami, leaving on this date and this date, so this is all wonderful and you can see that everything is working exactly as expected and this is the basic idea behind creating a slot filling bot.

Lesson: Reprompts

Reprompts

[00:00] Okay, so the biggest benefit of using slot filling is that Dialogflow will keep prompting the user until the user provides an input which matches the type of entity that you are expecting. To show that, to explain how that works, let me do the same thing in the simulator, book a ticket and it is asking where are you flying from. Now, just for the sake of the demonstration, let us say that I type in some random like just random text, it is not even a valid city name and if I press enter, you can see that it is just doing the same thing, it is re-prompting you to input something, where are you flying from and I am going to do the same thing one more time, it is again re-prompting, but this time I will give a proper value, okay.

Notice that it is now changed the question and it is moving on to where are you flying to and you can see that the parameter is now recorded as from Seattle, but once again I will provide some garbage, it is once again re-prompting, but this time I will give some proper value and then it is changing the question, right.

[01:09] It keeps going like that until it hits the, I mean it keeps going like that until you give it a value that is valid for that particular type of entity that it is expecting, right. If you say when do you return and instead of saying providing a date, let us say that you say something like 7 days from departure, okay.

The problem with what I am typing now is it is quite possible it might understand it as something else, but let me just give it a shot. Okay, good. Thankfully it did not actually understand what I wrote, it is just asking when do you want to return and instead of saying 7 days from departure you might as well say something like Jan 17th, okay, something like that, right.

[02:04] Then it is moving on to the next question, how many passengers and it is going to confirm the message. What is happened here is by using the re-prompting mechanism, we are making sure that the user does provide an input for some value that we are expecting, okay. And by doing this what we are also doing is making sure that when all this information is collected and sent over to the business logic which processes that information, it does not have any missing information which is of course it is an important thing.

It is sort of if you have filled out those forms on the internet you kind of know that when you submit and you have not filled out an information it will just put like that red color asterisk mark right next to the label of that whatever field you forgot to fill in, right. As a reminder that hey until you actually do this you cannot submit this form, right. It is a required parameter that is why it is called required parameter and this is how the slot filling helps us make sure that all the information is collected in a dialogue form.

Lesson: Reprompts with no-match-default

Reprompts with no-match-default

[00:00] So what you have seen now is that slot filling will keep re-prompting the user until they provide the expected value. Now this was actually a big problem in Dialogflow ES and the reason is when they had the slot filling, it will just keep continuously re-prompting. There was the option to change the prompt message but often that wasn’t, in my view, that still wasn’t good enough and there are a lot of reasons for that. I am not going to go over that in too much detail right now.

The important thing I will point out here is that they have made a major improvement in this feature in CX and to show you an example, what I am going to do is, I am going to go to this from parameters over here, okay, and you can see that, okay, so this is, you can, you remember that this is marked as a required parameter, so it is asking where are you flying from, that is the regular prompt, okay, but also notice that you have event handlers which are actually specific to each parameter which is being collected and when you go into this event handler dialog, you see that you have all these options, okay, there is the invalid parameter, there is the no match default, no input default and you even see that no match one, no input one, let us not worry about, I want you to ignore the, everything except the no match default, okay, so no match default, what

[01:31]

it means is that whatever the user typed in right now was not, Dialogflow wasn’t able to understand it as a proper city name, okay, so which is kind of what happened when I typed in the junk value last time, so in that case what the agent might say is, please input a valid city name, so this is a way of saying to the user that whatever they have provided for whatever reason is not something that Dialogflow is able to actually parse, it is not something that it is able to understand as the parameter that it actually expects, so if you were to go to the simulator and go over our flow again, book a ticket, where are you flying from and if I were to say this, so notice that this time the reprompt message has changed from where are you flying from, it is instead changed to

[02:30]

please input a valid city name and if I were to type more junk, it is going to continuously reprompt with the same message and this time I might say Seattle and of course it is moved on to the next step, so that is one thing, the first thing is that you can do a reprompt which is giving some information to the user to help them out like to explain like, hey, you know, whatever you typed in was not what I expected, so could you please change it to a value which is more expected, okay, in the case of cities I think that that is, I am not sure what you can do to make it easier for the user but as you build Dialogflow bots, you notice that there are some use cases where you can be more specific and narrow down the choice for the user and things like that, at that point it will actually be much better to sort of narrow down the list of options for the user, so that

[03:30]

they can make a choice and it will help you to collect the information properly and we are going to look at an example of that in the next video.

Lesson: Reprompt to selection

Reprompt to selection

[00:00] So what I’m going to do in this video is I’m going to show you an example of how you can provide re-prompts which gives the user some help and makes them give a better input for the particular entity that you’re trying to collect. So what I’m going to do is create a new entity and I’m going to call it class as in the flight class, which is first class and business class and economy.

Let’s stick with those three for now. So I just have them added as values here, okay. So we have this entity type called class. So I’ll go to the build and I’m going to add that as a parameter, okay.

[01:00] So let it be class, flight class and entity type will be class and you can say which class are you flying. So this is good. So let’s go to this simulator and say book a flight from Seattle to Miami.

What date do you leave? Tomorrow. When do you return? Next Tuesday. How many passengers? Three. And it’s going to ask which class are you flying? So here’s the thing. If I don’t know what options I have, I might say something like, okay, which is the cheapest one? Okay, so you can see that it’s simply coming back with which class are you flying, right?

[02:03] So what you can do in this situation is you might want to tell them that there are these three options, right? And if you provide, if you narrow the list down to those three, they will be able to make a choice as to which class they want to fly. So what I’ll do now is I’ll go to the flight class parameter and here I will add an event handler and the no match default will be something like choose from the following.

So you’re giving them some assistance, right? You can say economy and business or maybe make it even easier to read.

[03:06] Okay, so you can do that. And now if we go back to the agent, book a flight from Miami to Dallas, leaving tomorrow, returning next Wednesday or four, which class are you flying?

And you might say like, what are my options? So you can see it says choose from the following, economy, business and first class. Now, I just want to make something clear. As soon as I typed in what are my options, it came back with these three, but that’s a little misleading and I just realized it right now. It’s not because it understood that you’re asking for options.

[04:02] No matter what you had typed in here, which was not what it expected, it should have given you this report, right? So just to explain, I’m going to restart the flow. Book a flight from Seattle to New York. New York leaving tomorrow and returning on Tuesday. Let’s do that. So it’s come to the how many passengers for three.

Now it’s asking which class are you flying? And I might say, which one is the cheapest, right? And notice that it’s still going to prompt choose from the following, right? So it’s not really giving you an answer, right? It’s just giving you this prompt no matter what, if it didn’t understand what you said. So in this case, if I were to go with economy, then of course it’s moved on to the confirmation message.

[05:02] I now remember that I didn’t add the class into the confirmation message, but if you were to look at the parameters it has collected, you can see that it got the right value, which is economy, right? So that’s the first improvement. The first improvement, of course, is that by giving you this option to do this no match default, it has allowed, that is Dialogflow CX has allowed you to do this kind of narrowing. And I think that the example I took was probably a very simple one.

It’s probably not explaining the full power of this ability to narrow down the options. But what you can say is that already this is much better than the blind re-prompting that was possible in Dialogflow ES, where you don’t have this kind of like, okay, what happens if there’s a first mismatch and then what happens if there’s a second mismatch and so on, okay?

[06:03] So that’s already a big improvement. And I’ll also show you in the next lesson, what you can do if for some reason you can’t get the value from the user and you don’t mind, sort of maybe you collect like four out of the five pieces of information which are required, and then you might have someone call them up and get the last piece of information or maybe it’s not really a required piece of information and things like that.

So you can still do that, but you might be able to do that in Dialogflow CX very easily and it was nearly impossible in Dialogflow ES. So we’ll take a look at how to do that in the next lesson.

Lesson: Exiting the slot filling loop on first retry

Exiting the slot filling loop on first retry

[00:00] So one of the places where slot filling can get really stuck is where you are collecting the value of an entity and it so happens that it is quite impossible to list all the possible values for that entity. A really good example is the user’s name and if you try to collect information about the user’s name in Dialogflow ES, you know that that can be pretty tricky. What the CX does is it gives us a really nice way of handling this issue and of course, you still will have some small limitations, but as you will see, it is just a much more elegant way of solving the problem.

Okay, so what I am going to do is I am going to add a new parameter to this list of parameters that we are trying to get here and it is going to be called booking name and that is basically the name under which we are doing the booking.

[01:04] Okay, and then we are going to mark that as a given name, it is going to be entity type is going to be a given name and then the agency’s will be under whose name are you doing the booking. Okay. Let us go ahead and save that. And one more thing I am going to do is I am going to move this all the way to the top and remember that this is the order in which the entities are going to be collected, the values are going to be collected and so, if I were to say book of flight, it is going to come back with under whose name are you doing the booking.

Now let us say that I use my name and you can see that it is able to understand that name, right, and then I can go with the next parameter and so on. But you are almost certainly going to find some value which Dialogflow is not able to understand.

[02:00] I am going to use a name which is not too uncommon in India and you can see that Dialogflow does not understand that name. I have also used a somewhat unique spelling for that name, but still the fact remains that if someone has this actually as their name, Dialogflow is not able to understand that name, right. You can try more times, but it is not really going to help because this is just not a value that Dialogflow has been able to handle, right.

In that case, you cannot really narrow it down to a smaller list like we did with the flight class slot. What you should do now is, so here is the basic idea, okay. You go to the event handler, get the no match default, right, and do not worry about adding anything to the agent says and anything like that, but instead set the value of the booking name parameter to something which you can understand in your webhook.

[03:07] You might say unknown. This could just be a value which when you see this, you know that you are not able to actually get the value from the user, okay, but you also wanted to break out of the loop. And also remember to set the page to be the current page, okay. Once you say this, what is going to happen if you think about the flow is that once this page starts, it is going to prompt for the booking name, and if it is not able to get it in the first attempt, okay, what is going to happen is that it is going to, it is going to fill out the name with some predefined value, it is going to fill out the entity with some predefined value, and then it is going to transition to the current page.

Of course, you are transitioning to the current page because you do not really know whether the other slots have been filled or not.

[04:01] You just suppose that they have not, right. Now, if I were to go to the agent and I go, I am sorry, the simulator, I try book a flight. Now, I say under whose name are you doing the booking, if I do that. You can see that it is moved on to the next question. Of course, it is still repeating this, okay, let us get some information to complete the booking. But that is just the way we have defined this entry into the particular page, right.

Just to fix the problem, you could as well go here and delete this thing, right. It is not going to change anything. And now, if you were to test the agent of the flight, so, it is going to say under whose name are you doing the booking, I do this. And then you can see that it is moved on to where are you flying from. It is just put the value unknown into the booking name and just moved on to the next question. What we have done is we have effectively short circuited this unnecessary loop, which used to happen in Dialogflow ES.

Lesson: Exiting the slot filling loop after second retry

Exiting the slot filling loop after second retry

[00:00] So the previous lesson what you saw was there is a way to fill the parameter value using the event handler and that was short-circuiting the loop and then you might be thinking well, why do not we at least give the user at least one more chance to provide their input and if it still fails maybe we will do that short-circuiting right and Dialogflow CX makes that also very easy. So what I am going to do this time is I am going back to this booking name parameter, I deleted the old event handler I had and I will tell you why exactly in a minute.

So now instead of no match default I am going to choose no match 1 okay, that indicates that it is the first retry okay and here I will say something like please check or please enter your first name okay. So we went from booking, we went from asking them for under whose name you will do the booking to please enter the first name, maybe they provided the last name it was not mapped by Dialogflow CX, so we are trying to prompt them to provide only the first name okay and then what we will do is as soon as you do the no match 1 you will even see that there is the second thing here called no match 2 that is once you created event handler for no match 1 you will also see that there is a no match 2 and this time I will do the same thing we did last in the last lesson, booking name will be set to unknown, so you are giving them just a second chance okay and now what you have to do is go to the current page so that you are on the same flow alright.

[01:50]

So in the first no match 1 it is going to ask them, it is going to do a re-prompt but if it still fails then it is going to fill the value and move on okay, so what you are going to see here is book of flight under whose name, so I am going to provide the same name again and let us say that I just decided to change the name to the regular spelling, so now it is gone to where are you flying from and it got the booking name as Rishi which is what I typed okay, this is fine.

[02:31]

On the other hand under whose name it is going to do this, now if I were to type the same thing again, now it did go to where are you flying from but this time it went to that next question but the parameter you see is got a value of unknown, now how do you handle the unknown value is up to your business logic but you do know that whenever you get this unknown you have at least prompted the user once and you were not able to get the value that you are expecting.

[03:03] Now there are more things you can do in fact when this information is sent over to the webhook you will be able to have get a like a copy of all the things that the user typed in that conversation, if you look at the original response you will actually see that it is in the list of steps somewhere and yeah I maybe it is not available I have to confirm that but either way this is a way to exit the loop easily and also move on to the next question and it is also somewhat graceful way to exit the slot filling loop and you can do all that just in the inside the Dialogflow CX itself without having to do the same thing in the webhook.

Now the same thing in ES there wasn’t any easy way to do that and the difficult way to do that was to try and set that information from the webhook code and then forcibly move the intent to another intent and it was just a lot more complex and generally speaking it was just a much messier approach to doing the same thing.

[04:17] So here you can see that we have we have found a way to using just this reprompt handlers which are even numbered right you can see that there was no match one no match two so they are even numbered and before it goes to the next question that is it gives you a set number of retries set number of retries and you can also have specific logic to handle what happens when the user tries to input the same information again.

So this is why I think that for a slot filling bot Dialogflow CX should be your first choice I mean if you are sure that what you’re having is a slot filling bot then Dialogflow CX should be the first choice.

Note: This is my old website and is in maintenance mode. I am publishing new articles only on my new website. 

If you are not sure where to start on my new website, I recommend the following article:

Is Dialogflow still relevant in the era of Large Language Models?

Leave a Reply