# How to set up Entity Recognition in Flow Builder

In this guide, you will learn how to use the **Recognize Entities** step in [Flow Builder](https://www.messagebird.com/en/flow-builder/) to automatically extract entities from customer messages and use them to improve your flows.

&#x20;

**Requirements**&#x20;

* A [MessageBird account ](https://dashboard.messagebird.com/en/sign-up)
* [WhatsApp for Business account](https://www.messagebird.com/whatsapp/) or any other channel from [MessageBird's offering](https://dashboard.messagebird.com/en/channels)

&#x20;

**What’s Entity Recognition?**

**Named Entity Recognition** (NER) is the task of identifying and categorizing entities (key information) in text. An entity is something that often refers to the same thing. MessageBird’s Recognize Entities step uses machine learning models to detect these entities. For example, it might recognize the date in “I want to book a ticket for **next Friday**” or the email-address in “You can reach me on **<help@messagebird.com>**”.&#x20;

Use the demo in the Flow Builder step to check out more entities. In combination with our [Recognize Intent](https://support.messagebird.com/hc/en-us/articles/360012177857-How-to-set-up-the-Recognize-Intent-step) step, you can create some powerful applications built upon natural communication with your users.

**Supported entity types**

The **Recognize Entities** step supports the following entity types:

| **Entity Type**                                                   | **Flowbuilder entity** | **Example**                   |
| ----------------------------------------------------------------- | ---------------------- | ----------------------------- |
| Amount of Money                                                   | amount-of-money        | €42                           |
| Credit Card Number                                                | credit-card            | 4111-1111-1111-1111           |
| Distance                                                          | distance               | 10 kilometre                  |
| Duration                                                          | duration               | 3 mins                        |
| Email                                                             | email                  | <help@messagebird.com>        |
| Numeral                                                           | numeral                | 88                            |
| Ordinal                                                           | ordinal                | 33rd                          |
| Phone Number                                                      | phone-number           | +31 20 123456                 |
| Temperature                                                       | temperature            | 38 degrees                    |
| Time                                                              | time                   | Today at 9 AM                 |
| URL                                                               | url                    | <https://www.messagebird.com> |
| Volume                                                            | volume                 | 3 Gallons                     |
| Interval                                                          | interval               | From 9 to 5                   |
| Person                                                            | person                 | Robert Vis                    |
| <p>Geopolitical entity<br>(Cities, countries/regions, states)</p> | geopolitical           | San Francisco                 |
| Quantity                                                          | quantity               | 3 cups                        |

&#x20;

**How does it work?**

To recognize entities our **Recognize Entities** step uses an advanced (probabilistic) language parser in combination with Machine Learning to extract and find entities. It does so by learning from lots of examples of how an entity is used and in which contexts. It then uses a rule-based parser to turn the found entities into an expanded version (more explained on that below).

**Setting up an Entity Recognition flow**

In this first part of the quickstart, we’ll set up a flow for the fictional company CoffeeBird. The flow uses the **Recognize Entities** step to allow users to place a coffee order in an autonomous way.

**Step by step**

1\. Log in to your [MessageBird Dashboard](https://dashboard.messagebird.com/en/login) and go to [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).

2\. Select a flow (or create a new one). For this example, we’re going to create a **new custom flow** with an **Omni-channel** trigger.

3\. Create a **dataset** and **intent recognition** step according to the [**Intent Recognition - Quickstart**](https://docs.messagebird.com/connectivity-platform/getting-started/how-to-set-up-the-recognize-intent-step). The **dataset** should have two intents: “order” and “book”.

4\. Done? Awesome! Set up branching between the intents—we’ll only continue with the “Order” intent here.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-39b2f8ee13ff76bc64b0cb747dab643d7d331d14%2FScreenshot_2020-09-11_at_15.30.33.png?alt=media" alt=""><figcaption></figcaption></figure>

5\. **Reply** (using the **Reply to channel message** step) with: “How many coffees would you like to order?”

6\. Add a **Wait for a response** step and call the output variable of the response *coffee\_amount\_message*.

7\. Create a **Recognize Entities** step. Set the ‘**Content to recognize**’ to *coffee\_amount\_message.* Then, configure it to recognize **numerals** by clicking **Add entity** and setting the entity to **numeral** (we can use the variable name *coffee\_amount* here). And save both the entity and the step.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-e1e3a41c863488434d8c18ce53076e18bfb20fca%2FScreenshot_2020-09-11_at_15.32.35.png?alt=media" alt=""><figcaption></figcaption></figure>

8\. The user should now be able to answer with “I’d like two!” and “2” should end up in *coffee\_amount*. You can verify your flow by replying to the channel message with “You ordered **coffee\_amount.normalized** (**coffee\_amount.text**) coffee” with the **Test** feature next to the **Save draft** and **Publish** buttons.&#x20;

This step shows the attribute syntax (**coffee\_amount.normalized** instead of just **coffee\_amount**) that is sometimes used in Flow Builder, you might have seen it before when working with the **contact** variable. When recognizing entities, you probably want to do something with them. For instance, use a customer number as a tag in [Inbox](https://www.messagebird.com/inbox/), enrich your contacts using a recognized email, hand a custom product number over to your CRM, or use the desired delivery date to update your order fulfillment software. However, most systems won’t understand the date of the text “Next week friday” but will require more specific formatting. That’s what **coffee\_amount.normalized** is providing here.

Later in this quickstart, we will tell you more about the expansion of these variables. To get access to **coffee\_amount.normalized** start by typing **{{** and select the **coffee\_amount** variable and the **normalized** attribute.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-3f03e06735b82ad8e5019bd0dd75c58e88fff65b%2FScreenshot_2020-09-11_at_15.34.51.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-a8a519da778ffe8a7c68435a896bad00636c9887%2FScreenshot_2020-09-11_at_15.36.16.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-f7618a72352cfa66b43f6278f12dad2827486981%2FScreenshot_2020-09-11_at_15.37.15.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

9\. Reply to the channel message with: “When would you like to come to pick your coffee up??”

10\. Add a **Wait for a response** step (*pickup\_time*).

11\. Create a **Recognize Entities** step. Configure it to recognize **time** by going through the same process as in step 7 while choosing the right entity and variable names. This should recognize time in a message like: “At **3:00 pm**” or even “In **2 hours**”.

12\. Reply to the message with: “We’ll have it ready at **time.text** (**time.normalized**)”

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-085d84e0abe310e4d665c449344a150fef8a3354%2Fimage2.png?alt=media" alt=""><figcaption></figcaption></figure>

13\. You can now use the information you’ve collected in the conversation to start your order using a **webhook** or set it up as an **Inbox ticket**!

14\. **Publish** your flow in the top-right corner of your screen, and you're good to go!

&#x20;

**Good practices**

Check whether the **Recognize Entities** step found entities before continuing. A **Jump to** step might help here to go back up the flow and have the user send another message. See below for an example.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-5f5c102ffb029e69960002b354ef1c9a15860561%2Fimage5.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

**Expansion**

In step 8 of **Setting up an Entity Recognition Flow,** we showed you how the entity recognition **attributes** work. As explained, normal computer systems will not know how to work with text such as **“Next friday at 14:00”** but do understand the [ISO-version](https://en.wikipedia.org/wiki/ISO_8601) of the date **“2020-09-18T14:00:00.000+00:00”**. That’s why our Recognize Entities step does this automatically, but still gives you access to the text version as well. You can access them for a variable called **time** by using **{{time.text}}** and **{{time.normalized}}**.

Not all entities are able to be expanded. The ones where it is possible are: **time, interval, duration, and numeral**. The table below shows how they get expanded. Other entity types do not get expanded and the **.normalized** version will be filled with the same value as the **.text** version

&#x20;

| **Entity Type** | **Example**                                    | **variable.text**     | **variable.normalized**                                     | **Normalized format**                                                                                                                                 |
| --------------- | ---------------------------------------------- | --------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| time            | I’ll be there at **14:00**                     | 14:00                 | 2020-09-09T14:00:00.000+00:00                               | <p>ISO-date</p><p><em>Year</em>-<em>Month</em>-<em>Day</em>T<em>Hour</em>:<em>Minute</em>:<em>Second</em>.<em>Milliseconds</em>+<em>Timezone</em></p> |
| interval        | It will be delivered **between 3pm and 16:00** | between 3pm and 16:00 | 2020-09-09T15:00:00.000+00:00,2020-09-09T16:01:00.000+00:00 | ISO-date-from,ISO-date-to                                                                                                                             |
| duration        | It will take **3 hours**                       | 3 hours               | 3 hour                                                      | <p><em>Value</em> <em>unit</em></p><p>Unit: Hour, minute, second, day</p>                                                                             |
| numeral         | I’ll take **three**                            | three                 | 3                                                           | *Value*                                                                                                                                               |

&#x20;

&#x20;

**Adding custom coffees**

In this second part of the quickstart, we’ll set up custom entities to have CoffeeBird sell not only coffee but also more exotic variants like a Cappuccino and a Flat White. We’ll extend the previous flow to ask the user what kind of coffee they want to order.

First, we’ll set up the custom entities (these are the custom/specific words that we will be looking for within incoming messages). There are two types of Custom Entities:

* **Keywords**: This is the type that we’re going to be using in our example. It has a list of keywords that it extracts, e.g. our coffee types. It has the ability to recognize them even with some spelling errors. These keywords also are expanded in the same way that our **time** entity type is. Every keyword can have variants that will be expanded to the same keyword. For example in the context of CoffeeBird “Black” can be expanded to “Coffee”. Variants are added by using the plus sign to the right of a keyword.
* **Regular Expressions**: This type is all about extracting entities that follow a specific format, e.g. product number like “MB:NL:102”. To learn more about regular expressions and test your regular expressions take a look [here](https://regex101.com/) and select the “Python” flavor. The exact syntax used by our regular expressions can be found [here](https://docs.python.org/3.8/howto/regex.html#regex-howto).

You might use a Regular Expression to match a Dutch postal code by using this regular expression: *\[1-9]{1}\[0-9]{3}\s?\[a-zA-Z]{2}*

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-f40cac73c489477b5f9e55ae312995c9c7f406b7%2Fimage10.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

**Step by step**

**Step 1: Set up your custom entities**

1\. Log in to your [MessageBird Dashboard](https://dashboard.messagebird.com/en/login) and go to [Knowledge Bases](https://dashboard.messagebird.com/en/knowledge-base)

2\. In the list of datasets, there is an item called **Custom Entities**. Here we can set up our brand new coffees!

3\. Add a **Custom Entity** and name the new group of custom entities “Coffee types”.

4\. Choose **Keywords** on the left and add the following keywords: “Coffee”, “Cappuccino”, “Flat White”, “Espresso” and “Americano”. To extend the functionality of our entity recognizer we will add a variant for our “Coffee” keyword. Use the plus sign to the right of our “Coffee” keyword to add a variant. Fill the variant for instance with “Black”.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-2d1175c2c1841c25843c940bdff13c3eea083c74%2Fimage7.png?alt=media" alt=""><figcaption></figcaption></figure>

5\. **Save** your Custom Entities.

Done? Awesome! Let’s extend the flow to start using them!

**Step 2: Extend your flow**

1\. In the “Order” branch add an additional **Reply to channel message** with the text “What kind of coffee would you like to order? Our menu consists of Coffee, Cappuccino, Flat White, Espresso and Americano”

2\. Add a **Wait for a response** step.

3\. Create a **Recognize Entities** step below it. Configure it to recognize the custom entity “Coffee types”. The step will pick up the coffee entities we just defined even if your customer misspells them slightly!

4\. Change the **Reply to channel message** step below to include the Coffee type by using the text: “How many **coffee\_type.normalized** would you like to order?”. Notice in the image below that the misspelling “Capucino” still gets picked up as the correct coffee type!

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-05bd4035c3e720adff0d7aeb9d1cd120d8e9c7be%2Fimage1.png?alt=media" alt=""><figcaption></figcaption></figure>

5\. **Publish** your flow to get the coffee orders to come in!

And that’s it! 🎉 Now you know how to set up Entity Recognition in Flow Builder.&#x20;
