Dialogflow CX Entity Types (English)
What are entity types in Dialogflow CX?
Dialogflow CX Entity Types
Previous Requisites
Here are the technologies used in this project
- Google Cloud Account - Sign up here for free
- Dialogflow API enabled - How to enable it
- Dialogflow CX CLI - Install and configure Dialogflow CX CLI
What is this?
Entity Type
One of the most important parts of NLU is the Entity types or entities. These are the key information in a text, such as names, dates, products, organizations, places, or anything we want to extract from the text. We call this concept “Entities”. For example, let’s take a look at the order_intent
intent:
- I want a pizza
- I want 3 cokes
- Give me two burgers
As you can see in the example above, we can extract 2 Entity Types: quantity
and order_type
. We can extrapolate the utterances above like this:
- I want {quantity} {order_type}
- Give me {quantity} {order_type}
We can think about Entity Types as variables as well.
It is a good practice to test your training phrases with your end users. This will allow you to detect missing training phrases in your NLU.
Dialogflow Console
Dialogflow Console is a web interface where you can design your conversations by creating agents and within an agent, creating flows, intents, entity types, etc. On the Dialogflow Console, you can create and interact easily with your intent. To do that you just need to go to the Dialogflow CX Console: https://dialogflow.cloud.google.com/cx. This is what it looks like:
Dialogflow CX Console
You will find your entity types in the Manage tab and the clicking in the entity types section:
Dialogflow CX Entity types
With the Dialogflow CX Console, you can do:
- Create an entity type:
- When you create an entity type, you can add synonyms.
- Delete an entity type
- Train and validate your NLU
When you are creating an entity type, you can specify whether or not it has synonyms or if it is a regexp entity. If you choose the regexp option, the classifier will use a regular expression instead of synonyms during query classification.
These are the Entity Types that you can use in your intents:
- Custom entities: entity types created by the developer.
- System entities: the ones available in dialogflow CX (number, dates, colours, etc.).
- Session entities: these are dynamic entities that can be extended during the users’ sessions.
- Regexp entities: entities that are regular expressions.
Whenever you create, modify or delete an entity type it is important to re-train your Dialogflow CX flows. This will re-train your NLU. By doing this your bot will “understand you” including your latest changes.
Dialogflow CX CLI
The Dialoglfow CX CLI or cxcli
is a Command Line Interface Tool that you can use to interact with your Dialogflow CX projects in a terminal. It is an open-source project created by Xavier Portilla Edo. With the cxcli
you can interact easily with your Dialogflow CX entity types.
All the commands that you have available in the cxcli
to interact with your entity types are located down the cxcli entity-type
command.
Create
You can create an entity type using this tool. This command has this usage:
cxcli entity-type create [entity-type-name] [parameters]
You can find the full usage here. It is important to explain the --entities
parameter. It is a list of the entities with their synonyms, comma separated. This parameter has the following format:
entity1@synonym1|synonym2,entity2@synonym1|synonym2
Here you have an example: pikachu@25|pika,charmander@3
This a simple example of the cxcli entity-type create
command:
cxcli entity-type create order_type --entities "pizza@piza|pizzas,burguer@hamburguer|burguers" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
The command above will give you an output like this one:
$ cxcli entity-type create order_type --entities "pizza@pizza|pizzas,coke@coke|cokes" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
INFO Entity Type created with id: projects/test-cx-346408/locations/us-central1/agents/40278ea0-c0fc-4d9a-a4d4-caa68d86295f/entityTypes/457a451d-f5ce-47da-b8dc-16b17d874a5d
You can see the order_type
entity type on the Dialogflow CX Console:
order_type
Delete
Also, an entity type can be deleted. The usage of this command is pretty much similar to the one used for creating an entity type:
cxcli entity-type delete [entity-type-name] [parameters]
You can find the full usage here. This a simple example of the cxcli entity-type delete
command:
cxcli entity-type delete pokemon --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
The command above will give you an output like this one:
$ cxcli entity-type delete pokemon --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
INFO Entity Type deleted
Resources
If you want to check the full usage of the cxcli entity-type
command, please refer to this page.
If you want to learn more about Dialogflow CX entity types, check the official documentation.
Conclusion
This was a basic tutorial to learn what is a Dialogflow CX Entity Type. As you have seen in this example, creating entity types and evolving your NLU in Dialogflow CX either with the console or the cxcli
is very easy!
I hope this tutorial will be useful to you.
That’s all folks!
Happy coding!