Introduction
Entities are Dialogflow’s mechanism for identifying and extracting useful data from natural language inputs.
While intents allow your agent to understand the motivation behind a particular user input, entities are used to pick out specific pieces of information that your users mention — anything from street addresses to product names or amounts with units. Any important data you want to get from a user’s request will have a corresponding entity.
There are three types of entities:
System entities
Dialogflow is equipped with numerous system entities, which allow agents to extract information about a wide range of concepts without any additional configuration. For example, system entities are available for extracting dates, times, and locations from natural language inputs.
Developer entities
If you need to extract information about concepts beyond those covered by Dialogflow’s system entities, you can define your own developer entity types. For example, a brand might create an entity type to recognize its unique set of product names.
Session entities
It is also possible to define entity types that apply only to a specific conversation. For example, you might create an entity type to represent the time-sensitive options available to a particular user when making a booking. These are called session entity types.
How to enable and use System Entities in Dialogflow
- Navigate to Go to the Dialogflow Console.
- Select the AppointmentScheduler agent that we created in the previous codelab.
- Click on “Intents”
- Click on “Schedule Appointments” to open the intent settings
- You will notice that in the current intent settings there are training phrases like “Set an appointment for 4pm tomorrow” where Date and Time are automatically extracted as system entities date and time. Feel free to add more training phrases to see how Dialogflow extracts the system entities automatically.
- As you saw, System entities allow agents to extract information about a wide range of concepts without any additional configuration. Data like address, emails, currency, phone numbers are some of the common examples of system entities. Find more here.
How to enable and use Developer Entities in Dialoglfow
Create Developer Entities
- So far we have been addressing our Appointment scheduler in a generic manner. Let’s suppose our scheduler is for a state’s Department of Motor Vehicles (DMV) service.
- Drivers license and registration are two main services that DMV offers, so let’s create those entities.
- Click on Entities
- Click on “Create Entity” button
- Add the Entity Name “AppointmentType” and add “Vehicle registration” and “Driver license” as the two entity entries with a few synonyms and Click Save. See the screenshot for examples to enter.
- You can add more rows with more services as entity types.
- You can check the box “Allow automated expansion” to add more entities automatically. Automated expansion of developer entities allows an agent to recognize values that have not been explicitly listed in the entity. If a user’s request includes an item that isn’t listed in the entity, automatic expansion recognizes the undefined item as a parameter in the entity. The agent sees the user’s request is similar to the examples provided, so it can derive what the item is in the request.
- [For your information] Upload or download entities in bulk:
- Click on the three dots, near “”Create Entity” button.
- You will see “upload Entity” button
- Then you can upload a file in CSV or JSON format.
- Should end this by saying “click Save”
Edit Intent to accommodate the newly created developer entity
- Click on “Intent” on the left pane
- Add the training phrase into “Schedule Appointment” intent.
- “Set an appointment for drivers license for 3pm tomorrow”. You will see that Drivers license is identified as a developer entity “AppointmentType” that we set up in the previous section. System entities time and date are also automatically identified.
- Add a few more training phrases like these.
- License renewal appointment on Monday
- Set an appointment at 2pm on Monday for license
- Vehicle registration appointment for Monday
- Remember slot filling from the first Codelab? Review slot filling here. In short, to book an accurate appointment, we need all three pieces of information: Appointment Type, Date and Time. If the user only provided one or two pieces then Dialogflow will ask for the left over information before it acts on the response.
- We need to make “AppointmentType” a required field just like time and date. To do so, click on the Checkbox near AppointmentType.
- Then add a prompt, if the user does not provide appointment type, this prompt will be used. Example prompt: “What services are you looking to get? DMV offers Driver’s license and vehicle registration services.”
- When done, Save the changes.
Test Your Chatbot!
Let’s test our chatbot, you can test it in the simulator or use the web or google home integration we have learnt in previous codelabs.
Test case 1: In this case user only asks to set an appointment without the three pieces of information. Hence, Dialogflow’s slot filling asks for the date, time and appointment type using the Slot filling prompts that we set up in “Action and Parameters” section of the intent.
- User: “Set an appointment”
- Chatbot response: “What date?”
- User: “May 23”
- Chatbot response: “What time would you like to come in?”
- User: “10am”
- Chatbot response: “What services are you looking to get? DMV offers Driver’s license and vehicle registration services.”
- User: “License”
- Chatbot: “You are all set for your vehicle registration appointment on 2019–05–23 at 10-:00:00. See you then!”
Test case 2: In this case user asks to set an appointment with partial information. Hence, Dialogflow’s slot filling asks for the date, time and appointment type using the Slot filling prompts that we set up in “Action and Parameters” section of the intent.
- User: “Need an appointment for 4pm tomorrow”
- Chatbot response: “What services are you looking to get? DMV offers Driver’s license and vehicle registration services.”
- User: “License”
- Chatbot: “You are all set for your Drivers License appointment on 2019–04–24 at 16:00:00. See you then!”
Test case 3: In this case user provides all the information in one shot. Dialogflow processes the information and provides a response with appointment confirmation.
- User: “Set an appointment for vehicle registration at 2pm tomorrow”
- Chatbot response: “You are all set for your vehicle registration appointment on 2019–04–24 at 14:00:00. See you then!”
Congratulations!
You built a chatbot created a chatbot with custom entities.