Dialogflow CX Entity Types
Learn what a Dialogflow CX entity type is and how easy it is to create entity types and evolve your NLU in Dialogflow CX, either with the console or the CX CLI!
Join the DZone community and get the full member experience.
Join For FreePrevious Requisites
Here are the technologies used in this project
- Google Cloud Account
- Dialogflow API enabled
- Dialogflow CX CLI - Installed and configured
What Are Entity Types?
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, create 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. This is what it looks like:
You will find your entity types in the Manage tab and the clicking in the entity types section:
With the Dialogflow CX Console, you can do the following:
- 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, colors, 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 I created. With the cxcli
, you can interact easily with your Dialogflow CX entity types.
All of 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:
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 a Dialogflow CX entity type is. 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!
Published at DZone with permission of Xavier Portilla Edo, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments