NLP APIs

Let’s start from the pre-built APIs as one of the NLP development tools.
You’ll focus on the Dialogflow API and be introduced to the Natural Language API.

Dialogflow is a natural language understanding (NLU
) platform to design and integrate a conversational user interface …

into your mobile app, web application, device, bot, interactive voice response system, or similar use.
The Dialogflow API can be used to build a human-like agent to interact with and engage your customers.

Dialogflow can analyze multiple types of input from your customers, including text or audio inputs (like from a phone or voice recording).

It can also respond to your customers in a couple of ways, either through text or with synthetic speech.

Dialogflow provides two types of services in terms of the complexity of the problem and the size of the data:

Dialogflow ES —ES standing for Essentials— provides the standard agent type suitable for small and simple agents.

A Dialogflow agent is similar to a human call-center agent;
the only difference is that it’s a virtual (or machinery) agent.
You train the Dialogflow agent to handle conversation scenarios based on a large amount of data such as past conversations or an existing knowledge database, the same way you train a human call-center agent.

Dialogflow CX —CX stands for Customer experience— provides an advanced type suitable for large or complex agents.
Let’s compare these two services in more detail:

In terms of the target problems that we just mentioned, Dialogflow ES focuses on small and relatively simple problems;
Dialogflow CX targets larger and more complex problems.

Dialogflow ES allows one agent per project.
CX has different types of agents, such as sales agents, marketing agents, and customer service agents, and allows up to 100 agents per project.

For the building blocks of a virtual agent, Dialogflow ES uses a flat structure called intent. Dialogflow CX uses a graph structure of flows and pages.

When you create an agent on the Dialogflow Console, Dialogflow ES provides text forms;
Dialogflow CX gives you a visual representation that shows conversation paths.

And last, the primary benefit of using Dialogflow ES is to allow a small company to create an agent quickly and affordably.
Using Dialogflow CX instead of ES allows a large enterprise to create multiple virtual agents and better scale across multiple development teams.

With a brief idea of the differences between these two services, let’s focus on Dialogflow ES.

Dialogflow handles conversation in almost the same way as a human interaction.

Imagine a conversation: You ask Google Assistant

“can you send me a reminder?”
Google Assistant may respond …

“what do you want to be reminded about?”
You reply …

“Mom’s birthday is on May 1”.
Google Assistant asks a follow-up question:

“do you want to add it to Google Calendar?”
You reply …

“yes, please!

You might have noticed three major components involved in this conversation.

First is the topic, what is this conversation about?
What does a customer want?
So what do you think the goal of this conversation?

Right, a reminder.
The customer needs to set up a reminder.

In Dialogflow, we call the topic or the goal of a conversation as intent, and it indicates the intention from a customer, for example,

setting up a reminder,

asking for the weather,

or checking an account balance.

Based on the data from tons of conversations, Dialogflow built a database that includes the popular intents.

When an end user writes or says something, referred to as an end-user expression, Dialogflow matches the expression of an end user to the intent in the database.
Matching an intent is also known as intent matching or intent classification.

Two algorithms are used to match an intent: rule-based reasoning and machine learning matching.

Rule-based reasoning refers to the traditional decision tree.
For example, do you like dogs or cats? If cats, do you like long hair or short hair? If short hair, here are the three choices.

ML matching uses machine learning models to teach the machine from a large number of conversations in order to identify intents and matching keywords.
Dialogflow simultaneously attempts both algorithms and chooses the best result.

After identifying the intent, or the topic of a conversation, the next task is

identify the entities, or the specifics of the topic.
In this conversation, what would be the specifics of the reminder?

The reminder is about mom’s birthday, and the date is May the first.

You can think of entities as

related to the details, or the specifics, of an intent, such as

who,

what,

when, and

where.
For example,

this reminder needs to be set to a certain date,

and this reminder is about a birthday.


Dialogflow provides predefined system entities that can match many common types of data, such as dates, times, colors, and email addresses.

You can also create your own custom entities for matching custom data.
For example, you could define a vegetable entity that can match the types of vegetables available for purchase with a grocery store agent.

After the intent (or the topic of a conversation) and the entities (or the specifics of the topic) are identified,

the third component is the flow of the conversation.
For example, in this case, Google Assistant understands the details of the request

then asks a follow-up question if the end user wants to save the reminder on Google Calendar.

The conversation can continue to ask the users if they want to send flowers a week before the birthday.

Based on the answer, Google Assistant might continue to ask which flower shop to call

or end the conversation.

This conversation flow is based on

context.
Dialogflow contexts are similar to natural language context.

If a person says to you “they are orange”,

you need context to understand what “they” refers to.

Similarly, for Dialogflow to handle an end-user expression like that,

it needs to be provided with context to correctly understand an intent.



input and output contexts.
Input and output contexts are applied to intents.
They work together to control conversation flow:

Output contexts control active contexts.
When an intent is matched, any configured output contexts for that intent become active.

Input contexts control intent matching.
While contexts are active, Dialogflow is more likely to match intents with the currently active contexts.

Use the same reminder example, you asks to set up a reminder.

Dialogflow matches your expression to the SendReminder intent.

This intent has a Reminder output context and it becomes active.

Based on the Reminder output context, Google Assistant asks what the reminder is.

You responds with “Mom’s birthday on May 1”.

Dialogflow matches your expression to the AddtoCalendar intent,

which is also a match to the Reminder input context.

At the same time, the AddtoCalendar intent activates another output context called Calendar.

Based on the Calendar output context, Google Assistant asks whether you want to add the reminder to Google Calendar, and the conversation goes on.

To put all the pieces together, let’s look at how Dialogflow works.

Please note that, by default, your agent responds to a matched intent with a static response.

If you use one of the integration options,

you can provide a more dynamic response by using fulfillment,

meaning self-defined actions.

An end user starts a conversation by either typing or speaking.

Dialogflow matches the expression of the end user to an intent and extracts entities.

3/4/5.
If you have self-defined fulfillments, Dialogflow sends a message to the webhook service, queries the database, and gets a response.

Dialogflow sends the response to the end user.

The end user sees or hears the response.

In addition to the Dialogflow API, Google also provides the Natural Language API and the Healthcare Natural Language API.

Natural Language API uses powerful pre-trained models and allow developers to easily apply natural language understanding (NLU
) to their applications.

The key features include

sentiment analysis,

entity analysis,

entity sentiment analysis,

content classification,

and syntax analysis.

The Healthcare Natural Language API helps you gain real-time analysis of insights stored in unstructured medical text.

It lets you distill machine-readable medical insights from medical documents,

and AutoML Entity Extraction for Healthcare makes it simple to build custom knowledge extraction models for healthcare and life sciences apps and doesn’t require coding skills.

Try the demo yourself to better understand what the Natural Language API can do.

In addition to the pre-built APIs,

Google offers two other ways to develop an NLP project.