Demystifying Dialogflow : Episode 1 — The Building Blocks

Vishnu Priya Vangipuram
Whispering Wasps
Published in
7 min readOct 14, 2019

In an attempt to be brief and explanatory about one of the popular frameworks to learn and implement Conversational AI, here I am to kick start a series of informational posts to demystify Google’s DialogFlow. Lets get the ball rolling by delving into ABC's of Dialogflow for the uninitiated.

If you are someone who has no idea about conversational AI and chatbots and the associated technicalities,Dialogflow framework is one of the best and possibly the easiest to learn and get familiar without wading through the chatbot tornado.

Enough of small talk. Let us get acquainted with terms that govern the behavior of Dialogflow and conversational AI in general.

Chatbots and Conversational AI?

Chatbots basically involve conversations between an end user and a provider of services and the facilities (eg.customer service) which the user can make use of, with maximum efficiency and least margin of error.

Conversational AI comes in to make these conversations as authentic and as explanatory as possible with little or no human assistance from the provider’s end.

There are many tools and technologies that help in building Conversational AI like Dialogflow,Wit.ai,IBM Watson,Rasa to name a few.

Now that we know the purpose chatbots serve, and the role of Conversational AI in achieving it, today,let’s get to the behavioural aspect of Dialogflow.

Also, as we get to understand the behaviour of Dialogflow,we also get to understand Natural Language Understanding/Generation,an integral part of Conversational AI.

Let’s dive into the Dialogflow jargon.

Agent :

In Dialogflow,the bot and it’s components are placed under a combined package called Agent.

Intents:

An intent in Dialogflow parlance,is nothing but the information the user wants/intends to receive from the provider.

In simple terms,it is the user’s “intention” for contacting our bot.

Consider the example:

“I want to know the weather in San Francisco.”

Here the user’s intention is to get information on the weather in San Francisco and hence the Intent can be : “get weather details”.

An user’s intention may be as simple as asking for information related to weather or as complex as wanting to know the history of certain financial transactions above a certain pre-defined or new parameters.

In Dialogflow, using it’s Intents offering,both these can be handled in an easy way with very less effort, if the training phase (more about training phases in a dedicated section at the end of the post) is carried out appropriately.

Entities :

Users with specific intentions expect the information to be as specific or accurate to their intentions.

Consider the example intent:

I want to know the weather at San Francisco.”

In this intent,the user is very specific about the weather at San Francisco,hence “San Francisco” defines the specificity of the intent and is the Entity for this intent example.

Specificity,if defined and categorized well during training,can also help in user retention and the information exchange to be real quick,enhancing the user experience.

This specificity is what we call Entities. In Dialogflow we have System Entities,where we can define the specific time,place etc using entities like sys.time,sys.geo-city,to name a few.

Dialogflow also has provision for Custom Entities, where we can define our own specificity using two concepts called Reference Value and Synonyms.

Consider the example conversation:

User : Any interesting sport event around me?

Bot : Absolutely,but may I know your favorite sport?

User : I like to watch Cricket.”

In this example the user specifically asks for a sport event and the answer from the user can be any sport.In this case,we can create a Custom Entity “Sport_Name”

Reference Value is a response we would like to give to the user if a specificity is met.

In this case our response will be the events related to Cricket,something like:

“Under 19 Cricket Tournament is underway at SS Stadium.Would you like me to book a ticket for you?”

Or if the user says Football,the reference value can be something like :

“Inter Collegiate Football Tournament starts tomorrow.Would you like to book a ticket and enjoy the thrills of the match?

Once the reference value is set,we can set the synonyms for the entity.

Synonyms are nothing but the variations in which the same specificity can be provided.

For example,the sport of Cricket can be specified by different variations or synonyms like :

Cric,Cricket match, Cricket event,Cricket Tournament” etc.

Both Cricket and Football can be defined under the single Custom Entity Sport_Name since both are sport related specifics.

Similarly we can add more than one specific under a Custom Entity and add the respective Reference Value and Synonyms in order to serve the specificity of the user intention and also give Dynamic Responses related to the specificity.

