Cloud OnAir: Building Chatbots with Dialogflow

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[MUSIC PLAYING] WHITLEY TALMADGE: Welcome to Cloud OnAir, live webinars from Google Cloud. We're hosting webinars every Tuesday. My name is Whitley Talmadge. And today, I will be talking about Dialogflow. You can ask questions anytime on the platform. And we have Googlers on standby to answer them. Let's get started. I'm Whitley Talmadge. I am a customer engineer for Google Cloud. And I will be talking about how to build conversational experiences with Dialogflow using Google Cloud Platform today. So I'll be providing a brief overview of Dialogflow, Google's conversation engine, and a preview of our upcoming Coursera course called Building Conversational Experiences With Dialogflow. I'll demonstrate some of the basic features of Dialogflow in a few Google Cloud Platform products using the Qwiklabs platform. I'll go over the free training offers we have available as part of this session to get you hands-on with Dialogflow. And as I mentioned, we'll also be answering the questions that you submit. In this course, we take a look at how to build engaging conversational experiences using Dialogflow. We start off by using Dialogflow's building blocks to create an agent step by step by defining user intents, extracting potential entities, maintaining the context of the conversation, as well as being able to perform fulfillment actions outside of Dialogflow-- for example, storing data pieces from the conversation into a database. We have plenty of demos that walk you through each of these steps and then have you do the same through a series of hands-on labs, at the end of which you get to test out your chatbot. Next, we discuss a number of themes that are important when you want to take your chatbot to production, like being able to add basic authentication, customizing your chatbot's UI, deploying fulfillment code on scalable serverless architecture, and leveraging existing sources to automate parts of a agent building process. Towards the end of the course, we also talk about how to integrate your chatbot into other channels or surfaces, like the Google Assistant. And we also touch on a few other additional functionalities that can make your agents smarter and even more engaging. To achieve the learning objectives discussed, the Building Conversational Experiences With Dialogflow course consists of these five modules-- building conversational experiences with Dialogflow, defining intents and entities, maintaining context and taking action, taking your chatbot to production, and additional functionality. Conversational experience is the descriptive comprehensive name for a new class of solutions that include chatbots, conversational apps, and other similar terms. Dialogflow is a tool that can help you build smart conversational agents. Dialogflow is an end to end developer platform for building natural and rich conversational experiences. At its core, Dialogflow is a powerful natural language understanding engine to process and understand natural language input. In other words, it lets you easily achieve a conversational user experience by handling the natural language understanding for you. Using Dialogflow, you can build conversational experiences faster, engage end users more efficiently, and maximize reach across geographies and platforms. By leveraging these capabilities and what the developer provides as input training data, Dialogflow creates unique algorithms for each specific conversational agent under the hood, which continuously learns and is tweaked for you as more and more users engage with your agent. Some conversational agents exist for very specific, very simple use cases with few intents and minimal dependency on communicating with back end systems or knowledge bases, while some have multiple intents dealing with more complex domains and back ends. But typically, the workflow to get your conversational agent up and running maps out to these three phases-- design, what to build, develop, how to build, and deploy, how to deliver. Keep the style guide in mind as you design your agents responses. For the best user experience, you probably don't want your agent to sound too formal or robotic. For example, to make your agent more reminiscent of actual human conversation, you might have it say something like, does that sound good? Rather than something like-- if you feel you have reached this message in error. Creating your Dialogflow agent all starts with intents. Intents are the trunk of the dialog tree. They connect all of the branches. Intense determine where a conversation will go and what an agent should do. In communication, intents can be thought of as the root verbs in the conversation, such as wanting coffee translating to acquiring a beverage. Sometimes the intents are not explicit and instead are inferred from the entire composition of a phrase. You want to map your intents to the goal of your application. If you are a help desk application, then your intents might include opening and filing a ticket, updating a ticket, and closing a ticket. But your application may also need to access and update a user's account information, branch over to a live technician, and even pass along a quality assurance survey. Even affirmation, answering yes or no, is an intent. Intents evolve as your understanding of the user's needs evolves. And you may find yourself doubling or tripling your intents beyond your initial set of intents. To make the task of defining intents easier, some rules of thumb can be applied. First, identify the verbs in the dialogue people will have with your agent. Doing that will allow your agent to have its actions mapped to needs from the user. Another possible scenario is to identify where the application should branch logic. Here are some examples. Two mocha coffees, please. How many calories in a slice? I want a pizza. Or even, I really need some caffeine. Once you have chosen your intents, you need to train your agent to recognize them. This can be done with the use of training phrases. The training phrases for each intent should be representative of how users will say the intent. It is always a good idea to add variations to the grammatical construction of a request, such as passive versus active voices or questions versus statements. This will help represent the variety of ways a user might say an intent. When creating an intent, the more training phrases you can think of, the better. Later, we will discuss best practices for writing your training phrases. Entities help you get to the specifics of an interaction. In dialogue, the entities are the nouns or quantifiers found through the conversation, such as a person's name, the food in a review of a cruise, specific numbers or dates just to name a few. When you are creating an entity and you identify that the entity contains attributes that you need to map to, one way is to use composite entities. For our ordering pizza example, let's say that we want to create an intent for ordering pizza. A pizza could be of type regular or thin crust. Regular and thin crust, in this case, both are entries in an entity called pizza. System entities are pre-built entities provided by Dialogflow in order to facilitate handling the most popular concepts. Use one of the system entities to represent date and time, for example, or others such as addresses, currency, units, numbers, and many others. Contexts allow the agent to keep track of where the user is at in the conversation. In the context of Dialogflow, they are also a means for an application to store and access variables mentioned in the dialog. In this example of ordering pizza, if the sentence, actually, make that two hours, is said out of context, there is no way that the agent can know that the user is referring to the pickup time for the pizza order. The context in this conversation ensures that your Dialogflow agent knows that this request is related to the pizza ordering intent. For the pizza example, we built our agents step by step, starting with creating intents, followed by entities, and then contexts all done within the Dialogflow UI. Sometimes you may already have existing sources that you can extract entities from-- for instance, a call center playbook or an FAQ document. So we look at ways to leverage this data when building our agent. Sometimes all you need is a conversation interface to surface answers from the existing back end systems and capabilities. And so we look at deploying your back end code as a webhook on App Engine. We also look at how to customize your agent's UI, so that you can have your own branding. This is where we deploy a custom front end on App Engine. We also want to secure our webhook, so it only makes authenticated calls to the back end services. In our course, we start with a pizza ordering example where the back end is meant to store pizza orders. So you're mainly writing into the database. Then we move on to an HR manual example, where the back is a knowledge base where a query will look up for definitions and send it back to the user. So you're mainly reading from the database. So how do we build this knowledge base in the first place? We use an employee handbook, which is an HR manual document with topic keywords and definitions. So all we need to do is leverage that to build our knowledge base. In the hands-on lab, we use Cloud Datalab Notebooks to quickly run Python scripts to extract topics from the sample HR manual, then push them into a data store entity using the Cloud Datastore API. Next, we use Google's Natural Language API to form synonyms of these topics and add them to data store. Finally, we call the Dialogflow API to then populate your Dialogflow agent's entity list with these topics from the data store entity. The demo that follows will walk you through the steps covered so far. So I will pull up our demo screen. And I will maximize it. So I've already done some of the setup work for the demo that you would do in the lab. So I've already created a Datalab instance. This is actually a Compute Engine VM that hosts our Datalab Notebooks. So that's already up and running. So now, we can preview our Datalab Notebook. So I'll go to a Web Preview and change the port to 8081, Change And Preview. And I already cloned the Datalab Notebooks that we will need to use. So the first one that we're going to look at is process handbook. So I'll click that. And I'll do Clear All Cells to make sure that we have a fresh start. And then I can execute these cells one by one. So we'll make sure that we have the right version of Cloud Datastore. Then I'm going to make sure that that new version gets restarted. And now, we can look at our code for processing the handbook. So I'm going to run these cells one by one. So I'm importing the Datastore library. And then this is what will actually extract our topics and their definitions from this HR manual text file. So I'll run this block of code. And we can see that it's extracting the different headings, which are our topics, from that text file. Now, we're going to do basically the same thing with the Synonyms notebook. So this will just generate synonyms for all of the topics that we just extracted. So I'm opening the Process Synonyms notebook. I'm going to clear this one and do the same thing. So we'll make sure that we have the correct version of Datastore. And then reset the session to make sure that that takes effect. And now, we will import the NLTK library to generate our synonyms. And we'll import Datastore in this notebook as well. So this is going to look at the Datastore entities that we already have named under Topic. And it's going to use the NLTK library to generate synonyms for those entities. So we'll run this block of code. And there it goes generating synonyms for all of our topics. So this might take a second. And in Datalab, the way that we know that a cell is finished running is this side bar will turn from gray to blue. So that will let us know that it's completely finished with that block of code. So we'll have to wait for that. Looks like we're getting a lot of synonyms for these topics. It should be almost done, towards the end of the alphabet now. And our side bar there turned to blue, so that one's finished. So now, we will actually call the Google Natural Language API to evaluate the salience of each of these topic keywords to determine how relevant they are to the overall context. So we'll run each of these cells. And this is what will actually push all of the synonyms that we just generated into Datastore as well. So we can see this is going through the different topics and evaluating their salience in the overall context of the document. And so that cell is finished. So now, we can look at Datastore and see how those got pushed into our Datastore kinds. So I can go to a Datastore in the GCP console. And I see we should have two kinds. So we have Topic. This is all of the actual keywords that were extracted from the HR manual. And then we can switch over to synonym. These are all of the synonyms that were generated from those topics and also pushed to Datastore. So those are all set. So now, I can go to the Dialogflow console itself. And I've already created my agent. And when I created it, I imported an existing project. So I imported this same project that I have my Datastore topics and synonyms in, so that they're matched up and connected. And so now that that is set up, I can go back to my Datalab notebooks and look at this Dialogflow notebook. And I'm going to clear this one just to make sure it's fresh. And we will run this cell to install the correct version of Dialogflow. And then just for good measure, I'm going to do a restart to make sure that that gets incorporated into this notebook. And then we can pick back up here. So this Dialogflow notebook will actually take all of the entities that we created in Datastore and import them into our Dialogflow agent. OK. So that's done. So now, I can switch back to the Dialogflow console. And I can click on Entities and create one. So I'm going to name it Topic. I'll uncheck Define Synonyms, because we did that in our notebook. And I'll just enter a test value for now as a placeholder. So I'll hit Save, so that it creates that entity. Actually, I may need to run that Dialogflow notebook again, since I hadn't created the entity yet. So let me restart that. So we'll do clear. And I should be able to just pick up here and then run this one. OK. Let's check it now and see if that worked. So let me refresh here. And there they are. So that Dialogflow notebook actually took all of these entities that we had in Datastore and their synonyms and put them in our matching Topic entity in Dialogflow. So now, we're going to look at intents. So I can create a new intent. And I'm just going to name this one Topic as well. And I need to allow this intent to be able to be looked up. So I'm going to create an action under the intent. And I'm just going to call it lookup. And I'll name the parameter name Topic. And then I'm going to connect it to that Topic entity that we created, so it shows up there. And then the value will also be Topic. And for fulfillment, I am going to go ahead and enable fulfillment, because we're going to enable a webhook call for this intent. So all of that is set up. So I'll save that. And now, I'll add a couple of training phrases. So these are what we talked about in the presentation. We can start with just a few, so that the agent can kind of know how this topic entity will be called from the topic intent. So we can just give it one or two for now, so that it gets a quick idea. So I'm going to say, tell me about annual salary. And before I exit out of that, I'm going to highlight the term annual salary. So I just click and drag there. And I'm going to make sure it knows that this is calling my topic entity. So I'll hit Enter. And then I'll add one more. I'll do, what is discipline? Discipline is another term from our HR manual. And I'll do the same thing with that topic entity. So that should be good to start with. So I can hit Save. And you can see this dialog here popping up saying agent training started. So we'll wait for that to finish. It should give us a completed message when it's done. There we go, Agent Training Completed. OK. So now, I can switch back to my presentation, since we have all of that groundwork set up. OK. So this is what we just did. So now, we can talk about App Engine. App Engine is Google's fully managed serverless platform as a service product that allows you to build highly scalable applications. The underlying infrastructure is taking care of for you. With support for multiple programming languages, App Engine enables developers to focus on developing their applications without needing to worry about infrastructure concerns. You can deploy your webhook to App Engine by running the gcloud app deploy command. App Engine will find your app.yaml file for your service, read any additional parameters that you set, such as version number runtime and service name, and deploy your application. To run your app locally before pushing it to production, you can run the dev_appserver.py command, for example, to test your Python app from Cloud Shell. So in our HR chatbot example, the webhook is called by the Dialogflow agent's fulfillment component to get answers from Datastore once a topic entity is matched. The webhook code uses information from the HTTP post request sent by your agent to look up the keyword and match it with the topic entity in Cloud Datastore. The webhook will then return a response back to the user, which contains the definition of the keyword passed in the request. So we'll go back to the demos and take a quick look at the webhook code. So I will pull back up my Demo tab. OK. And so now the notebook that will run is our webhook notebook. So I can open this one up. And we'll clear it just to be safe. And now we can run these cells one by one. OK. And then this is what we actually need to create a webhook for our fulfillment component of our Dialogflow agent. So one way to do this is, from this Datalab notebook, we can click this dropdown next to notebook. And we could do something like convert to Python. So that would convert everything in this Datalab notebook into an actual executable Python script. And then we could deploy that to App Engine. So that's exactly what we did in this project. So if I open a new tab in my Cloud Shell, and I can look for that Python script, OK, so I called it main.py. Actually, I can look at this from the Code Editor, because that will be a better way to see it. So I'm opening the Code Editor from Cloud Shell. And I have my folder I already created. So I'll go into webhook. And we can look at the main.py file. So this is the exact same thing that was in our Datalab notebook we just saw, but it's just created as a Python script. So this is how we can deploy this Python app into App Engine. So let me go to App Engine, so we can see the dashboard. And we need to initialize App Engine really quick. Let me do select an existing project. So I'll choose this one, Confirm Project, Next. So we don't need to do this tutorial. So I'm going to cancel out of it. But that should have initialized our App Engine setup. So now we can actually deploy that webhook onto App Engine. So let me take a look at the app.yaml. This is what will deploy this service into App Engine. So for now, I'm going to remove this service name, because our first service on App Engine needs to be the default. So we will take out that named service name for now. And let me make sure I'm still in the right directory. OK. So now I can do gcloud app deploy. So this is going to deploy all of our webhook code we just saw on App Engine-- shouldn't take too long. So App Engine is automatically taking care of a lot of stuff for us, like updating the service and setting traffic split for the service automatically. So now it is finished deploying. So I'll switch back to the App Engine Dashboard. Let me click on Services. I'll do a refresh and see if that helps. OK. So now we've got it. So at this point, we don't have a UI for our service. So when we click this, we won't see anything yet. It's just going to say not found. But we can grab this URL. And we can switch back over to the Dialogflow console. And we'll go back to Fulfillment. So up here, I'm going to enable webhook. And then I'm going to paste that URL in and add webhook at the end. And then we had already set the user name and password for basic auth in that webhook code. So I will enter that here. And then I can scroll down and hit Save. So now we should have a deployed webhook that's hosted on App Engine that our Dialogflow agent is calling. So let me try. Tell me about annual salary, which was one of our training phrases. And we see the default response. So this is the response that is from that HR manual text file that we extracted all of the topics and definitions out of into Datastore and then pushed them into our Dialogflow agent. And it is calling a hosted webhook on App Engine that is secured with basic auth on the back end. So that is the idea. Let me switch back to our presentation. OK. So a quick recap of some things we just did-- we added HTTP basic authentication to our webhook to prevent unauthorized access. And so this ensures that unauthorized callers can't call our webhook. And in the webhook code, we implemented flask security framework for a HTTP basic authentication. So this requires_auth method requires authentication to access our app. And we had a check_auth method which validates the submitted user name and password. So these user name and password values in this code snippet are what we used in the Dialogflow console. And then the authenticate method sends a 401 response if authentication fails. And so we also had to add this requires_auth decorator to our handle method to ensure that the method validates those authorization credentials. So besides having a customized front end, Dialogflow agents can also be enabled in multiple channels in surfaces from text to voice to phone. So beyond the web chat core feature, which we saw when we tested it out in the console, you can use the built-in feature for deploying your agent onto any Google Assistant enabled device, such as the Assistant Mobile app or a Google Home device. So you can also easily integrate your Dialogflow agent into other third party apps, like Facebook Messenger, Twitter, and Slack. And there are also import and export capabilities for easily importing your Dialogflow agent into Amazon Alexa or Microsoft Cortana compatible files. So while Dialogflow gives you several surface options from the Dialogflow console web interface to Google Assistant to Google Home devices, these all rely on the actions SDK for creating the actions that form your agent. This allows you to seamlessly move between surfaces for the same agent no matter which platform or functionality you need. So a quick recap of our course and some things that we just previewed-- conversation is the new UI. And it's very quickly changing the way that users communicate with businesses, employers, and others. We looked at some of the challenges when creating conversational agents that can handle natural language input and discussed how Dialogflow can address some of these concerns. And through the life of a conversation, we looked at some of the essential elements that you want your chatbot to have, like intents, entities, context, and fulfillment. You also learned how to define intents and entities using the Dialogflow UI. And in the HR chatbot example, we leveraged an existing data source to extract entities from your Dialogflow agent. And we learned that being able to maintain context is important for the agent to be able to control the flow and minimize repetition and improve overall satisfaction. And with fulfillment, you can add functionality, like connecting to back end systems. We then saw the coming together of GCP products to productionize your agent, like deploying your webhook on App Engine so it can scale, building a knowledge base in Cloud Datastore by leveraging the HR manual, and using the Natural Language API to generate synonyms and adding security. And then towards the end, we talked about how you can easily integrate your agent into other surfaces, like the Google Assistant, and demonstrated some of the newer additional features. And one last thing before we go to Q&A, remember to claim your free month of Google Cloud Specializations on Coursera for any of our specialization courses, including data engineering, architecting, and developing applications, and a lot more by going to this link or scanning this QR code. And look for our full length Building Conversational Experiences With Dialogflow course launching on Coursera soon. So we are ready for Q&A. Stay tuned for live Q&A. We'll be back in less than a minute. OK. So we are back with some questions from the audience for Dialogflow and everything that we just talked about. So let's look at the first question. We use .NET or any other development platform. Can I use Dialogflow from our environment? So the answer to that one is yes. So the example that I showed and that we talk about in the Coursera course is all using Python, but that is definitely not the only option. There are a ton of different Dialogflow fulfillment libraries that are available. And a lot of them are already written and ready to use on Dialogflow's GitHub page. So we have .NET, Node.js, Java, Python, C#, and Ruby. I think those are the ones. I don't believe I've left any out. But the answer is yes, definitely. And then, of course, another option would also be just to use the REST API calls to use the Dialogflow interface. OK. So second question, we have developed our own specialized speech to text or use another third party's. Can I use it with Dialogflow? So the answer to that one is also yes. Because of that REST API integration, you can integrate your own speech to text API with Dialogflow speech to text API. So that would definitely work. So I guess we didn't get any other questions. So I will go ahead and close this out. So I think that's it for our Dialogflow course. Stay tuned for the next session, CETV Machine Learning 101, the What, Why, and How of ML. Thank you. [MUSIC PLAYING]
Info
Channel: Google Cloud Tech
Views: 17,592
Rating: 4.8723402 out of 5
Keywords: Cloud OnAir, Dialogflow
Id: 9MB_wqpmDiA
Channel Id: undefined
Length: 37min 19sec (2239 seconds)
Published: Tue Dec 18 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.