Checkpoints
Create a BigQuery dataset
/ 10
Create a new table in BigQuery dataset
/ 10
Build an ML model to predicts time taken to resolve an issue
/ 20
Run the query to evaluate the ML model
/ 20
Create a Dialogflow Agent
/ 10
Import an IT Helpdesk Agent
/ 20
Create a Fulfillment that Integrates with BigQuery
/ 10
Integrating BigQuery ML with Dialogflow ES Chatbot
GSP431
Overview
Wouldn’t it be awesome to have an accurate estimate of how long it will take for tech support to resolve your issue? In this lab you will train a simple machine learning model for predicting helpdesk response time using BigQuery Machine Learning. You will then build a simple chatbot using Dialogflow, and learn how to integrate your trained BigQuery ML model with your helpdesk chatbot. The final solution will provide an estimate of response time to users at the moment a request is generated.
The exercises are ordered to reflect a common cloud developer experience:
-
Train a model using BigQuery Machine Learning
-
Deploy a simple Dialogflow application
-
Use an inline code editor within Dialogflow for deploying a Node.js fulfillment script that integrates BigQuery
-
Test your chatbot
What you'll learn
-
How to train a machine learning model using BigQuery ML
-
How to evaluate and improve a machine learning model using BigQuery ML
-
How to import intents & entities into a Dialogflow agent
-
How to implement custom Node.js fulfillment scripts
-
How to integrate BigQuery with Dialogflow
Prerequisites
-
Basic concepts and constructs of Dialogflow. Check out these Tutorials & Samples for an introductory Dialogflow tutorial that covers basic conversational design and fulfillment using a webhook.
-
Basic SQL and Node.js (or any coding language) knowledge.
Solution feedback/lab help
-
For more information on this solution or feedback on this lab, please reach out to gcct-ce-amer-specialists-ml@google.com.
Setup lab
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell
at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
-
Click Authorize.
-
Your output should now look like this:
Output:
-
(Optional) You can list the project ID with this command:
Output:
Example output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Add data for lab
-
Run the following commands to create a bucket in your current project, then add the data needed to build a table for this lab:
Task 1. Train a model using BigQuery machine learning
Open the BigQuery console
- In the Google Cloud Console, select Navigation menu > BigQuery.
The Welcome to BigQuery in the Cloud Console message box opens. This message box provides a link to the quickstart guide and the release notes.
- Click Done.
The BigQuery console opens.
- In the left pane, under Explorer section, click on the View actions icon next to your project ID, then select Create dataset.
-
For Dataset ID, type helpdesk.
-
Select us(multiple regions in United States) as the location.
-
Click Create dataset.
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
-
In the left menu, click the View actions icon next to helpdesk dataset you just created, then select Open in > New Tab.
-
Click Create table.
- Use the following parameters to create a new table leaving the defaults for all other fields:
Properties |
Values |
Create table from |
Google Cloud Storage |
Select file from GCS bucket |
|
File format |
CSV |
Table name |
issues |
Auto detect |
Check the check-box for Schema |
Advanced options > Header rows to skip |
1 |
YOUR BUCKET
with the bucket id through Navigation menu > Cloud Storage.
- Click Create table.
This will trigger a job that loads the source data into a new BigQuery table. It will take about 30 seconds for the job to complete, and you can view it by selecting Job History from the bottom.
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
-
In BigQuery click + Compose new query and add the following query:
- Click Run and examine the data.
In the next query, the data fields category
and resolutiontime
are used to build a machine learning model that predicts how long it will take to resolve an issue. The model type is a simple linear regression, and the trained model will be named predict_eta_v0 in the helpdesk dataset.
-
Clear the previous query from the editor and run this query, it takes about 1 minute to complete:
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
-
Clear the previous query from the editor and run the following query to evaluate the machine learning model you just created. The metrics generated by this query tell us how well the model is likely to perform.
Using the evaluation metrics, we can see that the model doesn't perform very well. When the r2\_score
and explained\_variance
metrics are close to 0, our algorithm is having difficulty distinguishing the signal in our data from the noise.
We are going to use a few more fields during training and see if there is an improvement: seniority, experience & type. The final trained model will be named predict_eta.
-
Clear the previous query from the editor, and run the following query:
-
Now, run the following query to evaluate the updated machine learning model you just created:
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
After adding the additional fields during training, we can see that our model has improved. When the metrics r2\_score
and explained\_variance
are close to 1, there is evidence to suggest that our model is capturing a strong linear relationship. We can also see that our error metrics are lower than before, which means our model will likely perform better.
-
Now we can execute a query to get a prediction of resolution time for a given scenario:
When seniority is 5, experience is 3-Advanced, category is Billing, and type is Request, our model is saying that the average response time is 3.74 days.
Task 2. Create a Dialogflow agent
In a new browser tab, create an Agent at Dialogflow.
-
Go to Dialogflow.com.
-
If required, click Sign-in with Google, then use the credentials you logged into this lab with.
-
Check Yes, I have read and accept the agreement, and then Accept the agreement.
-
In the left menu, click on Create Agent.
-
Name your agent and select other properties such as language and time zone.
-
Set Google Project to your Qwiklabs ID.
-
When you're ready, click Create.
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
Task 3. Import intents & entities for a simple helpdesk agent
To save time, instead of configuring an agent from scratch, you are going to import the intents and entities for an existing helpdesk agent.
Import an IT helpdesk agent
-
Download settings file from GitHub and save it to your local computer.
-
Still in the Diagflow console, click the hamburger icon in the top left to open the left panel.
-
Click the gear icon (
) next to your existing agent.
- Click on Export and Import tab from the list of settings.
- Select Import from zip.
- Select the
ml-helpdesk-agent.zip
file from your local computer. - Type
IMPORT
in the given textbox and click Import. - Click Done.
- Once the import completes, use the left panel to navigate to Intents.
- Examine the intents that were imported.
Submit Ticket is the main intent, which has the follow-up intents Submit Ticket - Email and Submit Ticket - Issue Category.
-
Submit Ticket - Email is used to collect a user's email address.
-
Submit Ticket - Issue Category is used to collect the issue description from the user and automatically infer a support category.
- Use the left panel to navigate to Entities and look at the @category entity.
This entity will be used to map a request description that the user provides to support category. The support category will be used for predicting response time.
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
Task 4. Use the Inline Editor to create a fulfillment that integrates with BigQuery
- Click on Fulfillment in the left panel and switch the Inline Editor toggle to Enabled.
-
Copy the following code and paste it in the index.js tab, replacing the existing content:
- While in this file update the BIGQUERY_CLIENT variable.
- Replace
your-project-id
with your Project ID.
Notice that your fulfillment script contains the ML.PREDICT function in Query statement. This is what is going to return a prediction of response time back to the client. Dialogflow will automatically categorize the ticket description and send the category to BigQuery ML for predicting issue response time.
-
Copy the following code and paste it in the package.json tab, replacing the existing content:
- Click the Deploy button. Wait until you see a message that the deployment was successful. This may take a few minutes.
Test completed task
To check your progress in this lab, click Check my progress below. A checkmark means you're on track.
Task 5. Enable webhook for fulfillment
-
Go back to Intents in the left panel.
-
Click the down arrow next to Submit Ticket to reveal its follow-up intents.
-
Click on the last follow-up intent Submit Ticket - Issue Category to open it for editing.
- Scroll to the bottom, in the Fulfillment section, verify that Enable webhook call for this intent is turned on.
Task 6. Test your chatbot
At this point, the Dialogflow should be set up.
-
Test it in the Try it now panel on the right by typing in the following conversation, one line at a time:
- Hi
- I would like to submit a ticket
- My email is student@qwiklabs.net
- I can't login
The output from #4 should look like:
Task 7. Understanding the BigQuery integration
Remember that your BigQuery ML model required other fields to return a prediction: seniority and experience. If this were a real world app, you could programmatically get the user's seniority & experience from a company database using the name or company ID they provide. For this example assume 5 as seniority and 3-Advanced as experience.
To extend this example further, you could also collect the seniority and experience information from the chatbot user by leveraging the Slot Filling functionality in Dialogflow. Read the article Webhook for slot filling to learn more about slot filling in Dialogflow.
Task 8. Test using a one-click integration
Dialogflow provides many types of integrations for your chatbot. Take a look now at a sample web user interface.
-
Click on Integrations in the Dialogflow left panel.
-
Click the Web Demo integration.
-
Click Enable .
- Click on the URL link to launch Web Demo:
Start using the chat interface by typing in the Ask something... section. If you are using a Chrome browser, click the microphone icon to ask the chatbot your questions. Start chatting with the chatbot using the following conversation:
-
Type "Hi" and hit Enter. The chatbot should respond as before.
-
Then enter/say "Submit ticket"
-
Provide the name "My email is student@qwiklabs.net"
-
Provide the ticket details of "My printer is broken"
Congratulations!
You have trained a machine learning model for predicting helpdesk response time using BigQuery Machine Learning.
Finish your quest
This self-paced lab is part of the BigQuery for Machine Learning and Applying BigQuery ML's Classification, Regression, and Demand Forecasting for Retail Applications quests. A quest is a series of related labs that form a learning path. Completing a quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.
Next steps/learn more:
- Check out the code samples at the Dialogflow Github page.
- Try some more BigQuery in the Exploring NCAA Data with BigQuery lab.
Manual last updated Aug 10, 2022
Lab last tested Aug 4, 2022
Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.