Links

2. Understanding your users

In the previous tutorial, we created a new bot and added a greeting dialog. Now it's time to make your bot able to understand its users by powering it with our Natural Language Processing engine.

📚 A bit of theory: NLP

Before we continue with ChooChoo, let's take you through some concepts that you need to know to grasp how your chatbot can actually understand what users are saying.
The science behind a bot able to understand humans is called Natural Language Processing, or NLP. In Chatlayer, building an NLP model is done in 3 steps:
  1. 1.
    Define what the users would mean (or the intents)
  2. 2.
    Define how users could formulate those intents (or the expressions)
  3. 3.
    With those intents and expressions, train the NLP model so your bot learns to label expressions with intents
We will build an NLP model together for ChooChoo, but first, let's go through theory in a bit more details 👇

The NLP engine

To build a chatbot that responds differently depending on what is asked, it is key to understand what the NLP engine is.
The Natural Language Processing (NLP) engine is the underlying AI algorithm that allows the bot to understand what the user is saying. And as each language has its own words and grammar, we have a separate NLP model for each language!
To be efficient, the NLP model of your bot needs to be trained. You will learn how to do that in the steps below.
Understanding language isn't easy: it takes us humans about 6 years and hundreds of examples to understand the most common 20,000 words. It's not so different for computers either. To train an NLP engine, we need huge amounts of data. Luckily, we rely on pre-trained models that have a lot of smarts built in already. Check this tab to go deeper in everything there is to know about NLP.
The NLP of your bot is configured by making groups of expressions that we call intents 👇

Intents and expressions

An intent is a series of expressions (or utterances) that mean the same intention or goal from the user side. During the conversation, intents are recognised by the NLP engine and serve to steer the conversation in different ways.
For example: an intent can be a question, a statement, an answer to a question, or a greeting. Each intent can be expressed in many different ways, which is why we call them expressions.
The expression "How do I sign up for a free trial" is recognised by the NLP engine as an explain-free-trial intent, which triggers the correct response from the bot.
Here are some examples of intents and some expressions to formulate them:
Intent
Expression1
Expression2
Expression3
Book train ticket
"I want to book a train ticket"
"I need to go from Antwerp to Brussels"
"Can I order a ticket here?"
Who are you
"what is your name?"
"what can you do?"
"what should I call you?"
Yes
okay
yup
confirm
Let's now incorporate those concepts to ChooChoo.

Step 3: Adding an intent

For our ChooChoo bot, we want to give ChooChoo the ability to answer basic questions about itself. To get started, we will create an intent for the question: Who are you?
  • On the left side of the screen in the navigation menu, click on NLP to navigate to the NLP module. Click the Intents submenu.
To create intents, click on the Intents tab underneath the NLP module.
  • Click on Add Intent and name it Who are you and click on Create
Creating a new intent called "Who are you"
  • Now you see that the intent is successfully created, without any expressions added to it (that is what the '0' means below the language)
The new intent is successfully added to the Intents list
Yet, since this intent has 0 expressions, this means that it cannot be recognised by the NLP model. Next step is about filling this newly-created intent with different expressions in natural language 👇

Step 4: Adding expressions

Now we have to make sure the NLP recognises the intent that was just created. This can be done by feeding the model with expressions.
Expressions are different ways your users will express one intent. In bot building, as in real life, there are more ways to say something or ask a question.
The more expressions you add to an Intent, the more accurately this intent will be recognised by the NLP engine. It is crucial for an intent to have a wide variety of expressions to give accurate results. Learn more about NLP best practices here.
  • Select the Who are you intent in the Intents pane on the left hand side
  • The Expressions pane will open in the right. Click on Add Expression
Adding an expression to your intent
  • Enter Who are you? in the open text field
  • Click on Create
