# 2. Understand your users

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FVCBlP55EogtXWiSvSJuc%2FChooChoo%20tutorial%20rework%20(5).jpg?alt=media&#x26;token=efdbb8e1-2a7e-4876-ae26-97609660e910" alt="" width="563"><figcaption><p>What will be built in Leadzy lesson 2. </p></figcaption></figure>

Humans begin to process speech from birth. We hear numerous sentences over time which help us understand new ones. Consider your bot as a baby: it needs you to 'teach' it many expressions to recognize ones it has never encountered before.

{% hint style="success" %}
Teaching a bot to process language is called Natural language processing, which you’ll see referred to as NLP. For a deep dive in NLP, read more [here](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp).
{% endhint %}

In Chatlayer, building a NLP model is done in 3 steps:

1. Define what the users would mean (the [intents](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp/intents)).
2. Define how users could formulate those intents (the [expressions](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp#expressions)).
3. With those intents and expressions, [train the NLP](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp#expressions) so that your bot learns to properly label an expression with an intent.

Let’s build a small NLP model for our retail chatbot.

## Step 4: Add an intent

After the bot introduced itself and suggested a discount, we would like users to be able to type if they’re interested. To do so, we need to add a yes intent.

{% hint style="success" %}
Intents are a group of expressions or utterances that mean the same thing. When you build a chatbot, an intent can be referred to as a user goal. For instance, the intent yes could be made of expressions like *I agree*, *Yes*, *yes please*, etc. Learn more about intent and expressions [here](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp/intents).
{% endhint %}

### Create an intent

To create an intent:

1. Under the NLP tab on the left-hand side, click on **Intents**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FKbX1GgzX9ehgVUIcEXhz%2FScreenshot%202024-03-26%20at%2015.57.46.png?alt=media&#x26;token=3b190f0b-08d8-49d9-86c3-e763eaf42f39" alt=""><figcaption><p>The Intents tab is empty.</p></figcaption></figure>

2. Click on the **+** button at the top of the screen, or on the green **Create intent** button in the middle of the screen.
3. A **Create intent** window opens. Give your intent the name *yes*, and add a description to it, e.g. *An intent to agree or say yes to a discount*.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FHgYQ6y7YU9AgVvNWarDW%2FScreenshot%202024-02-02%20at%2012.13.38%20(1).png?alt=media&#x26;token=8302b9f8-c5cc-4fca-ac0c-09b380fe6dac" alt="" width="375"><figcaption><p>Create a new yes intent and give it a description.</p></figcaption></figure>

4. Click on **Create**.

Your intent now appears on your screen, with zero expressions in it. This means that it is empty. We need to add expressions to it so that we can use it.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FFSDaY6QZag71tDSzyOZu%2FScreenshot%202024-03-26%20at%2016.01.15.png?alt=media&#x26;token=9562f55b-1ef8-4e4e-9b17-194c533678b8" alt=""><figcaption><p>The yes intent has 0 expressions in it.</p></figcaption></figure>

### Add expressions to an intent

To add expressions to your **yes** intent:

1. From your **Intents** page, click on the **yes** intent that we just created.
2. Type your expression in the text field. For instance, type *yes please*.
3. Let’s first add expressions manually. Either click on the **+** button next to it, or click Enter on your keyboard. You can add expressions like:
   * *yes*
   * *oh yeah!*
   * *i'd love that*

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FurCtyvW5WkeVZGfC20RY%2FScreenshot%202024-02-02%20at%2012.17.16.png?alt=media&#x26;token=c8cdf2be-5c7c-4c37-9f92-3f347e05ff91" alt=""><figcaption><p>Manually add expressions to your intent. </p></figcaption></figure>

4. If you would like AI to generate expressions for you:
   * &#x20;click the stars button next to the text field.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FpmtSXK0ky8NpQp2n8NSz%2FScreenshot%202024-03-26%20at%2016.05.04.png?alt=media&#x26;token=ef1b5faa-4b87-4736-9042-8bd349523451" alt=""><figcaption><p>Generate new expressions using AI.</p></figcaption></figure>

* Accept the Generative AI terms and conditions.
* You’re suggested a list of expressions based on the intent that you made. Select the generated expressions that you’d like to keep.
* Click on **Add selected**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FfPF0xn3sZAepkaE3IxCe%2FScreenshot%202024-02-02%20at%2012.20.39.png?alt=media&#x26;token=534d689f-4fae-43c5-a6a7-728df8d7b1d9" alt=""><figcaption><p>Add AI-generated expressions to your intent.</p></figcaption></figure>

The added expressions appear now as a list underneath your intent.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FunjuaQKav2TNVnxSvDVb%2FScreenshot%202024-03-06%20at%2015.26.43.png?alt=media&#x26;token=dfa746df-2e05-49bd-9002-dcbf45bf6fc9" alt=""><figcaption><p>The yes intent contains 6 expressions.</p></figcaption></figure>

You've successfully created an intent! This means that your intent now has expressions. However, it's not yet utilized in the bot. Let's explore how to connect this intent to a block.

### Make your intent trigger a response

For now, your intent exists in your chatbot but it isn’t used inside the conversation. In other words, when a user says ‘*yes*’, it wouldn’t trigger any response from the bot.

To make your intent trigger a response, we need to insert this intent in the bot canvas.

#### Add an Intent block to your canvas

To add your intent to your canvas:

1. Under **Bot dialogs**, click on **Flow** to access your bot canvas.
2. From the left-hand side, drag and drop an intent block to your canvas.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FrrIVDw1UWdeKNuSkqD1i%2FScreenshot%202024-02-02%20at%2016.13.19.png?alt=media&#x26;token=afa526c5-6e1e-4d9d-be89-0f456d15a911" alt=""><figcaption></figcaption></figure>

3. The Intent block opens on the right-hand side on the screen. From the dropdown, select yes, which is [the intent that you just created](#create-an-intent).

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F28xBu7bVwhh9qd6RvfYf%2FScreenshot%202024-02-02%20at%2016.18.15.png?alt=media&#x26;token=a9a90db8-219f-4436-848f-9d977767ec15" alt="" width="375"><figcaption><p>Add the yes intent to your canvas.</p></figcaption></figure>

#### Connect your intent to a response

Now, if the user answers ‘**yes**’, we would the bot to answer ‘Amazing!’. To do so, we should link the intent block to another one by using a Go-to connection.

{% hint style="success" %}
On Chatlayer, a [Go-to connection](https://docs.chatlayer.ai/bot-answers/go-to-connections) is represented by an arrow on the canvas. If the block A is linked to block B by a Go-to, it means that block B will happen just after block B in the conversation.
{% endhint %}

To connect your intent to a response:

1. Still from inside your intent block, click on **Go to**, at the bottom of the window.
2. Click on the placeholder to select a block where the bot should go to after this one. Create a new block by giving it a name. Type *Yes to discount* and select the **Message** block type.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FJ5yFcFR7v8ioyxIaL8Ei%2FScreenshot%202024-03-06%20at%2015.34.57.png?alt=media&#x26;token=471e3d97-ea9a-4a57-96da-88f17af595d9" alt="" width="375"><figcaption></figcaption></figure>

3. Click **Save**.

The **yes** intent now appears on your canvas and it’s linked to a block called **Yes to discount**.

Yet, the content of **Yes to discount** block is still empty. To edit the content of this new block:

1. Click on the **Yes to discount** block to open it.
2. Add a text there that says: *Amazing!*
3. **Save** your changes.

The result on your canvas should look like this:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FkTZvWFblK7QHakE6VUtM%2FScreenshot%202024-02-02%20at%2016.29.39.png?alt=media&#x26;token=bc0acdc5-34de-42a7-80ef-2022cdede698" alt=""><figcaption><p>The yes intent triggers the Yes to discount block.</p></figcaption></figure>

Time for testing the changes!

#### Test your bot

Reproduce what we did in step 3 to test your bot:

1. Enter one of the expressions of the **yes** intent.
2. Your bot should recognize the expression and answer *Amazing*!

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FvvJ2314s9uAvgLrOfVk8%2FScreenshot%202024-02-06%20at%2011.26.56.png?alt=media&#x26;token=8adef3eb-1419-400f-b199-4b502e3f3991" alt="" width="374"><figcaption><p>Test your flow if you say yes to a discount.</p></figcaption></figure>

3. Click on the **Restart conversation** icon at the top right corner of the **Test window.**

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FRBDZIDqyK8JZdjbreYPe%2FScreenshot%202024-03-26%20at%2016.15.31.png?alt=media&#x26;token=fd87a80b-d790-453f-b52b-fb1fd8e0bbe6" alt="" width="375"><figcaption><p>Restart the test conversation.</p></figcaption></figure>

4. Now, enter something that wasn’t in your set of expressions, like *yeah sure*.
5. Your bot should display the **Not understood** block as follows:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FpEpdkRCijsXgVceSX1v7%2FScreenshot%202024-02-06%20at%2011.29.57%20(1).png?alt=media&#x26;token=954aa5ff-6660-4a71-ba7c-4ca79e28ff95" alt="" width="373"><figcaption><p>Test your bot with an expression that wasn't in your intent.</p></figcaption></figure>

{% hint style="success" %}
The **Not understood** block is triggered when your bot didn’t understand what the user said.
{% endhint %}

This means that your bot doesn’t recognize *‘yeah sure’* as a **yes** intent. Why is that the case? Because you we haven’t trained the NLP model yet!

{% hint style="info" %}
If you haven’t [trained your NLP](#train-the-nlp-model), your chatbot will only be able to recognize the exact expressions that you have entered in an intent.
{% endhint %}

## Step 5: Train your NLP

Let's explore how to train the Natural Language Processing (NLP) model to recognize a wider range of expressions.

{% hint style="info" %}
[Training your NLP ](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp#train-the-nlp)model allows your bot to understand new expressions that convey the same meaning as those already entered in an intent.
{% endhint %}

### Train the NLP model

To train your NLP:

1. From your Intents tab, click on the **Train** button at the upper right corner of your screen.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fln2vShqI4mcc4Hbc2d1j%2FScreenshot%202024-03-19%20at%2011.52.56.png?alt=media&#x26;token=6a437eee-d47f-42db-9640-a79d42a9e234" alt=""><figcaption><p>Train your NLP by clicking the button on the top right corner of your Intent tab.</p></figcaption></figure>

2. A window pops up. Select **English** as the language that you want to train.
3. Click on **Update**.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fx8qCN6KfPnHpWgZ8chPL%2FScreenshot%202024-02-06%20at%2011.47.05.png?alt=media&#x26;token=0b9a511e-8fbf-4d10-9b62-5efbfc077c22" alt="" width="374"><figcaption><p>Select the language to train your NLP on.</p></figcaption></figure>

{% hint style="info" %}
You can see when was the last time your NLP was updated by checking the [NLP dashboard](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp/nlp-dashboard-and-nlp-improve#nlp-dashboard). To do so, go to **Dashboard** under the **NLP** tab.
{% endhint %}

{% hint style="success" %}
Tip: turn on the [AI Intent booster](https://docs.chatlayer.ai/understanding-users/natural-language-processing-nlp/ai-intent-booster) to increase the recognition of your intents for smaller bots. This will be explored in a follow-up tutorial dedicated to the Chatlayer AI functionalities.
{% endhint %}

### Test your bot

It’s time now to test the bot with our *yeah sure* again.

Your bot should recognize it, therefore answer with the right block!

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F6r48IeCNCH9HqeatJrxB%2FScreenshot%202024-02-06%20at%2011.58.14.png?alt=media&#x26;token=f4e33008-3747-4e75-bc66-85fe5a28b3b2" alt="" width="366"><figcaption><p>Test your flow with an expression which isn't part of your set of expressions.</p></figcaption></figure>

## \[Optional: Test your knowledge]

Reproduce the same steps so that you add a **no** intent: create the intent, fill it with expressions, link it to a block, train your NLP and test it.

This is what it should look like on your canvas:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2Fl7hfm3I4nULvhGjsbgEj%2FScreenshot%202024-02-06%20at%2012.13.59.png?alt=media&#x26;token=ea9a5553-2a9a-4592-a8ff-444595fc2c7f" alt=""><figcaption><p>The no intent triggers the No to discount block.</p></figcaption></figure>

## Step 6: Edit your Not Understood block

Every bot should have a way to redirect users to a human. Typically, this is what you want to happen if the user is not understood multiple times.

To edit your Not Understood block:

1. From your canvas, double click on the **Not Understood** block to open it.
2. Edit the text for the following: *I’m sorry, but I didn’t get that. Please try a rephrase or send us an email with your question:* [*email@company.com*](mailto:email@company.com)*.*
3. **Save** your changes.

It should look like so on your canvas:

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F88VyzubsE4Dtp9NDpYNn%2FScreenshot%202024-03-19%20at%2011.57.11.png?alt=media&#x26;token=8f6df572-35b6-4bd0-a517-a369cd1754c4" alt=""><figcaption><p>When the user says something that the bot doesn't understand, the Not understood block gets triggered.</p></figcaption></figure>

## Lesson 2 recap

In this lesson, you’ve learned how to:

* [ ] Make an NLP model.
* [ ] Add intents to your NLP, and give them expressions.
* [ ] Trigger a response from the bot based on what it recognized as an intent.
* [ ] Train your NLP model so that it recognizes more expressions.
* [ ] Edit your Not Understood block so that it redirects your user to a human.

## Coming next

In the next lesson, we will see how your bot can keep user input in memory to re-use it later.

{% content-ref url="3.-collect-and-display-user-input" %}
[3.-collect-and-display-user-input](https://docs.chatlayer.ai/start-quickly/leadzy-tutorial/3.-collect-and-display-user-input)
{% endcontent-ref %}

## 💬 Feedback

{% hint style="warning" %}
Your feedback on the tutorial means the world to us! Please, let us know what you think through [this short form.](https://forms.office.com/Pages/ResponsePage.aspx?id=ropROyGJe0qEl2GddWziDlEYn6XpsIRDjnCtdRk8L21UMFZMMlAzN0tHOTI4UjMxVTgzTVAwTE5aOCQlQCN0PWcu)
{% endhint %}
