Slot Filling
Slot Filling is a process of requesting additional data in order to fulfill the client request. The data acquired during an additional data request are available for use in the script.
Slots are the data that the client sends with a request or when additional data are requested. Each slot has required attributes: Name, Type.
Filling slots from a request
More details about slot filling in the interface
If we regard the intent as a function that the client can call, then a slot is a variable or a parameter of this function.
For example, for the /Weather intent, an example phrase can be "Weather in London today" and the two slots, City and Date. In this example, London will be placed in the City slot and the current date will be placed in the Date slot.
Here, all filled slots will be passed into the script in the variable $parseTree._<SlotName>. The associated value will be stored in the variable, and text will be included if there is no associated value.
The filled slots are used in the script as follows:
state:
intent!: /Weather
a: The weather in {{ $parseTree._City }} on {{ $parseTree._Date }}The Type attribute
Each slot must have a Type that corresponds to the entity Type = entity. This type defines the type of the data that will be placed into the slot. You can use both system and custom entities.
For example, for the Date slot with the type @zb.datetime: the word "today" from a client request will be passed to the entity @zb.datetime and will be placed into the Date slot.
If there are multiple slots of the same type in the intent, then they will be filled in sequentially.
If you need to handle an arbitrary amount of slots of one type in a request or to handle variables with different entity types, use the $entities structure into which all found entities will be passed in their initial form.
The Required attribute
Each slot has a Required attribute:
- If the slot is a required one and no clarifying questions have been specified, then the system will not output this intent if the slot has not been filled in the replies.
- If the slot is a required one and clarifying questions have been specified, then the system may return the intent without this slot. The intent will be handled by the slot filling module, and the client will be asked clarifying questions.
Before you start the slot filling process, familiarize yourself with slot filling in more detail.
Arrays in slots
You need to have an array in the filled $parseTree._<SlotName> slot to process requests with duplicate entities.
Enable the Is Array switch to have all the entities placed into this slot in the form of an array:
If the Is Array switch is...
- Disabled: the first processed value of this entity is placed into the slot.
- Enabled: all the entities of this type are placed into the slot in the form of an array. If only one value of an entity is detected, it is also converted into an array.
Connecting the slot filling module
To connect the slot filling module, specify the following in the script in the main.sc file:
require: slotfilling/slotFilling.sc
module = sys.zb-commonThe mechanism for handling clarifying questions
The system will ask clarifying questions in the order they are defined for all the slots that are left unfilled.
The client replies will be searched for entities that match the slots. If matching entities have been found then the respective slot will be filled.
After all slots have been filled, control is passed to the main script with all the slots filled in $parseTree.
You can exit the slot filling script only by answering all the questions or by using the /start command.
Consider the following script:
state:
intent!: /Weather
a: The weather in {{ $parseTree._City }} on {{ $parseTree._Date.value }}In this case, we have filled all the slots as follows:
Here @City is a custom entity where we have specified all the cities for which we can provide weather forecasts.
Client requests:
The weather in Moscow for tomorrow: the slots are filled and the bot will provide an answer right away.The weather for tomorrow: theCityslot is empty so clarifying questions will be asked. As soon as a correct answer is given, the control will be passed to the script and the bot will give a reply.The weather in Moscow: theDateslot is empty so clarifying questions will be asked. As soon as a correct answer is given, the control will be passed to the main function and the bot will give a reply.
Interruption of slot filling
You can configure slot interruption conditions in the chatbot.yaml file in the injector section:
injector:
slotfilling:
maxSlotRetries: 1
stopOnAnyIntent: true
stopOnAnyIntentThreshold: 0.2The following parameters are available here:
maxSlotRetries— the number of retries for a single slot. If the client has answered the specified number of times and the slot has not been filled then slot filling will be interrupted. The last phrase of the client will be handled in the bot script.stopOnAnyIntent— takes a Boolean valuetrue/false, this parameter defines interruption of slot filling by intent.stopOnAnyIntentThreshold— a matching parameter that specifies the minimum required similarity of the phrase to a class. This is a parameter for slot filling interruption by intent.
Interruption by intent
If stopOnAnyIntent: true and an intent whose confidence parameter is greater than stopOnAnyIntentThreshold matches the client request, then slot filling will be interrupted by intent.
The confidence parameter is the degree of confidence that the JAICP platform has that the input phrase is related to the specified intent.
Note that it is important to take the starting context of the slot filling into consideration. For example, if on interruption it is not possible to reach the state with the respective intent (for example, the tag intent is not global), then the request will result in event!: noMatch.
If the interruption parameters are not specified in the chatbot.yaml configuration file, then slot filling will be interrupted according to the default parameters:
injector:
slotfilling:
maxSlotRetries: 2
stopOnAnyIntent: false
stopOnAnyIntentThreshold: 0.2