avatar khanh than

SOFTWARE ENGINEER

To keep tracking my skills & accomplisments

20 Dec 2024

● Dev Tools

Gcp Gemini Models In Bigquery

AMBITOUS: use AI to derive data insights and build a marketing strategy.

A. TASKS IN THIS POST:

  1. CRM Use case: Social Media Sentiment Analysis.
  2. Work with AI/ML Models in BigQuery.
  3. Analyze customers reviews with using Gemini in SQL.
  4. Analyze customers reviews with using Gemini in Python Notebooks.

Also, the customer is still “Coffee on Wheels”. As a modern food provider, it relies on social media to grow the customer base, gain insights from consumers practices, customize marketing campaign. However, the abundant and fast-paced nature of data from diverse sources make this process complex and time-intensive.

B. CHALLENGE: “Manage customer relationship in an efficient and scalable way”

Tactics: broke the challenge down into smaller and manageable subtasks, build a line of workflow.

Which tools we need:

C. BGML (BIGQUERY MACHINE LEARNING)

Model types and their applications:

BQML AI tasks

In terms of deployment, there 3 main types of models:

BQML model types based on hosting

This is all the types of built-in models in BigQuery. For simplicity, we should start with “Logistic regression” and “Linear regression”:

BQML built-in models

Create a model: it depends on type of model, creating it could differ slightly.

BQML create models

D. METHODS TO RUN A MODEL:

BQML method to run models

BQML methods to create models

BQML methods to use models

E. METHODS FOR MODEL EXPLANATION & MONITORING:

BQML explain a model

BQML monitor a model

BQML workflow for creating and using a model

F. ANALYZE CUSTOMER REVIEWS WITH SQL: (GEMINI IN ACTIONS)

STEPS TO SETUP:

Step 1. Establish connections (Explorer) & grant user permissions (IAM):

BQML step1 for customer review analysis

Step 2: Build multimodal dataset. Thanks to “Object Table”, BigQuery can understand various types of data (text, images, audios). “Object table” make unstructured data accessible in BigQuery via Embedding technology (vectorization).

BQML step2.1 upload text

BQML step2.2 object tables

BQML step2.3 connecting object tables

Step 3: create Gemini model (fine-tune a Gemini foundation model). If data includes unstructured data like images, audios, we need to specify “gemini_pro_vision” at step 3.2 like below:

BQML step3 select Gemini models

Step 4: Analyze customer reviews (learning?). Notice: Different requests will requires different data(dimensions or columns) and probably different models to analyze. This means, we must specify which columns to analyze, no need to choose all the tables because this can save time of analysis.

BQML step4 analyze data

BQML step4 method ML.GENERATE_TEXT details

Step 5: Generate a response and marketing campaign.

G. LAB SESSION: uncover insights with Gemini in Bigquery with SQL

Task 1. Create the cloud resource connection and grant IAM role by adding an extra role “Vertex AI role” linking to the connection via an ID.

Add cloud resources into BigQuery

Grant access with service-account-id

Task 2. Review images, and files, and grant IAM role to service account

images in bucket

grant access to the Storage Object Admin role

Task 3. Create the dataset, and tables in BigQuery:

create dataset

create table by loading with SQL

create an object table

Task 4. Create the Gemini models in BigQuery

Task 5. Prompt Gemini to analyze customer reviews for keywords and sentiment

Task 6. Respond to customer reviews

sentiments per social media sources

Task 7. Prompt Gemini to provide keywords and summaries for each image:

gemini_pro with image reviews

E. USING PYTHON TO ANALYZE CUSTOMER FEEDBACK.

SUGGESTION:

USAGE:

F. LAB SESSION:

Task 1. Create BigQuery Python notebook and connect to runtime

Task 2. Create the cloud resource connection and grant IAM role

Python setup in BigQuery

- Click "view action" next to the project-id in "Explorer", then select "refresh contents", look at the "external connections", choose th connection we have just created "us.gemini_conn", copy the "service_account_id",  "bqcx-302770467052-ny5q@gcp-sa-bigquery-condel.iam.gserviceaccount.com"

- Grant Vertex AI User role to the connection's service account: "IAM & Admin" => "Grant Access" => paste the service-id into "New principals" => select "Vertex AI User" role => save. *(This will add a new role "Vertex AI User" for current logined user)*.

Task 3. Review audio files, dataset, and grant IAM role to service account

review audio, images in cloud storage

Task 4. Create the dataset, and customer reviews table in BigQuery

Task 5. Create the Gemini Pro model in BigQuery

Task 6. Prompt Gemini to analyze customer reviews for keywords and sentiment

Task 7. Respond to customer reviews

Congratulations!

Share on: