A Healthy Dialogflow Part I: A Case for Google Cloud Platform’s NLP Service

Zakariya Ahmed
Slalom Build
Published in
8 min readMar 11, 2020

In the age of automation, we are experiencing a growing trend of investment and utilization of Artificial Intelligence and Machine Learning platforms for business applications and services. While most of these “smart” platforms are in early stages of growth and development, one service primed to provide value today is Google Cloud Platform’s Dialogflow.

The GCP Dialogflow platform enables users to build interactive and engaging text or voice-based conversational interfaces such as chatbots, using Natural Language Processing (NLP) powered by Google’s AI.

In 2016, the chatbot market size was approximately $190.8 million, and it is expected to grow to $1.25 billion by 2025. It is easy to see why — Chatbots allow for 24-hour customer service, immediate responses to inquiries, and the ability to answer simple questions leading to better user experiences.

Juniper predicts chatbot conversations will deliver $8 billion in cost savings by 2022. Massive opportunity exists for companies to take advantage of growth in this space and integrate smart chatbots into services and platforms for cost savings and better user experiences.

At GCP Next ’19, it was revealed Dialogflow is now integrated with Salesforce’s Einstein platform allowing customers such as Hulu to build applications using Dialogflow’s NLP service:

As an existing Service Cloud customer, Hulu will be able to seamlessly integrate Google AI to proactively identify and resolve customer issues, boost agent productivity, and improve data quality and analytics.

After seeing Dialogflow in action, I wanted to test the capabilities of this NLP platform myself. Below are some findings from a proof of concept with the Dialogflow platform.

Section I: Dialogflow Crash Course

Before diving into how Dialogflow provides value to applications, it is important to understand the basic concepts comprising this NLP service.

Agent

The agent is an all-encompassing natural language understanding module which handles user conversations. Think of the agent as a call center rep trained to handle customer conversations and requests.

Intents

An intent is an end-user request. User queries such as “What’s the weather outside?” or “How is the traffic to LAX?” are considered intents which can be answered or fulfilled by the agent. The agent extracts data fields and parameters from the intent in order to answer the user request.

Entities

Entities are parameters extracted from end-user intents which are captured to fulfill requests. Dialogflow comes pre-built with several entities such as time, color, and location. Entities can also be built from scratch for the agent. For example, if you are building a health or medical application, the agent might need symptom and disease as entities to capture a patient’s condition.

Context

Context is used to chain intents together to form natural conversations between the agent and end-user. Consider the following conversation:

[End-User]: I would like to buy some t-shirts.[Agent]: Ok. How many t-shirts would you like to buy?[End-User]: Three.[Agent]: Ok. I am placing an order for 3 t-shirts.

This conversation is comprised of 2 intents (i.e user requests) chained together via context. Without context, the agent would not be able to understand that the end-user is asking for three t-shirts.

Fulfillment

Without fulfillment, the Dialogflow agent can only respond with static pre-defined messages. In order to fulfill requests dynamically, fulfillment must be enabled.

Let’s revisit the t-shirt example:

[End-User]: I would like to buy some t-shirts.[Agent]: Ok. How many t-shirts would you like to buy?[End-User]: Three.[Agent]: Ok. I am placing an order for 3 t-shirts.

To complete this request, the agent would need database access to check if t-shirts are in stock and to send requests to the application’s checkout and payment services. The Dialogflow console makes fulfillment easy with a webhook backed by serverless GCP Cloud Functions. These functions can call other HTTP endpoints or services in order to fulfill the end-user request.

Once we have the concepts of Agent, Intent, Entity, Context, and Fulfillment down, we can begin to work with Dialogflow! While these are the main concepts in Dialogflow, there are additional concepts that round out Dialogflow’s capabilities. Please see the Dialogflow documentation for an in-depth explanation of all of the concepts.

Note: Managed cloud services and platforms such as Dialogflow are subject to frequent revisions and iterations on existing features. To stay up-to-date on the most relevant features, it is always important to read the documentation! For example, Dialogflow’s V2 API is out now and V1 will be deprecated this year.

Section II: A Healthy Dialogflow (Proof of Concept)

Excited about the business opportunities and customer experiences Dialogflow can enable, a group of co-workers and I wanted to build a proof of concept to evaluate the power of this platform. Over the course of a month, the team built a Dialogflow agent known as eVect Health.

The Concept

eVect Health is a chatbot application built on GCP using a Dialogflow agent trained to ingest text and spoken user requests to provide health and medical information pertaining to vector borne illnesses. This application would be used by individuals traveling internationally who need prevention information regarding vector borne diseases and treatment information if they feel ill or have symptoms while traveling.

The service’s pre-trained NLP capabilities will allow users to converse with the application while the agent fulfills user requests by accessing data stored in BigQuery via Cloud Functions.

