When a chat user does not provide enough information in the utterance, you can have the chatbot automatically ask for these missing entity values. Slot filling ensures that your chatbot automatically asks for missing information from the chat user.
A specific case where entities come in handy, is when you want to ask the user for missing information. Let's have a look at this example:
U: Hi, I'd like to order a pizza!
B: Great, would you like that small, medium or large?
U: Small
B: Got it! And what topping would you like? I've got mushrooms, pineapple, onion or salami.
U: Mushroom
B: All set! One small pizza with mushrooms on the way!
Your chatbot recognizes that there is no value for the entity pizza.size or pizza.topping in the user's utterance, so it asks for that information. Your chatbot literally asks for entity values to fill empty slots.
How do I create a dialog with slot filling?
Let's build a basic dialog with slot filling. We'll use an 'order pizza' flow as an example. The structure of a slot filling dialog is as follows:
Step 1: User turn for catching the general intent of the user
Step 2: Bot question requesting entity value
Step 3: User turn for giving an entity value
Step 4: Train utterances to recognize valid entity values
Step 5: Bot reply for confirming the given entity value
Step 6: Bot reply for when the user's given entity value doesn't match
Step 1: Create intent
- Create a user turn with an intent 'order.pizza'
- Don't select an entity
- Enter a primary utterance
- Save your intent
Step 2: Ask for entity value
1. Add a bot turn to your intent
2. In the turn editor, select 'Question' to create a question.
3. In the 'Question' text field, add a question that asks for the pizza topping.
4. In the Entity field, select the name of the pizza.topping entity that you created in the previous step. This is the slot that your bot wants to fill.
5. Save your bot turn.
Step 3: Capture user answer
Add a user turn for catching the user's pizza topping
1. Add a user turn to your bot question.
2. In the 'Enter intent' field, create an intent 'add.topping' to let the user choose their pizza topping.
3. In the 'Add entity' field, select the name of the pizza.topping entity that you created in the last turn. We need this so that your chatbot can check whether your user's answer matches one of the values for pizza.topping.
4. In Utterances, add 5 to 10 utterances that contain the values of your pizza.topping entity (including some synonyms).
5. Save your intent.
Step 4: Mark utterances with entities
Train your utterances to recognize entity values.
Before we can move on to the next step, there's one more thing you need to do: to let your chatbot know what the entity values are in your users' utterances.
1. Open your add.topping intent once more.
2. For each of the user utterances, select the entity value in that utterance, so that it is marked blue. In our example, we're marking the toppings.
3. From the list, select the entity that this value belongs to. In our case, all toppings belong to the entity pizza.topping.
4. Save your intent.
You should now see your bot's pizza topping question, followed by a user turn and a no.response turn:
Step 5: Confirm user's choice
Create a bot reply to confirm the user's choice
When your user enters an entity value that your chatbot recognizes as one of the toppings in your pizza.topping entity, you want to confirm their choice.
1. Add a bot reply to your add.topping intent.
2. Add a reply text that confirms your user's choice. To include the recognized entity value in your bot's response, add the entity name between double curly brackets: "A pizza with {{pizza.topping}}, great choice!"
3. In the live chatbot, this code will be replaced by the actual entity value that the chatbot has recognized.
4. Save the bot reply.
Step 6: Create no.response
Create a bot reply for when the entity value isn't matched.
When your user asks for a topping that's not part of the pizza.topping entity (for example, we didn't add chicken to the list), you want to let them know, and offer them another suggestion.
1. Add a bot reply to your no.response turn.
2. Add a reply text that lets your user know that their choice is not available, and ask them to choose something that is.