Teach your conversational AI assistant to pick up entities in Teneo Studio

Conversational AI entity and input

In order for your bot to understand what the user said, some words of the user’s utterance are more important than others. Typical examples for such important words include so-called named entities like cities or product names. Here is how you pick up an entity from user input in Teneo Studio.

Sometimes it’s not enough to recognize which flow to trigger. Your bot may also need to extract some piece of information from the input to respond appropriately. Let’s assume that the user wants to know where our Longberry Baristas stores are located. This is how such a conversation could go about:

User: Where are your stores located?
Bot: Currently our only store is in New York.

Another possible conversation is the following, where the user asks whether Longberry Baristas have a store in a specific city. Here, the first part of the answer is the same, but then in the second part, the bot picked up the city the user is interested in and used it in the response:

User: Do you have a store in London?
Bot: Currently our only store is in New York. We might consider opening additional stores in London in the future.

On this page we will first build the basic flow that handles questions about where our stores are located. Then, we will extend it to pick up the city the user mentioned and re-use it in the bot’s answer. This is what our final flow will look like:

Final flow structure

Create the basic flow

    1. Create a new flow and name it User wants to know if we have a store in city. (If you need guidance on how to add a new flow, please check Your first flow).
    2. Copy the following learning examples to your clipboard:

Where are your stores located?
Where are your shops located Where are your cafes located?
Where do you have cafes?
Where do you have stores Where do you have shops?
Where is Longberry Baristas?
Where can I find you?
Where can I find your cafes Where can we find you?

  1. Then, select the trigger, open the ‘Learning Examples’ panel on the right, and click where it says ‘No positive learning examples’. Then hit right mousekey + paste or the shortcut CTRL + V to paste the learning examples.
  2. Name the trigger Where do you have stores?.
  3. Select the output node, open the ‘Answers’ panel to the right and paste Currently our only store is in New York. in the answer text field. Then, name the output node Our only store is in....
  4. Hit ‘Save’.

That’s it! You have now created the basic flow that can handle the following kind of conversations:

User: Where are your stores located?
Bot: Currently our only store is in New York.

Extend the flow to pickup an entity

Now we will go ahead and extend this basic flow in order to recognize a city that the user mentioned and re-use it in the bot’s reply. To do this we’ll do the following:

  • Add a flow variable in which we can store the city mentioned by the user.
  • Add a new trigger that recognizes inputs like ‘Do you have a store in Paris?’.
  • Pick up the city from the input.
  • Extend the flow with an output that refers to the city mentioned by the user.

Add a flow variable

In order to be able to store the city mentioned by the user, we need to create a flow variable:

  1. Click on the tab ‘FLOW’ in the top left corner of the flow window.
  2. Choose ‘Variables’ in the purple bar on the left.
  3. Click ‘Add’ in the top right of the window.
  4. Name the variable city by replacing the word ‘Variable 1’.
  5. We want to initialise this variable as an empty string, so in the text box below add "".
  6. Use the back arrow to return to the flow graph.

Add a new trigger

We will now make sure that this flow triggers for inputs in which the user asks whether we have a store in a particular city. We can either add additional learning examples to the already existing trigger or add a second trigger. In this case we’ll go for the latter:

    1. In the ‘Add Flow Trigger’ section of the top ribbon, select ‘Class’ in order to add another class trigger.
    2. Copy the following learning examples to your clipboard:

Do you have a store in London?
Do you run a cafe in New York
Are there any of your stores in Sydney?
Do you have a branch in San Francisco
Have you got a cafe in Utrecht?
Is there a cafe in London
Do you have a coffee shop in Tokyo?
Have you shops in Berlin
Do you have any cafes in Paris?
In London, do you have a store there?
Is there a cafe of yours in Stockholm.
Do you have a cafe in Stockholm
Is there a store in Stockholm?

  1. Open the ‘Learning Examples’ panel to the right, click into the field ‘No Positive Examples’ and paste the learning examples from the clipboard.
  2. Name your trigger Do you have a store in city?.

Pick up the entity

Now that we have the trigger in place it is time to pick up the city that the user mentioned. We will do so by using a flow listener:

  1. Go to the ‘Flow’ tab on the top left.
  2. Select ‘Listeners’ from the purple bar on the left hand side.
  3. Click on the little ‘Add’ icon at the top to add a new flow listener.
  4. Name it Pick up city and paste %LOCATION.ENTITY^{city = _USED_WORDS} in the condition field. This will store the part of the user input that matched ‘%LOCATION.ENTITY’ in the flow variable city.
  5. Hit ‘Ok’ to close the Listener window and then the back arrow to return to the main flow window.

The LOCATION.ENTITY is pretty generous, it recognizes not only cities but also other locations like countries. If you want to be more precise and restrict the recognition to cities, you may use the language object CITIES.LIST instead. However, you risk that a particular city might be missing on this list.

Add a new output node

The only thing that remains to be done now, is to add another output node after the existing one:

  1. Select the output node ‘Our only store is in…’
  2. In the ‘Add Node’ of the top ribbon, select ‘Output’. This will add another output node after the existing one.
  3. Select the new output node and paste the following into the ‘Answers’ field: We might consider opening additional stores in ${city} in the future.
  4. Name the new output node We might consider opening a store in city.
  5. Hit ‘Save’.

Have you noticed that the flow variable is used in the answer? When you embrace something in an answer text with ${ and } it will be programmatically evaluated before it is displayed to the user. Here that means that ‘city’ will be replaced with its current value.

If at this point you try the example conversation, you will notice it will not work. The flow will get stuck after the first output node. In order to fix it, we have to configure the transition between the two output nodes. As you can see, the transition is displayed as a solid line, which means it is waiting for an input of the user. But here we do not expect a user input between the two output nodes. Instead, we want the second output to be given only if the user has mentioned a city when asking for our stores. We thus have make the transition ‘Conditional’. This is how we proceed:

  1. Select the transition between the two output nodes.
  2. Open the ‘Examples’ panel to the right.
  3. Use the first toggle to set the transition from ‘Gets input before continuing’ to ‘Continues without input’. This will make sure that Teneo will not wait for a new input.
  4. Use the second toggle to set the transition from ‘Unconditional’ to ‘Conditional’. This will open a ‘Condition’ field.
  5. Into this ‘Condition’ field, paste {city}. This is the name of our flow variable in which we store the city mentioned by the user. Adding the variable to the condition means that this transition will only be traversed if this variable has a value, which is the case if the user mentioned a city.
  6. Give the transition the name City mentioned.

Now we are almost there. The only thing remaining to do is to add a node that allows us to properly exit the flow for the cases where the user did not mention a city. This is what we do:

  1. Select the ‘Our only store is in…’ node.
  2. Then, in the ‘Add node’ section of the top ribbon click ‘Junction’.
  3. Select the transition between the two nodes. In the ‘Examples’ panel on the right, make it ‘unconditional’.
  4. Name this transition No city mentioned, drop the flow.
  5. Hit ‘Save’.

Try it out!

That’s it. Now go to Try-out and give it a go! Depending on whether or not you mention a city in your request, you should get either the short or the extended answer.

Originally published at www.teneo.ai on May 1, 2019.

Teneo Developers

Try Before You Buy.
Build. Deploy. Analyze.

Sign up to get your own developer sandbox of Teneo containing all the tools needed to build and manage advanced conversational solutions.

Get Started For Free

Author:
Gareth Walters is Vice President of Innovation and Community. Having moved into IT 20 years ago, he was responsible for Professional Services teams in several ERP, Supply Chain Management and Content Management software companies in a variety of sectors including Central Government, FMCG, Automotive and Pharmaceutical.

Leave a Reply

Your email address will not be published. Required fields are marked *

[ Webinar ]
[ Webinar ]