הסבר על הפונקציה ML.UNDERSTAND_TEXT

הפונקציה ML.UNDERSTAND_TEXT מאפשרת לנתח טקסט לא מובנה ישירות ב-BigQuery. אתם יכולים להעריך את סנטימנט הלקוחות, לזהות ישויות עיקריות ולבדוק את תחביר הטקסט בלי ליצור צינורות נפרדים לעיבוד נתונים. הפונקציה משתמשת במודל מרוחק של BigQuery ML כדי לחבר את BigQuery ל-Cloud Natural Language API.

במדריך הזה תיצרו מודל מרוחק ב-Cloud Natural Language API ותבצעו ניתוח סנטימנטים וניתוח ישויות במערך נתונים ציבורי של ביקורות על סרטים.

מטרות

  • יוצרים מערך נתונים וקישור למשאבים ב-Cloud.
  • נותנים הרשאות לחשבון השירות של החיבור.
  • יוצרים מודל מרוחק של BigQuery ML.
  • לנתח את הסנטימנט בטקסט ולחלץ ישויות באמצעות הפונקציה ML.UNDERSTAND_TEXT.

עלויות

במסמך הזה משתמשים ברכיבים הבאים של Google Cloud, והשימוש בהם כרוך בתשלום:

  • BigQuery: You incur costs for the data that you process in BigQuery.
  • Cloud Natural Language API: You incur costs for calls to the Natural Language API service that's represented by the remote model.

בעזרת מחשבון העלויות אתם יכולים להעריך את העלויות בהתאם לשימוש הצפוי.

משתמשים חדשים של Google Cloud ? יכול להיות שאתם זכאים לתקופת ניסיון בחינם.

למידע נוסף, קראו את המאמרים התמחור ב-BigQuery והתמחור ב-Natural Language API.

לפני שמתחילים

המסוף

  1. 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

  2. Verify that billing is enabled for your Google Cloud project.

  3. Enable the BigQuery, BigQuery Connection API, and Cloud Natural Language API APIs, if any are 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 APIs

  4. מוודאים שיש לכם את התפקידים הבאים בפרויקט: אדמין ב-BigQuery, אדמין IAM בפרויקט.

    בדיקת התפקידים

    1. נכנסים לדף IAM במסוף Google Cloud .

      כניסה לדף IAM
    2. בוחרים את הפרויקט.
    3. בעמודה Principal, מחפשים את כל השורות שמזהות אתכם או קבוצה שאתם חברים בה. כדי לברר לאילו קבוצות אתם שייכים, פנו לאדמין.

    4. בכל השורות שבהן אתם מופיעים, בודקים בעמודה Role אם רשימת התפקידים כוללת את התפקידים הנדרשים.

    מתן התפקידים

    1. נכנסים לדף IAM במסוף Google Cloud .

      כניסה לדף IAM
    2. בוחרים את הפרויקט.
    3. לוחצים על Grant access.
    4. בשדה New principals, מזינים את מזהה המשתמש. ‫ בדרך כלל זה המזהה של משתמש במאגר זהויות של כוח עבודה. למידע נוסף, קראו את המאמר ייצוג המשתמשים במאגרי כוח עבודה בכללי מדיניות IAM או פנו לאדמין שלכם.

    5. לוחצים על Select a role ומחפשים את התפקיד.
    6. כדי לתת עוד תפקידים, לוחצים על Add another role ומוסיפים אותם.
    7. לוחצים על Save.

gcloud

  1. התקינו את ה-CLI של Google Cloud.

  2. הגדירו שה-CLI של gcloud ישתמש בזהות המאוחדת שלכם.

    איך נכנסים ל-CLI של gcloud באמצעות הזהות המאוחדת?

  3. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  4. יוצרים או בוחרים פרויקט ב- Google Cloud .

    התפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • בחירת פרויקט: כדי לבחור פרויקט לא נדרש תפקיד IAM ספציפי – אתם יכולים לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד "יצירת פרויקטים" (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים?
    • יוצרים פרויקט ב- Google Cloud :

      gcloud projects create PROJECT_ID

      מחליפים את PROJECT_ID בשם של הפרויקט ב- Google Cloud שאתם יוצרים.

    • בוחרים את הפרויקט שיצרתם ב- Google Cloud :

      gcloud config set project PROJECT_ID

      מחליפים את PROJECT_ID בשם הפרויקט ב- Google Cloud .

  5. מוודאים שהחיוב מופעל בפרויקט ב- Google Cloud .

  6. מפעילים את BigQuery, את BigQuery Connection API ואת Cloud Natural Language API, אם הם עדיין לא מופעלים:

    התפקידים שנדרשים כדי להפעיל ממשקי API

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד "בעלים" (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד "אדמין בממשק 'שימוש בשירות'" (roles/serviceusage.serviceUsageAdmin). כך מקצים תפקידים.

    gcloud services enable bigquery.googleapis.com bigqueryconnection.googleapis.com language.googleapis.com
  7. נותנים תפקידים לחשבון המשתמש. מריצים את הפקודה הבאה לכל אחד מהתפקידים הבאים ב-IAM: roles/bigquery.admin, roles/resourcemanager.projectIamAdmin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

    מחליפים את מה שכתוב בשדות הבאים:

יצירת קבוצת נתונים

כדי ליצור מערך נתונים ב-BigQuery, בוחרים אחת מהאפשרויות הבאות:

המסוף

  1. נכנסים לדף BigQuery במסוף Google Cloud .

    כניסה ל-BigQuery

  2. בחלונית הימנית, לוחצים על Explorer:

    כפתור מודגש לחלונית Explorer.

    אם החלונית הימנית לא מוצגת, לוחצים על Expand left pane כדי לפתוח אותה.

  3. ב-Explorer, מרחיבים את הפרויקט ולוחצים על Datasets.

  4. בדף Datasets, לוחצים על Create dataset.

  5. בחלונית Create dataset:

    • בשדה Dataset ID, מזינים bqml_tutorial.

    • בקטע Data location (מיקום הנתונים), בוחרים באפשרות US (ארה"ב).

    משאירים את שאר הגדרות ברירת המחדל כמו שהן.

  6. לוחצים על Create dataset.

BQ

כדי ליצור קבוצת נתונים חדשה, משתמשים בפקודה bq mk --dataset.

  1. יוצרים מערך נתונים בשם bqml_tutorial ומגדירים את מיקום הנתונים ל-US:

    bq mk --dataset \
      --location=US \
      --description "BigQuery ML tutorial dataset." \
      bqml_tutorial
  2. מוודאים שמערך הנתונים נוצר:

    bq ls

API

מפעילים את השיטה datasets.insert עם משאב של מערך נתונים מוגדר:

{
  "datasetReference": {
     "datasetId": "bqml_tutorial"
  }
}

יצירת חיבור

יוצרים קישור למשאבים ב-Cloud באזור US שבו יצרתם את מערך הנתונים. ואז מקבלים את חשבון השירות של החיבור.

בוחרים באחת מהאפשרויות הבאות:

המסוף

  1. נכנסים לדף BigQuery.

    כניסה ל-BigQuery

  2. בחלונית הימנית, לוחצים על Explorer:

    כפתור מודגש לחלונית Explorer.

    אם החלונית הימנית לא מוצגת, לוחצים על Expand left pane כדי לפתוח אותה.

  3. בחלונית Explorer, מרחיבים את שם הפרויקט ולוחצים על Connections.

  4. בדף Connections, לוחצים על Create connection.

  5. בשדה Connection type, בוחרים באפשרות Vertex AI remote models, remote functions, BigLake and Spanner (Cloud Resource).

  6. בשדה מזהה החיבור, נותנים שם לחיבור.

  7. בקטע Location type, בוחרים מיקום לחיבור. החיבור צריך להיות באותו מיקום כמו המשאבים האחרים, למשל מערכי נתונים.

  8. לוחצים על יצירת חיבור.

  9. לוחצים על מעבר לחיבור.

  10. בחלונית Connection info, מעתיקים את מזהה חשבון השירות כדי להשתמש בו בשלב מאוחר יותר.

SQL

משתמשים בהצהרה CREATE CONNECTION:

  1. נכנסים לדף BigQuery במסוף Google Cloud .

    כניסה ל-BigQuery

  2. בעורך השאילתות, מזינים את ההצהרה הבאה:

    CREATE CONNECTION [IF NOT EXISTS] `CONNECTION_NAME`
    OPTIONS (
      connection_type = "CLOUD_RESOURCE",
      friendly_name = "FRIENDLY_NAME",
      description = "DESCRIPTION"
      );

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫CONNECTION_NAME: שם החיבור בפורמט PROJECT_ID.LOCATION.CONNECTION_ID,‏ LOCATION.CONNECTION_ID או CONNECTION_ID. אם לא מציינים את הפרויקט או המיקום, הם נגזרים מהפרויקט ומהמיקום שבהם ההצהרה מופעלת.
    • ‫FRIENDLY_NAME (אופציונלי): שם תיאורי לחיבור.
    • ‫DESCRIPTION (אופציונלי): תיאור של החיבור.

  3. ‫לוחצים על Run.

מידע נוסף על הרצת שאילתות זמין במאמר הרצת שאילתה אינטראקטיבית.

BQ

  1. בסביבה של שורת הפקודה, יוצרים חיבור:

    bq mk --connection --location=REGION --project_id=PROJECT_ID \
        --connection_type=CLOUD_RESOURCE CONNECTION_ID

    הפרמטר --project_id מבטל את פרויקט ברירת המחדל.

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫REGION: אזור החיבור שלכם
    • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud
    • ‫CONNECTION_ID: מזהה לחיבור

    כשיוצרים משאב חיבור, BigQuery יוצר חשבון שירות ייחודי של המערכת ומשייך אותו לחיבור.

    פתרון בעיות: אם מופיעה שגיאת החיבור הבאה, עדכנו את Google Cloud SDK:

    Flags parsing error: flag --connection_type=CLOUD_RESOURCE: value should be one of...
    
  2. מאחזרים ומעתיקים את מזהה חשבון השירות כדי להשתמש בו בשלב מאוחר יותר:

    bq show --connection PROJECT_ID.REGION.CONNECTION_ID

    הפלט אמור להיראות כך:

    name                          properties
    1234.REGION.CONNECTION_ID     {"serviceAccountId": "connection-1234-9u56h9@gcp-sa-bigquery-condel."}
    

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במדריך למתחילים של BigQuery באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של BigQuery Python API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

import google.api_core.exceptions
from google.cloud import bigquery_connection_v1

client = bigquery_connection_v1.ConnectionServiceClient()


def create_connection(
    project_id: str,
    location: str,
    connection_id: str,
):
    """Creates a BigQuery connection to a Cloud Resource.

    Cloud Resource connection creates a service account which can then be
    granted access to other Google Cloud resources for federated queries.

    Args:
        project_id: The Google Cloud project ID.
        location: The location of the connection (for example, "us-central1").
        connection_id: The ID of the connection to create.
    """

    parent = client.common_location_path(project_id, location)

    connection = bigquery_connection_v1.Connection(
        friendly_name="Example Connection",
        description="A sample connection for a Cloud Resource.",
        cloud_resource=bigquery_connection_v1.CloudResourceProperties(),
    )

    try:
        created_connection = client.create_connection(
            parent=parent, connection_id=connection_id, connection=connection
        )
        print(f"Successfully created connection: {created_connection.name}")
        print(f"Friendly name: {created_connection.friendly_name}")
        print(
            f"Service Account: {created_connection.cloud_resource.service_account_id}"
        )

    except google.api_core.exceptions.AlreadyExists:
        print(f"Connection with ID '{connection_id}' already exists.")
        print("Please use a different connection ID.")
    except Exception as e:
        print(f"An unexpected error occurred while creating the connection: {e}")

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Node.js במדריך למתחילים של BigQuery באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של BigQuery Node.js API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

const {ConnectionServiceClient} =
  require('@google-cloud/bigquery-connection').v1;
const {status} = require('@grpc/grpc-js');

const client = new ConnectionServiceClient();

/**
 * Creates a new BigQuery connection to a Cloud Resource.
 *
 * A Cloud Resource connection creates a service account that can be granted access
 * to other Google Cloud resources.
 *
 * @param {string} projectId The Google Cloud project ID. for example, 'example-project-id'
 * @param {string} location The location of the project to create the connection in. for example, 'us-central1'
 * @param {string} connectionId The ID of the connection to create. for example, 'example-connection-id'
 */
async function createConnection(projectId, location, connectionId) {
  const parent = client.locationPath(projectId, location);

  const connection = {
    friendlyName: 'Example Connection',
    description: 'A sample connection for a Cloud Resource',
    // The service account for this cloudResource will be created by the API.
    // Its ID will be available in the response.
    cloudResource: {},
  };

  const request = {
    parent,
    connectionId,
    connection,
  };

  try {
    const [response] = await client.createConnection(request);

    console.log(`Successfully created connection: ${response.name}`);
    console.log(`Friendly name: ${response.friendlyName}`);

    console.log(`Service Account: ${response.cloudResource.serviceAccountId}`);
  } catch (err) {
    if (err.code === status.ALREADY_EXISTS) {
      console.log(`Connection '${connectionId}' already exists.`);
    } else {
      console.error(`Error creating connection: ${err.message}`);
    }
  }
}

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Java במדריך למתחילים של BigQuery באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של BigQuery Java API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

import com.google.api.gax.rpc.AlreadyExistsException;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.bigquery.connection.v1.CloudResourceProperties;
import com.google.cloud.bigquery.connection.v1.Connection;
import com.google.cloud.bigquery.connection.v1.CreateConnectionRequest;
import com.google.cloud.bigquery.connection.v1.LocationName;
import com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;
import java.io.IOException;

public class CreateConnection {

  /**
   * Creates a BigQuery connection to a Cloud Resource. A Cloud Resource connection provisions a
   * service account that can be granted access to other Google Cloud resources for federated
   * queries.
   *
   * @param projectId The Google Cloud project ID (for example, "example-project-id").
   * @param location The geographic location of the connection (for example, "us-central1").
   * @param connectionId The ID of the connection to create (for example, "example-connection-id").
   */
  public static void createConnection(String projectId, String location, String connectionId) {
    LocationName parent = LocationName.of(projectId, location);

    // CloudResourceProperties provisions a managed Google Cloud service account on creation.
    CloudResourceProperties cloudResourceProperties = CloudResourceProperties.newBuilder().build();
    Connection connection =
        Connection.newBuilder()
            .setFriendlyName("Example Connection")
            .setDescription("Cloud Resource connection for federated queries.")
            .setCloudResource(cloudResourceProperties)
            .build();

    CreateConnectionRequest request =
        CreateConnectionRequest.newBuilder()
            .setParent(parent.toString())
            .setConnectionId(connectionId)
            .setConnection(connection)
            .build();

    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
      Connection response = client.createConnection(request);

      System.out.printf("Successfully created connection: %s%n", response.getName());
      System.out.printf("Friendly name: %s%n", response.getFriendlyName());
      System.out.printf(
          "Service Account: %s%n", response.getCloudResource().getServiceAccountId());
    } catch (AlreadyExistsException err) {
      System.err.printf(
          "error: connection '%s' already exists in location '%s' for project '%s': %s%n",
          connectionId, location, projectId, err.getMessage());
    } catch (ApiException | IOException err) {
      System.err.printf(
          "error: failed to create connection '%s' in location '%s' for project '%s': %s%n",
          connectionId, location, projectId, err.getMessage());
    }
  }

Terraform

משתמשים במשאב google_bigquery_connection.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

בדוגמה הבאה נוצר קישור למשאבים ב-Cloud בשם my_cloud_resource_connection באזור US:


# This queries the provider for project information.
data "google_project" "default" {}

# This creates a cloud resource connection in the US region named my_cloud_resource_connection.
# Note: The cloud resource nested object has only one output field - serviceAccountId.
resource "google_bigquery_connection" "default" {
  connection_id = "my_cloud_resource_connection"
  project       = data.google_project.default.project_id
  location      = "US"
  cloud_resource {}
}

כך מחילים את ההגדרות של Terraform בפרויקט ב- Google Cloud :

הכנת Cloud Shell

  1. מפעילים את Cloud Shell.
  2. מגדירים את פרויקט ברירת המחדל ב- Google Cloud שבו רוצים להחיל את ההגדרות של Terraform.

    תצטרכו להריץ את הפקודה הזו רק פעם אחת לכל פרויקט, ותוכלו לעשות זאת בכל ספרייה.

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    אם תגדירו ערכים ספציפיים בקובץ התצורה של Terraform, הם יבטלו את ערכי ברירת המחדל של משתני הסביבה.

הכנת הספרייה

לכל קובץ תצורה של Terraform צריכה להיות ספרייה משלו (שנקראת גם מודול ברמה הבסיסית).

  1. יוצרים ספרייה חדשה ב-Cloud Shell ובה יוצרים קובץ חדש. שם הקובץ חייב לכלול את הסיומת .tf, למשל main.tf. במדריך הזה, הקובץ נקרא main.tf.
    mkdir DIRECTORY && cd DIRECTORY && touch main.tf
  2. אם אתם עוקבים אחרי המדריך, תוכלו להעתיק את הקוד לדוגמה בכל קטע או שלב.

    מעתיקים את הקוד לדוגמה בקובץ main.tf החדש שיצרתם.

    לחלופין, אפשר גם להעתיק את הקוד מ-GitHub. כדאי לעשות את זה כשקטע הקוד של Terraform הוא חלק מפתרון מקצה לקצה.

  3. בודקים את הפרמטרים לדוגמה ומשנים אותם בהתאם לסביבה שלכם.
  4. שומרים את השינויים.
  5. מפעילים את Terraform. צריך לעשות זאת רק פעם אחת לכל ספרייה.
    terraform init

    אופציונלי: תוכלו לכלול את האפשרות -upgrade, כדי להשתמש בגרסה העדכנית ביותר של הספק של Google:

    terraform init -upgrade

החלה של השינויים

  1. בודקים את ההגדרות ומוודאים שהמשאבים שמערכת Terraform תיצור או תעדכן תואמים לציפיות שלכם:
    terraform plan

    מתקנים את ההגדרות לפי הצורך.

  2. מריצים את הפקודה הבאה ומזינים yes בהודעה שמופיעה, כדי להחיל את הגדרות Terraform:
    terraform apply

    ממתינים עד שב-Terraform תוצג ההודעה "Apply complete!‎".

  3. פותחים את הפרויקט ב- Google Cloud כדי להציג את התוצאות. במסוף Google Cloud , נכנסים למשאבים בממשק המשתמש כדי לוודא שהם נוצרו או עודכנו ב-Terraform.

מתן הרשאות לחשבון השירות של החיבור

בוחרים באחת מהאפשרויות הבאות:

המסוף

  1. נכנסים לדף IAM & Admin.

    כניסה לדף IAM & Admin

  2. לוחצים על הוספה.

    תיבת הדו-שיח Add principals נפתחת.

  3. בשדה New principals, מזינים את מזהה חשבון השירות שהעתקתם קודם.

  4. בשדה Select a role, בוחרים באפשרות Service Usage ואז באפשרות Service Usage Consumer.

  5. לוחצים על הוספת תפקיד.

  6. בשדה Select a role, בוחרים באפשרות BigQuery ואז באפשרות BigQuery Connection User.

  7. לוחצים על Save.

gcloud

משתמשים בפקודה gcloud projects add-iam-policy-binding:

gcloud projects add-iam-policy-binding 'PROJECT_NUMBER' --member='serviceAccount:MEMBER' --role='roles/serviceusage.serviceUsageConsumer' --condition=None
gcloud projects add-iam-policy-binding 'PROJECT_NUMBER' --member='serviceAccount:MEMBER' --role='roles/bigquery.connectionUser' --condition=None

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_NUMBER: מספר הפרויקט.
  • ‫MEMBER: מזהה חשבון השירות שהעתקתם קודם.

אם לא תתנו את ההרשאה, תופיע הודעת שגיאה.

יצירת המודל המרוחק

משתמשים בהצהרה CREATE MODEL כדי ליצור מודל מרוחק שמייצג את Cloud Natural Language API המארח:

  1. נכנסים לדף BigQuery במסוף Google Cloud .

    כניסה ל-BigQuery

  2. בעורך השאילתות, מריצים את ההצהרה הבאה:

    CREATE OR REPLACE MODEL `bqml_tutorial.nlp_model`
      REMOTE WITH CONNECTION `LOCATION.CONNECTION_ID`
      OPTIONS (REMOTE_SERVICE_TYPE = 'CLOUD_AI_NATURAL_LANGUAGE_V1');

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫LOCATION: מיקום החיבור
    • ‫CONNECTION_ID: המזהה של החיבור ל-BigQuery

      כשמציגים את פרטי החיבור במסוף Google Cloud , זה הערך בקטע האחרון של מזהה החיבור המלא שמוצג ב-Connection ID, לדוגמה projects/myproject/locations/connection_location/connections/myconnection

    השאילתה מסתיימת תוך כמה שניות, ואז המודל nlp_model מופיע במערך הנתונים bqml_tutorial. אין תוצאות לשאילתה.

הבנת טקסט

משתמשים בפונקציה ML.UNDERSTAND_TEXT ובמודל המרוחק כדי לנתח טקסט ממערך נתונים ציבורי של ביקורות על סרטים:

  1. נכנסים לדף BigQuery במסוף Google Cloud .

    כניסה ל-BigQuery

  2. בעורך השאילתות, מריצים את ההצהרה הבאה כדי לבצע ניתוח סנטימנטים על חמש ביקורות של סרטים:

    SELECT
      *
    FROM
      ML.UNDERSTAND_TEXT(
        MODEL `bqml_tutorial.nlp_model`,
        (
          SELECT
            review AS text_content
          FROM
            `bigquery-public-data.imdb.reviews`
          LIMIT 5
        ),
        STRUCT('ANALYZE_SENTIMENT' AS nlu_option));

    הפלט אמור להיראות כך:

    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    | text_content                             | ml_understand_text_result                                                                                                                          | ml_understand_text_status |
    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    | Once again Mr. Costner has dragged out   | {"document_sentiment":{"magnitude":0.8,"score":-0.7},"language":"en","sentences":[{"sentiment":{"magnitude":0.8,"score":-0.7},"text":{...}}]}      |                           |
    | This movie is amazing because the fact...| {"document_sentiment":{"magnitude":0.9,"score":0.8},"language":"en","sentences":[{"sentiment":{"magnitude":0.9,"score":0.8},"text":{...}}]}        |                           |
    | ...                                      | ...                                                                                                                                                | ...                       |
    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    

    ציון חיובי מציין סנטימנט חיובי, וציון שלילי מציין סנטימנט שלילי. העוצמה מציינת את חוזק הסנטימנט.

  3. בעורך השאילתות, מריצים את ההצהרה הבאה כדי לבצע ניתוח ישויות בחמש ביקורות על סרטים:

    SELECT
      *
    FROM
      ML.UNDERSTAND_TEXT(
        MODEL `bqml_tutorial.nlp_model`,
        (
          SELECT
            review AS text_content
          FROM
            `bigquery-public-data.imdb.reviews`
          LIMIT 5
        ),
        STRUCT('ANALYZE_ENTITIES' AS nlu_option));

    הפלט אמור להיראות כך:

    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    | text_content                             | ml_understand_text_result                                                                                                                          | ml_understand_text_status |
    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    | Once again Mr. Costner has dragged out...| {"entities":[{"mentions":[{"text":{"begin_offset":-1,"content":"Costner"},"type":"PROPER"},{"text":{"begin_offset":-1,"content":"Mr."},"type"...]  |                           |
    | This movie is amazing because the fact...| {"entities":[{"mentions":[{"text":{"begin_offset":-1,"content":"people"},"type":"COMMON"}],"name":"people","salience":0.37163052,"type":...]       |                           |
    | ...                                      | ...                                                                                                                                                | ...                       |
    +------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+
    

    בפלט מוצגות הישויות שזוהו בטקסט, סוג הישות והחשיבות (salience) של הישות. החשיבות מציינת עד כמה הישות חשובה לטקסט.

הסרת המשאבים

כדי להימנע מחיובים בחשבון Google Cloud בגלל השימוש במשאבים שנעשה במסגרת המדריך הזה, אפשר למחוק את הפרויקט שמכיל את המשאבים, או להשאיר את הפרויקט ולמחוק את המשאבים הנפרדים.

מחיקת הפרויקט

    כדי למחוק פרויקט ב- Google Cloud :

    gcloud projects delete PROJECT_ID

מחיקת משאבים ספציפיים

אם אתם רוצים להשתמש בפרויקט שוב, אתם צריכים למחוק את המשאבים שיצרתם בשביל המדריך.

המסוף

  1. מוחקים את מערך הנתונים. מחיקת מערך הנתונים מוחקת גם את המודל המרוחק:

    1. בחלונית Explorer, מרחיבים את הפרויקט ולוחצים על Datasets.

    2. ברשימה Datasets, לוחצים על מערך הנתונים bqml_tutorial.

    3. בחלונית הפרטים, לוחצים על מחיקה.

    4. בתיבת הדו-שיח Delete dataset, לוחצים על Delete.

  2. מחיקת החיבור:

    1. בחלונית Explorer, מרחיבים את הפרויקט ולוחצים על Connections.

    2. ברשימה Connections, לוחצים על החיבור שיצרתם.

    3. בחלונית הפרטים, לוחצים על מחיקה.

    4. בתיבת הדו-שיח Delete connection, מזינים את הערך delete כדי לאשר את המחיקה.

    5. לוחצים על Delete.

gcloud

  1. מוחקים את מערך הנתונים bqml_tutorial ואת המודל המרוחק:

    bq rm --dataset --recursive bqml_tutorial
    
  2. מחיקת החיבור:

    bq rm --connection <var>PROJECT_ID</var>.<var>LOCATION</var>.<var>CONNECTION_ID</var>
    

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫<var>PROJECT_ID</var>: מזהה הפרויקט ב- Google Cloud
    • ‫<var>LOCATION</var>: מיקום החיבור
    • ‫<var>CONNECTION_ID</var>: מזהה החיבור

המאמרים הבאים