The Certainly Platform offers a new AI service that will allow your bots to recognize user intent in a more natural way. This updated version uses AI to predict languages
, sentiments
, entities
(both default and custom), and intents
directly within the Module actions, without needing to employ dedicated Webhooks.
Each time a user reply is received, all this metadata is extracted seamlessly under an object called nlu
. You can then access the NLU object and use the information collected to obtain user information or direct the conversation flow in specific ways.
We'll go more in-depth as to how we can use the new AI version in real bot conversations. Please note that you can use both AI versions at once in a single bot. Activating the new version will not render the traditional AI useless. Below, we'll cover:
- Activating the new AI
- Introduction to the NLU object
- Supported prebuilt entities
- Training the AI with custom entities
- Using Jinja to extract entities from the NLU object
Activating the new AI
By default, this version of the AI is not active on newly-created bots. However, you can send a request to our Customer Success team for this feature to be enabled in your bot for free. Please contact us at support@certainly.io to request access.
Once activated, both AI versions will work in tandem. The AI Manager, accessed via the right sidebar menu of your bot canvas, will remain unchanged, and all your previously built Domains and Intents will still be saved and fully functioning.
This means that activating the new AI will not impact the current functioning of the bot, and it does not require reconfiguration of existing flows in order for it to continue working.
Introduction to the NLU object
As noted above, all the metadata extracted from a user's reply is stored in an object called nlu
. This object can then be operated on through the use of Jinja templates to extract all the information that is relevant in a particular situation.
To view all the metadata stored in the nlu
object at any point in the conversation flow, we can set up a simple variable inside the bot and use it to store the nlu
object. Here, you can see an example of this setup:
The bot will populate the Custom Variable {{nlu}} with the whole value of the nlu
metadata object.
Once organized, the nlu
object follows the basic structure outlined below:
The object provides four different types of predictions: languages
, sentiments
, entities
, and intents
.
- Languages: Automatically detects to a certain degree of confidence (0 ≤ confidence value ≤ 1) the language in which the end user typed their reply. Can be used to configure multi-language bots or to inform the user that a bot is capable of speaking in only one language.
- Sentiments: The AI analyzes the overall emotion of the user's input within a range of -1 to 1. A neutral user reply is represented by a value of 0. If a user's emotion is understood as positive, the key
sentiments
in thenlu
object have a positive value (0 < sentiments value ≤ 1). A negative user reply translates to a negative value (-1 ≤ sentiments value < 0).
This measurement is based on publicly available datasets of words that have been manually annotated with positive or negative scores. As such, there are limitations that should be considered. For instance, the AI is not capable of distinguishing irony, and we cannot provide absolute guidance as to what a specific negative or positive value signifies. We recommend combiningsentiments
withintents
when configuring your bot to get the best results possible. - Entities: Must be defined inside your AI Manager as specific categories. The bot owner needs to define what entities they want to use, in addition to what values these could have. The AI comes with some prebuilt entities specifically designed for ecommerce that will help you set up your bot in record time.
- Intents: Can be defined as the overall intention behind a chatbot user's reply. The AI evaluates to a certain degree of confidence (0 ≤ confidence value ≤ 1) if the user's reply belongs to one of the configured intents in your AI Manager.
Supported prebuilt entities
The new AI service supports the following prebuilt entities:
- Country information
- Temporal expressions
- Measurements
- Personal information
- Shipping
- Fashion: Sizing
- Fashion: Clothing
- Fashion: Attributes
Country information
Entity Label | Example Entity Value | Entity String |
Country |
US, the Netherlands |
entity/common/country |
City |
Birmingham, Copenhagen |
entity/common/city |
Postal code |
1050, 28806 |
entity/common/postcode |
Temporal expressions
Entity Label | Example Entity Value | Entity String |
Time |
Tomorrow, 1st of April, next weekend, this Sunday |
entity/common/time |
Duration |
4 days, 2 hours and 3 minutes |
entity/common/time/duration |
Holiday |
Christmas, New Year's Eve, May fourth |
entity/common/holiday |
Month |
January, July, May |
entity/common/month |
Weekday |
Monday, Saturday, Friday |
entity/common/weekday |
Measurements
Entity Label | Example Entity Value | Entity String |
Number |
Seventeen, 1.5, 0,7, 212 |
entity/common/number |
Ordinal |
3rd, fourth, eighteenth |
entity/common/number/ordinal |
Volume |
300 ml, 2 liters, one gallon |
entity/common/number/volume |
Distance |
8 miles, 4 feet, 42,195 km |
entity/common/number/distance |
Temperature |
80 °F, 72° Fahrenheit, thirty three Celsius, 90 degrees |
entity/common/temperature |
Amount of money |
20 dollars, 5 bucks, $12 |
entity/common/amount_of_money |
Personal information
Entity Label | Example Entity Value | Entity String |
First name |
Susan, Casper, Joana |
entity/common/first_name |
|
contact@certainly.io |
entity/common/email |
Phone number |
415-123-3444 |
entity/common/phone_number |
URL |
https://www.certainly.io/ |
entity/common/url |
Credit card |
DinersClub, MasterCard, Visa |
entity/common/credit_card |
Browser |
Mozilla Firefox, Edge, Chrome |
entity/common/browser |
Shipping
Entity Label | Example Entity Value | Entity String |
Shipping provider |
DHL, FedEx, US Postal Service |
entity/common/shipping_provider |
Fashion: Sizing
Entity Label | Example Entity Value | Entity String |
Size |
XS, medium, 42, 104 |
entity/fashion/size |
Size jeans |
28/28, 32*30, 34l |
entity/fashion/size/jeans |
Size shoes |
45, 7, 40 |
entity/fashion/size/shoes |
Length |
normal, short, thigh length, 3/4 length |
entity/fashion/size/length |
Fit |
oversized, relaxed, slim |
entity/fashion/size/fit |
Fashion: Clothing
Entity Label | Example Entity Value | Entity String |
Category |
dress, beachwear, suit, belt |
entity/fashion/category |
Bag |
shoulder bag, clutch, computer sleeve |
entity/fashion/bag |
Dress |
Ballgown, maxi dress, cocktail dress |
Entity/fashion/dress |
Hat |
cap, fedora, tam o’ shanter |
entity/fashion/hat |
Outerwear |
wool coat, leather jacket, windbreaker |
entity/fashion/outerwear |
Knitwear |
hoodie, cashmere sweater, pullover |
entity/fashion/knitwear |
Pants |
chinos, jeans, shorts, jumpsuit |
entity/fashion/pants |
Shirt |
blouse, T-shirt, tunic |
entity/fashion/shirt |
Shoes |
dress shoes, heels, boots, mule sandals |
entity/fashion/shoes |
Swimwear |
bathing shorts, tankini, swimsuit |
entity/fashion/swimwear |
Fashion: Attributes
Entity Label | Example Entity Value | Entity String |
Fabric |
cotton, jersey, bamboo |
entity/fashion/fabric |
Occasion |
casual, festive, cocktail party |
entity/fashion/occasion |
Celebration |
birthday, wedding, Mother's Day, anniversary |
entity/fashion/celebration |
Color |
blue, red, green |
entity/fashion/color |
Training the AI with custom entities
You can train your bot's AI with a number of custom entities. Custom entities can refer to order numbers, product names and categories, and so on. Here, you can see the notation to follow when declaring an entity in an Example Sentence:
css
"Where is my order [23467,24547,76546,476876,347658,45756|order_number]?"
The Example Sentence shown above will result in your bot's AI learning about a custom entity type "order_number", which could look like any of the examples prepended to it. Keep in mind, you do not have to specify all possible values of the entity. Certainly will use machine learning to abstract a wider range of possibilities given the examples you supply in the AI Manager.
Here, you can see an instance where this Example Sentence has been added in a bot's AI Manager:
You may want to use a specific custom entity in several sentences inside the bot's AI Manager. In this case, it is possible to reference the entity in each sentence in which you're going to use it, and declare it only once in the AI Manager.
This can be seen in the image below, where the entity has been declared in the last Example Sentence:
When training your AI Manager with custom entities, it's important to remember the following:
- When declaring the entity, do not include any spaces between the different values and the name of the entity, as that will cause the custom entity to function incorrectly.
- When providing values for an entity, make sure to train the bot with both singular and plural values, such as shoe,shoes. Please note that the AI is case-sensitive.
Using Jinja to extract entities from the NLU object
We'll now explore how to process the nlu
object in order to extract the necessary entities and store the information in variables. We can use this method to extract both custom and default entities. Below, you'll find the following topics:
Extracting default entities
You can use the default entities listed above to extract information such as the user's email address, user name, phone number, and more from the user's replies. As we mentioned previously, the information comes from inside the nlu
object, so we need to use Jinja templates to extract the relevant information.
This is an example of the setup required to extract the user's email from the nlu
inside a Module's Connections:
Jinja template breakdown
Now we'll break down the Jinja snippet in order to get a better understanding of how the extraction works.
We first take the entire nlu
object and iterate through all the entities that are recognized by the AI in the user's message. We do this through the use of a for-loop:
{%- for entity in nlu.entities if entity.entity == "ENTER_ENTITY_STRING_HERE" -%} {%- endfor -%}
Inside this for-loop, we are also using an if statement to evaluate if any of the entities match the entity string we want. In the example setup above, "entity/common/email" is used to obtain the email.
Once we've identified that the entity is indeed present inside the nlu
object, the next step is making sure it is the entity recognized with the highest confidence. For this, it's important to know that the entities inside the nlu
object are ordered by confidence. Entities recognized by the AI appear first in the nlu
, whereas entities with lower confidence will be placed later.
Noting this, we can set up another if statement in our flow, where loop.index
represents the current iteration of the loop.
By saying {%- if loop.index == 1 -%}{%- endif -%}
, we are making sure the condition will be met only if the entity we're interested in is the first iteration of the loop. Since the first entity in thenlu
object will be the one with the highest confidence, we can use this to ensure the entity value we store in our Custom Variable is the one with the highest confidence.
If all the conditions mentioned are fulfilled, we can go ahead and print the value for that entity {{entity.value}}
inside the Custom Variable. We can then use this Custom Variable throughout the conversation.
Using the example described above, this would be the result of the setup we configured:
Extracting custom entities
For custom entities, it's important to train the AI model with the custom entities and configure the bot to use the new model.
In this example, we'll look closely at a setup that extracts two custom entities (item
and person
) from a visitor's message:
Jinja reference snippet:
The process of extracting the entities from the nlu
object is very similar to the one used for extracting default entities. For an in-depth explanation of the Jinja templates, please refer to the Jinja template breakdown section above.
The overall result of this setup will be as follows:
Comments
0 comments
Please sign in to leave a comment.