Text of docs.cloud.google.com › bigquery › docs › semantic-analysis as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Perform semantic analysis with managed AI functions | BigQuery | Google Cloud Documentation

Skip to main content Console English Deutsch Español Español – América Latina Français Indonesia Italiano Português Português – Brasil עברית 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in BigQuery Start free Home Documentation Data analytics BigQuery Guides Perform semantic analysis with managed AI functions Stay organized with collections Save and categorize content based on your preferences.

This tutorial shows you how to use the AI.IF , AI.SCORE , and AI.CLASSIFY functions to perform semantic analysis on customer feedback. Objectives Create a table that contains sample customer reviews for a device. Categorize overall sentiment of each review. Rate user sentiment based on how favorable a review is towards price, customer service, or quality. Categorize and filter reviews by their main emotion or topic. Identify semantically similar reviews.

Create reusable prompt user-defined functions (UDFs). Costs This tutorial uses billable components of Google Cloud, including the following: BigQuery BigQuery ML For more information on BigQuery costs, see the BigQuery pricing page. For more information on BigQuery ML costs, see BigQuery ML pricing . Before you begin Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios.

New customers also get $300 in free credits to run, test, and deploy workloads. In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on. Create a project : To create a project, you need the Project Creator role ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission.

Learn how to grant roles . Go to project selector If you're using an existing project for this guide, verify that you have the permissions required to complete this guide . If you created a new project, then you already have the required permissions. In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.

Create a project : To create a project, you need the Project Creator role ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission. Learn how to grant roles . Go to project selector If you're using an existing project for this guide, verify that you have the permissions required to complete this guide . If you created a new project, then you already have the required permissions.

Enable the BigQuery API, if it is not already enabled. Roles required to enable APIs To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role ( roles/owner ). Otherwise, you can get this permission through the Service Usage Admin role ( roles/serviceusage.serviceUsageAdmin ). Learn how to grant roles . Enable the API For new projects, the BigQuery API is automatically enabled.

Optional: Enable billing for the project. If you don't want to enable billing or provide a credit card, the steps in this document still work. BigQuery provides you a sandbox to perform the steps. For more information, see Enable the BigQuery sandbox . Required roles To get the permissions that you need to use AI functions, ask your administrator to grant you the following IAM roles on the project: Run query jobs and load jobs: BigQuery Job User ( roles/bigquery.jobUser ) Create a dataset, create a table, load data into a table, and query a table: BigQuery Data Editor ( roles/bigquery.dataEditor ) For more information about granting roles, see Manage access to projects, folders, and organizations .

You might also be able to get the required permissions through custom roles or other predefined roles . Create sample data To create a dataset called my_dataset for this tutorial, run the following query. CREATE SCHEMA my_dataset OPTIONS ( location = ' LOCATION ' ); Next, create a table called customer_feedback that contains sample customer reviews for a device: CREATE TABLE my_dataset . customer_feedback AS ( SELECT * FROM UNNEST ( [ STRUCT<review_id INT64 , review_text STRING > ( 1 , "The battery life is incredible, and the screen is gorgeous!

Best phone I've ever had. Totally worth the price." ), ( 2 , "Customer support was a nightmare. It took three weeks for my order to arrive, and when it did, the box was damaged. Very frustrating!" ), ( 3 , "The product does exactly what it says on the box. No complaints, but not exciting either." ), ( 4 , "I'm so happy with this purchase! It arrived early and exceeded all my expectations. The quality is top-notch, although the setup was a bit tricky." ), ( 5 , "The price is a bit too high for what you get.

The material feels cheap and I'm worried it won't last. Service was okay." ), ( 6 , "Absolutely furious! The item arrived broken, and getting a refund is proving impossible. I will never buy from them again." ), ( 7 , "This new feature for account access is confusing. I can't find where to update my profile. Please fix this bug!" ), ( 8 , "The shipping was delayed, but the support team was very helpful and kept me informed.

The product itself is great, especially for the price." ) ] ) ); Categorize overall sentiment It can be helpful to extract the overall sentiment expressed in text to support use cases such as the following: Gauge customer satisfaction from reviews. Monitor brand perception on social media. Prioritize support tickets based on how upset users are. The following query shows how to use the AI.CLASSIFY function to classify reviews from the customer_feedback table as positive , negative , or neutral : SELECT review_id , review_text , AI .

CLASSIFY ( review_text , categories = > [ 'positive' , 'negative' , 'neutral' ] ) AS sentiment FROM my_dataset . customer_feedback ; The result looks similar to the following: +-----------+------------------------------------------+-----------+ | review_id | review_text | sentiment | +-----------+------------------------------------------+-----------+ | 7 | This new feature for account access is | negative | | | confusing.

I can't find where to update | | | | my profile. Please fix this bug! | | +-----------+------------------------------------------+-----------+ | 4 | "I'm so happy with this purchase! It | positive | | | arrived early and exceeded all my | | | | expectations. The quality is top-notch, | | | | although the setup was a bit tricky." | | +-----------+------------------------------------------+-----------+ | 2 | "Customer support was a nightmare.

It | negative | | | took three weeks for my order to | | | | arrive, and when it did, the box was | | | | damaged. Very frustrating!" | | +-----------+------------------------------------------+-----------+ | 1 | "The battery life is incredible, and | positive | | | the screen is gorgeous! Best phone I've | | | | ever had. Totally worth the price." | | +-----------+------------------------------------------+-----------+ | 8 | "The shipping was delayed, but the | positive | | | support team was very helpful and kept | | | | me informed.

The product itself is | | | | great, especially for the price." | | +-----------+------------------------------------------+-----------+ | 5 | The price is a bit too high for what | negative | | | you get. The material feels cheap and | | | | I'm worried it won't last. Service was | | | | okay. | | +-----------+------------------------------------------+-----------+ | 3 | "The product does exactly what it says | neutral | | | on the box.

No complaints, but not | | | | exciting either." |

The rest of this page is on the live site.