
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create the cloud resource connection and grant IAM role
/ 10
Grant IAM Storage Object Admin role to the connection's service account
/ 10
Create the dataset and object table for the review images
/ 15
Create the Gemini models in BigQuery
/ 10
Prompt Gemini to analyze customer reviews for keywords and sentiment
/ 25
Respond to customer reviews
/ 20
Prompt Gemini to provide keywords and summaries for each image
/ 10
In this lab you learn how to use BigQuery Machine Learning with remote models (Gemini Pro) in SQL to extract keywords, assess customer sentiment in customer reviews, and respond to customer reviews with zero-shot and few-shot prompts.
BigQuery is a fully managed, AI-ready data analytics platform that helps you maximize value from your data and is designed to be multi-engine, multi-format, and multi-cloud. One of its key features is BigQuery Machine Learning, which lets you create and run machine learning (ML) models by using SQL queries or with Colab Enterprise notebooks.
Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro, Gemini Pro Vision and Gemini Flash models.
Additionally, you'll use the Gemini Pro Vision model to generate summaries and extract relevant keywords from customer review images.
In this lab, you learn how to:
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 are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
In this task you create a Cloud resource connection in BigQuery, so you can work with Gemini Pro and Gemini Pro Vision models. You will also grant the cloud resource connection's service account IAM permissions, through a role, to enable it access the Vertex AI services.
In the Google Cloud console, on the Navigation menu, click BigQuery.
Click DONE on the Welcome pop-up.
To create a connection, click + ADD, and then click Connections to external data sources.
In the Connection type list, select Vertex AI remote models, remote functions and BigLake (Cloud Resource).
In the Connection ID field, enter gemini_conn for your connection.
For Location type select Multi-region and then, from dropdown select US multi-region.
Use the defaults for the other settings.
Click Create connection.
Click GO TO CONNECTION.
In the Connection info pane, copy the service account ID to a text file for use in the next task. You will also see that the connection is added under the External Connections section of your project in the BigQuery Explorer.
In the console, on the Navigation menu, click IAM & Admin.
Click Grant Access.
In the New principals field, enter the service account ID that you copied earlier.
In the Select a role field, enter Vertex AI, and then select Vertex AI User role.
Click Save.
The result is the service account now includes the Vertex AI User role.
Click Check my progress to verify the objective.
In this task, you review the dataset and the image files, then you grant IAM permissions to the cloud resource connection's service account.
Before you dive into this task to grant permissions to the resource connection service account, review the dataset and the image files.
In the console, select the Navigation menu (), and then select Cloud Storage.
Click on Buckets and Select the
The bucket contains the gsp1246
folder, open the folder. You will see two items in it:
images
folder contains all image files you will analyze. Feel free to access the images folder and review the image files.customer_reviews.csv
file is the dataset that contains the text based customer reviews.Granting IAM permissions to the resource connection's service account before you start working in BigQuery will ensure you do not encounter access denied errors when running queries.
Return to the root of the bucket.
Click PERMISSIONS.
Click GRANT ACCESS.
In the New principals field, enter the service account ID you copied earlier.
In the Select a role field, enter Storage Object, and then select Storage Object Admin role.
Click Save.
The result is the service account now includes the Storage Object Admin role.
Click Check my progress to verify the objective.
In this task, you create a dataset for the project, the table for customer reviews, and the image object table.
In the console, select the Navigation menu (), and then select BigQuery.
In the Explorer panel, for ), and then select Create dataset.
You create a dataset to store database objects, including tables and models.
In the Create dataset pane, enter the following information:
Field | Value |
---|---|
Dataset ID | gemini_demo |
Location type | select Multi-region |
Multi-region | select US |
Leave the other fields at their defaults.
Click Create Dataset.
The result is the gemini_demo
dataset is created and listed underneath your project in the BigQuery Explorer.
To create the customer reviews table you will use a SQL query.
Click the + to Create a new SQL Query.
In the query editor, paste the query below.
This query uses the LOAD DATA statement to load the customer_reviews.csv
file from Cloud Storage to a BigQuery table with the given column names and data types.
Click Run.
The result is the query is processed and the customer_reviews
table created with the customer_review_id
, customer_id
, location_id
, review_datetime
, review_text
, social_media_source
, and social_media_handle
for each review in the dataset.
In the Explorer, click on the customer_reviews table and review the schema and details. Feel free to query the table to review records.
To create the object table you will use a SQL Query.
Click the + to Create new SQL query.
In the query editor, paste the query below.
Run the Query.
The result is the review_images
object table is added to the gemini_demo
dataset and loaded with the uri (the cloud storage location) of each audio review in the sample dataset.
In the Explorer, click on the review_images table and review the schema and details. Feel free to query the table to review specific records.
Click Check my progress to verify the objective.
Now that the tables are created, you can begin to work with them. In this task, you create models for Gemini Pro and Gemini Pro Vision in BigQuery.
Click the + to Create a new SQL Query.
In the query editor, paste the query below and run it.
The result is the gemini_pro
model is created and you see it added to the gemini_demo
dataset, in the models section.
In the Explorer, click on the gemini_pro model and review the details and schema.
Click the + to Create a new SQL Query.
In the query editor, paste the query below and run it.
The result is the gemini_pro_vision
model is created and you see it added to the gemini_demo
dataset, in the models section.
In the Explorer, click on the gemini_pro_vision model and review the details and schema.
Click Check my progress to verify the objective.
In this task, you will use Gemini Pro model to analyze each customer review for keywords and sentiment, either positive or negative.
Click the + to Create a new SQL Query.
In the query editor, paste the query below, and run it.
This query takes customer reviews from the customer_reviews
table, constructs prompts for the gemini_pro
model to identify keywords within each review. The results are then stored in a new table customer_reviews_keywords
.
Please wait. The model takes approximately 30 seconds to process the customer review records.
When the model is finished, the result is the customer_reviews_keywords
table is created.
In the Explorer, click on the customer_reviews_keywords table and review the schema and details.
Click the + to Create a new SQL Query.
In the query editor, paste and run the query below.
The result is rows are displayed from the customer_reviews_keywords
table with the ml_generate_text_llm_result
column containing the keywords analysis, social_media_source
, review_text
, customer_id
, location_id
and review_datetime
columns included.
Click the + to Create a new SQL Query.
In the query editor, paste the query below, and run it.
This query takes customer reviews from the customer_reviews
table, constructs prompts for the gemini_pro
model to classify the sentiment of each review. The results are then stored in a new table customer_reviews_analysis
, so that you may use it later for further analysis.
Plese wait. The model takes approximately 20 seconds to process the customer review records.
When the model is finished, the result is the customer_reviews_analysis
table is created.
In the Explorer, click on the customer_reviews_analysis table and review the schema and details.
Click the + to Create a new SQL Query.
In the query editor, paste and run the query below.
The result is rows customer_reviews_analysis
table with the ml_generate_text_llm_result
column containing the sentiment analysis, with the social_media_source
, review_text
, customer_id
, location_id
and review_datetime
columns included.
Take a look at some of the records. You may notice some of the results for positive and negative may not be formatted correctly, with extraneous characters like periods, or extra space. You can sanitize the records by using the view below.
Click the + to Create a new SQL Query.
In the query editor, paste and run the query below.
The query creates the view, cleaned_data_view
and includes the sentiment results, the review text, the customer id and the location id. It then takes the sentiment result (positive or negative) and ensures that all letters are made lower case, and extreanous characters like extra spaces or periods are removed. The resulting view will make it easier to do further analysis in later steps within this lab.
You can query the view with the query below, to see the rows created.
This query is designed to fetch all data from the cleaned_data_view
view and then arrange it in ascending order based on the date and time of the reviews.
You can use BigQuery to create a bar chart report of the counts of positive and negative reviews. Start with the query below.
The result is counts for positive and negative reviews are displayed.
To create the bar chart report of these counts, click CHART in the Query results section of BigQuery. BigQuery will automatically set the chart configuration, with chart type of Bar, and the sentiment column (the predicted sentitment as positive or negative) and the bar will display the count.
You can use BigQuery to list the count of positive and negative reviews per social media source using the query below.
Click Check my progress to verify the objective.
You can also use Gemini Pro to respond to customer reviews. In this task you will learn how to create a marketing response using zero-shot and a customer service response using few-shot, against specific reviews in the customer_reviews
table.
The customer with customer_id
5576 responded with:
This is clearly a positive review, how can you use Gemini Pro to respond to this customer and incentivize them for the positive review?
You can use Gemini Pro with these queries to accomplish this. In the query editor, paste the query below and run it.
This query is designed to analyze customer reviews from the customer_reviews
table, specifically those from customer ID 5576. When you run the query, it uses Gemini Pro to generate marketing suggestions based on the review text and then stores the results in a new table called customer_reviews_marketing.
This table will contain the original review data along with the generated marketing suggestions, allowing you to easily analyze and act upon them.
You can view the details of the customer_reviews_marketing
table by running the SQL query below.
Notice that the ml_generate_text_llm_result
column contains the response.
You can make this easier to read, and take action on the response by using the SQL query below:
You can view the details of the table by running the SQL query below.
Notice the marketing
column. An appliction can be written to take the response in the marketing
column and attach the 10 percent off coupon file as a notifcation for the customer's account in the data beans app or an email can be generated with these to the customer as well.
The customer with customer_id
8844 responded with:
This is clearly a negative review, how can you use Gemini Pro to respond to this customer and notify the coffee shop of their experience, in an effort to take action?
You can use Gemini Pro with these queries to accomplish this. In the query editor, paste the query below and run it.
This query is designed to automate customer service responses by using Gemini Pro to analyze customer reviews and generate appropriate responses and action plans. It's a powerful example of how Google Cloud can be used to enhance customer service and improve business operations. When the query is run, the result is the customer_reviews_cs_response
table is created.
You can view the details of the table by running the SQL query below.
Notice that the ml_generate_text_llm_result
column contains the response and the actions as two keys.
You can make this easier to read, by using the SQL query below two separate the response and the actions into two columns in a new table called customer_reviews_cs_response_formatted
:
You can view the details of the table by running the SQL query below.
Notice the response and actions fields are now created. You can build separate applications to respond to the customer, and to the location so that it can take actions to improve and the customer will be notified their feedback was received.
Click Check my progress to verify the objective.
In this task, you will use Gemini (the Gemini Pro and Vision models you created) to analyze images generating keywords and summaries.
Click the + to Create a new SQL Query.
In the query editor, paste the query below, and run it.
Please wait. The model takes approximately 1 minute to complete.
When the model has finished processing the image, the result is the review_images_results
table is created.
In the Explorer, click on the review_image_results table and review the schema and details.
Click the + to Create a new SQL Query.
In the query editor, paste and run the query below.
The result is rows for each review image are displayed with the uri (the CloudStorage location of the review image) and a JSON result including the summary and keywords the Gemini Pro Vision model.
You can retrieve these results in a more human readable way, by using the next query.
Click the + to Create a new SQL Query.
In the query editor, paste and run the query below.
The result is the review_images_results_formatted
table is created.
You can query the table with the query below, to see the rows created.
Notice how the uri column results remain the same, but the JSON is now converted to the summary and keywords columns for each row.
Click Check my progress to verify the objective.
You successfully created cloud resource connection in BigQuery. You also created created a dataset, tables, and models to prompt Gemini to analyze sentimenet on customer reviews, with a report of positive and negative review counts. You then used zero-shot and few-shot prompts with Gemini to respond to these reviews. Finally, you used the Gemini Pro Vision model to analyze images and generate summaries and keywords.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated: February 13, 2025
Lab Last Tested: February 13, 2025
Copyright 2025 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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one