1. Help Center
  2. Building Assistants
  3. Intents and Natural Language Processing

Using the new AI on the Certainly Platform

The Certainly Platform offers an 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.

Below, we'll cover:

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:

Nlu_0.png

The bot will populate the Custom Variable {{nlu}} with the whole value of the nlu metadata object.

Nlu_1.png

Once organized, the nlu object follows the basic structure outlined below:

The object provides four 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 the nlu 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 combining sentiments with intents 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

Entity Label Example Entity Value Entity String
Country US, the Netherlands country
City Birmingham, Copenhagen city

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
Email 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 shipping_provider

Fashion: Sizing

Entity Label Example Entity Value Entity String
Size XS, medium, 42, 104 size_cloth
Size jeans 28/28, 32*30, 34l size_jeans
Size shoes 45, 7, 40 size_shoes
Length normal, short, thigh length, 3/4 length fit_length
Fit oversized, relaxed, slim fit

Fashion: Clothing

Entity Label Example Entity Value Entity String
Category dress, beachwear, suit, belt cloth_category
Bag shoulder bag, clutch, computer sleeve bag
Dress Ballgown, maxi dress, cocktail dress dress
Hat cap, fedora, tam o' shanter hat
Outerwear wool coat, leather jacket, windbreaker outerwear
Knitwear hoodie, cashmere sweater, pullover knitwear
Pants chinos, jeans, shorts, jumpsuit pants
Shirt blouse, T-shirt, tunic shirt
Shoes dress shoes, heels, boots, mule sandals shoes
Swimwear bathing shorts, tankini, swimsuit swimwear

Fashion: Attributes

Entity Label Example Entity Value Entity String
Fabric cotton, jersey, bamboo fabric
Occasion casual, festive, cocktail party occasion
Celebration birthday, wedding, Mother's Day, anniversary celebration
Color blue, red, green 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:

"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:

NLU_3.png

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 below, where the entity has been declared in the last Example Sentence:
entities

Best practices for training the AI with custom entities

When training your AI Manager with custom entities, please keep these guidelines in mind:

Best Practices Examples
When providing values for an entity, add at least 5 values per entity. For better performance, we recommend adding at least 10 when possible. Instead of: [shoe,sock,tie|storeProduct]
Use: [shoe,sock,tie,coat,hat|storeProduct]
When providing values for an entity, make sure to train the bot with both singular and plural values. Note: The AI is case-sensitive. Instead of: [hat,tie|storeProduct]
Use: [hat,hats,tie,ties|storeProduct]
When declaring the entity, do not include spaces between the different values and the entity name. Instead of: [coat, coats | storeProduct]
Use: [coat,coats|storeProduct]
When creating a sentence with an entity, it should not be prefixed or suffixed with an alphanumeric character.

Instead of: I want to find a[storeProduct]
Use: I want to find a [storeProduct]

Instead of: I’m looking for [storeProduct]s
Use: I’m looking for [storeProduct]

When multiple entities are referenced next to each other in a sentence, separate them with a space. Instead of: I want [size][storeProduct]
Use: I want [size] [storeProduct]

When the sum of the number of values for all declared entities in a sentence is above 10, reference the entities in different sentences.

For instance, when you’ve declared the following entities as such:

[extra-small,small,medium,large,extra-large|size][shirt,shirts,socks,shoes,coat,coats|storeProduct]

Sum of the number of values = 11

Instead of: I want a [size] [storeProduct]

Use:

I want a small [storeProduct]
I want a [size] shirt

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:

Nlu_4.png

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 the nlu 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:

nlu_5.png

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:

nlu_6.png

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:

nlu7.jpg