Response:

Each user intention must be provided a suitable response so as to satisfy the user intention.

While responses can be given as plain responses when they are static (or pre-defined), Dynamic Responses like the one in our previous example can be given using entities by referring them with the dollar symbol($Sport_Name in the response field for our intent in this case).

Training Phrases:

Human language is very complex in general and it vividly varies with each individual as well.

Let us consider the intent of the user wanting to know about the weather. This intention can be expressed in many ways by different individuals like :

Weather info please”

What is the weather forecast for the day?”

“I want to know about the weather here tomorrow.”

to quote a few.

These examples or Training Phrases are needed to ascertain the right intent as we train the AI to recognize user intents.

Training the AI?

The Artificial Intelligence that drives Conversational AI is about making our machine learn (using Machine Learning by adopting the learning technique used by a child wherein the information is fed and reinforced a.k.a. training data,until the machine can comprehend and understand) the complexities of Natural Language (the language that humans speak, which involves lexical,semantic and syntactic rules making use of context,grammar and the usage of language respectively),which is also called Natural Language Understanding(NLU).

Dialogflow is also an NLU engine.While the components like Intents,Entities and Training Phrases comes under the Machine Learning Part of Conversational AI, the Dialogue Management or the Natural Language Generation(NLG) part is managed by Contexts in Dialogflow.

Contexts :

At this point, we have the user intention,the specifics of the intent,the various ways in which the same intent may be expressed, under each component of Dialogflow with us.

With all these inputs,we can give the specific information asked but we still have to figure out how to maintain a flow in the conversation.

We can’t give the information related to a cricket event without the user asking for it,nor we can give any irrelevant information just for the sake of it.

This is where Contexts come into play.

Reference : https://cloud.google.com/dialogflow/docs/contexts-overview

Dialogflow has two contexts:

  • Input Context.
  • Output Context.

Now let’s see how we can use Input and Output Contexts to manage our conversation flow.

In Dialogflow,we use Input and Output Context and make a flow akin to a flowchart where the output of the previous intent passes as an input to the next Intent.

To understand this much better,let’s allocate names for each intent and set a flow using our contexts.

Let us consider our earlier example :

User : Any interesting sport event around me?” — Intent : sport_near_me

“Bot : Absolutely,but may I know your favourite sport? ”Response for sport_near_me Intent.

“User : I like to watch Cricket.”Intent : fav_sport

“Bot : Under 19 Cricket Tournament is underway at SS Stadium.Would you like me to book a ticket for you? ” Response for Intent fav_sport using $Sport_Name in Response field.

“User : No Thanks!” Intent : User_Feedback_No

“Bot : Thanks for contacting me. Hope I could help you choosing your suitable recreation activity for the weekend! ”Response for Intent : User_Feedback_No.

From the context flow above, we know that the Intent “fav_sport” should follow the intent “sport_near_me” and “User_Feedback_No” Intent must follow the “fav_sport” Intent to maintain a flow in conversation.

Based on this understanding we need to set

Input Context : sport_near_me

Output Context : fav_sport

For the Intent : sport_near_me.

[AND]

Input Context : fav_sport

Output Context : User_Feedback_No.

For intent : fav_sport

If we see the combined contexts of the conversation,we see that the Output Context of previous intent (sport_near_me) is same as the Input Context of the next intent (fav_sport) ,thus defining Dialogue Management.

As easy as it can be!

Dialogflow provides a GUI interface to make it easy even for non programmers to develop a chatbot and also gives it the cloud advantages any Google Cloud Project (GCP) would have.

Thus ends my first and brief attempt at explaining the major building blocks(ABC's) of Dialogflow,while there are more deeper learnings as we move in-depth into the ebbs and tides of Dialogflow.

Hopefully,it was explanatory and encouraging enough to try the amazing framework and delve immediately into it.

In my next post, I will attempt at giving a pictorial, illustrative overview of working on a Dialogflow Project.

Thanks for reading ! Please leave your thoughts and feedback in the comments section :)

--

--