After you have finished your first expression, press Shift + Enter to save that Expression and immediately add a new one
Add some more expressions by clicking Add Expression:
  • What is your name?
  • Can I know your name?
  • Tell me more about yourself
  • Please, I'd like to know who I am talking to
  • How should I call you?
  • Who is Choo Choo?
  • Tell me what your name is
  • Who are ya?
  • What do people call you?
  • Are you a train?
  • Do you have a name?
This will result in the following screen:
Add varied expressions to your intents to make their recognition more accurate.
Let's try adding another intent and expressions:
Add another intent, like Greeting and add some expressions:
  • Hi
  • Hello
  • Hey
  • Hi there
  • Good morning
We have defined two intents now: Who are you and Greeting.
Adding more intents
However, if we were now to say 'Good morning' to the bot emulator, nothing will happen. That is because the NLP is not trained yet, and the intent is not yet linked to a bot dialog. We will work on that in the next steps.

Step 5: Training the model

To make sure the bot can use the intents with expressions that were created, we now need to update or train the NLP.
Updating the NLP means that the newly added intents and expressions will be learned by the bot so that it can recognise a wide range of expressions as belonging to the correct intent. This step is crucial: if you do not update the NLP, the bot has no knowledge of natural language understanding.
To successfully train the NLP, you need to have at least two intents with a minimum of 5 expressions each. Learn more about NLP best practices here.
  • Click the Update NLP button in the top right corner of the screen:
To train de NLP, click on the Update NLP button
  • Select the language you used to add the expressions. You can view the status of the NLP update for each language by clicking on the Update NLP icon.
The NLP needs more intents and expressions to be trained.
  • Click on Update to start the training. This can take a couple of minutes to one hour depending on the size of your chatbot. The more complex, the longer it will take.
The NLP is updating
That was a great first step to be able use the 'Greeting' and 'How are you' intent. The next step is to link these intents in the bot dialogs so that the bot can respond to them.

Step 6: Linking an intent with a dialog

You have now taught the NLP to understand intents, congrats!
The only thing left to do is teaching ChooChoo how to respond. This means we are going to choose what the response (or flow) should be for each intent.
Bot dialogs can be reached from any point in the conversation by being triggered by an intent. You can use the same intent to trigger different bot dialogs by using context.
Let's add a new bot dialog that will serve as a response to the intent Who are you:
  • Click on Bot Dialogs menu item in the navigation pane
  • Open the General flow
  • Click on the grey button on top + Bot message
  • In Settings, enter Who are you as the name
  • Choose the Introduction dialog state as the parent
A parent link is a visual aid to structure your bot in the Flow view. They are a visual tool to structure the conversational flow and keep an overview, which makes it easier to create complex conversations. They are not to be confused with Go-To links.
  • Open the NLP of that bot message
  • Link the intent to the bot dialog in the bot dialog NLP tab as follows:
Link the Who are you dialog to the Who are you intent
  • Go to Bot Message tab and add a text message that says:
I am Choo Choo, your personal assistant for booking train tickets
Your screen should look like this:
  • Click on Create
  • This will result in the following overview in the flow:
The Who are you dialog is successfully linked to the Who are you intent
If you now say 'Who are you' in the emulator, you immediately get the response that is typed in the 'Who are you' bot dialog. The dialog and the intent are successfully linked! 👏
See how the intent Who are you is recognised and triggers the Who are you dialog by testing your bot in the Emulator.

Lesson recap

Now, you have a bot with the following configuration:
  • 2 intents ('Greeting' and 'Who are you') and their expressions
  • A bot message 'Who are you', with the intent 'Who are you' and four text messages in it.
You should now be familiar with:
  • Adding an intent to a bot dialog
  • Creating intents and expressions
  • Training the NLP to use these intents and expressions
  • Adding multiple text messages in one bot message
  • Testing your intent and messages in the emulator
If any of these topics are difficult for you, revisit them in the tutorial or search on the page in the top right search bar to learn more about a topic.
In the next tutorial we'll be gathering user input for booking a train ticket. Check the rest of the tutorial to learn more 👉🏻