eVect Health Intents

The Dialogflow agent has two features: Warning and Prevention and Condition Intake which are comprised of several intents.

Warning and Prevention

Warning and Prevention is comprised of an intent and a follow-up intent. This conversation flow is for users wanting health and disease information about a country they will be visiting.

An example conversation:

[End-User]: 
I am traveling to Indonesia next week.
[Agent]:
I am looking into your trip.
[Agent]:
Here is a list of active diseases and contagions in Indonesia.
- Measles
- Hepatitis A
- Typhoid
[Agent]:
If you would like prevention tips on a disease, respond with the name of the disease.
[End-User]:
Tell me more about typhoid.
[Agent]:
Let me look up some prevention tips for that. You can get typhoid through contaminated food or water in Indonesia.
CDC recommends this vaccine for most travelers, especially if you are staying with friends or relatives, visiting smaller cities or rural areas, or if you are an adventurous eater.

Training

The initial Warning and Prevention intent is triggered by the user describing a future trip to a country. Sample test phrases for training the agent include:

I will be traveling to South America.
I’m visiting family in England.
I am backpacking across Africa.
I’m going to Indonesia.

Training the agent can be done directly from the intent console page — simply add the training phrases and hit Save. Dialogflow will pickup and annotate the entities in each phrase which will then be used to detect entities in user requests.

Condition Intake

Condition Intake is comprised of an intent, and 3 follow-up intents. The initial intent is triggered when the user tells the agent they are not feeling well on a trip. The agent will attempt to gather information about the user’s symptoms and evaluate if they need to seek medical attention. If the agent determines treatment is required, it will provide local hospital location information to the user.

An example conversation:

[Agent]:
Good day! What can I do for you today?
[End-User]:
I’m experiencing a high fever on my trip.
[Agent]:
What city are you currently located in?
[End-User]:
Paris.
[Agent]:
I understand that you are currently experiencing High Fever on your trip to Paris. Is this correct?
[End-User]:
Yes.
[Agent]:
I would like to gather some more information on your current condition. Could you please tell me if you’re experiencing any of the following symptoms?
- Severe Headache
- Joint Pain
- Eye Pain
[End-User]:
I’m also experiencing a severe headache and eye pain.
[Agent]:
Thank you for your cooperation.
Based on recent outbreaks in your area and the symptoms you’re exhibiting, you may have Dengue Fever.Please make your way to 1 Parvis Notre-Dame — Pl. Jean-Paul II, 75004 Paris, France for immediate treatment. Would you like additional hospital locations in your area?[End-User]:
Yes please give me more hospital options.
[Agent]:
There are other medical facilities located at: 47–83 Boulevard de l’Hôpital, 75013 Paris, France and 1 Avenue Claude Vellefaux, 75010 Paris, France

Training

The initial Condition Intake intent is triggered by the user describing symptoms of their condition or mentioning that they feel unwell. Sample test phrases include:

I’m experiencing muscle pain in London.
I have back pain and a fever.
Everything hurts.
I feel sick in Hong Kong.

eVect Health Entities

Entities are Dialogflow’s mechanism for identifying and extracting useful data from natural language inputs. Dialogflow’s pre-built entities such as geo-country or geo-city can be utilized out of the box. In addition to pre-built entities, the agent relies on the following custom trained entities:

@Disease
@Symptom

The @Disease entity is used to capture user mentions of diseases such as Polio, Malaria, or Typhoid.

The @Symptom entity is used to capture user mentions of symptoms such as Joint Pain, Nausea, or Fever.

The more entries and examples an entity has, the better the agent becomes at detecting entities in user-inputs. Training and updating entities takes only several minutes, although with larger data sets the time to train the agent would increase.

Entities allow the Agent to capture keyword information from user requests

Similarly to training intents, entities can also be created, defined, and trained from the Dialogflow console.

Next Steps

We now understand the concepts Dialogflow is built on (Agent, Intent, Entity, Context) and are able to use those features to start creating a chatbot. The next step is enabling Dialogflow fulfillment to dynamically respond to user requests with actionable information. Without enabling fulfillment, Dialogflow can only respond to requests using hard-coded values returning static canned responses.

In A Healthy Dialogflow Part II, we will discuss enabling fulfillment for Dialogflow as well as development and deployment of a Google Cloud Function that will power the application. Finally, we will do a performance analysis of eVect Health running on the Dialogflow platform to see how this NLP service holds up against real user requests.

Thanks

I hope you found this article helpful for understanding and working with Google Dialogflow. If you have questions, concerns, or comments feel free to drop a thought in the comments section, and please be sure to tune in for Part II where we discuss implementing dynamic responses with code and deployment examples.

Thanks!

--

--

Zakariya Ahmed
Slalom Build

Talking to myself because I am my own consultant.