ביצוע ניתוח סמנטי באמצעות פונקציות AI מנוהלות
במדריך הזה נסביר איך להשתמש בפונקציות מנוהלות של AI ב-BigQuery ML כדי לבצע ניתוח סמנטי של משוב מלקוחות.
מטרות
במדריך הזה תלמדו:
- יצירה של מערך נתונים וטעינה של נתוני סנטימנט לטבלה
- כדי לבצע ניתוח סמנטי, משתמשים בפונקציות ה-AI הבאות:
-
AI.IF: כדי לסנן את הנתונים באמצעות תנאים בשפה טבעית -
AI.SCORE: לדרג את הקלט לפי סנטימנט -
AI.CLASSIFY: כדי לסווג קלט לקטגוריות שהוגדרו על ידי המשתמש
-
עלויות
במדריך הזה נעשה שימוש ברכיבים של Google Cloudשחלים עליהם חיובים, כולל הרכיבים הבאים:
- BigQuery
- BigQuery ML
מידע נוסף על העלויות ב-BigQuery זמין בדף תמחור ב-BigQuery.
מידע נוסף על העלויות של BigQuery ML זמין במאמר תמחור ב-BigQuery ML.
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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.
-
מפעילים את BigQuery API.
תפקידים שנדרשים להפעלת ממשקי API
כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (
roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאהserviceusage.services.enable. איך מקצים תפקידיםבפרויקטים חדשים, BigQuery API מופעל באופן אוטומטי.
- אופציונלי: מפעילים חיוב בפרויקט. גם אם אתם לא רוצים להפעיל חיוב או לספק כרטיס אשראי, השלבים שבמסמך הזה עדיין רלוונטיים. BigQuery מספק לכם ארגז חול לביצוע השלבים. מידע נוסף זמין במאמר בנושא הפעלת ארגז החול של BigQuery.
התפקידים הנדרשים
כדי לקבל את ההרשאות שדרושות לשימוש בפונקציות AI, צריך לבקש מהאדמין להקצות לכם בפרויקט את תפקידי ה-IAM הבאים:
-
הפעלת משימות של שאילתות וטעינה:
BigQuery Job User (
roles/bigquery.jobUser) -
יצירת מערך נתונים, יצירת טבלה, טעינת נתונים לטבלה והרצת שאילתה בטבלה:
כלי עריכת הנתונים של BigQuery (
roles/bigquery.dataEditor)
להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.
יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.
יצירת נתונים לדוגמה
כדי ליצור מערך נתונים בשם my_dataset לצורך המדריך הזה, מריצים את השאילתה הבאה.
CREATE SCHEMA my_dataset OPTIONS (location = 'LOCATION');
לאחר מכן, יוצרים טבלה בשם customer_feedback שמכילה דוגמאות לביקורות של לקוחות על מכשיר:
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.")
])
);
סיווג הסנטימנט הכולל
יכול להיות שימושי לחלץ את הסנטימנט הכללי שמופיע בטקסט כדי לתמוך בתרחישי שימוש כמו הבאים:
- למדוד את שביעות רצון הלקוחות על סמך הביקורות.
- מעקב אחרי תפיסת המותג ברשתות החברתיות.
- קביעת סדר עדיפויות לכרטיסי תמיכה על סמך רמת הכעס של המשתמשים.
השאילתה הבאה מראה איך להשתמש בפונקציה AI.CLASSIFY כדי לסווג ביקורות מהטבלה customer_feedback כחיוביות, שליליות או ניטרליות:
SELECT
review_id,
review_text,
AI.CLASSIFY(
review_text,
categories => ['positive', 'negative', 'neutral'],
endpoint => 'gemini-2.5-pro') AS sentiment
FROM
my_dataset.customer_feedback;
התוצאה אמורה להיראות כך:
+-----------+------------------------------------------+-----------+ | 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." | | +-----------+------------------------------------------+-----------+ | 6 | "Absolutely furious! The item arrived | negative | | | broken, and getting a refund is proving | | | | impossible. I will never buy from them | | | | again." | | +-----------+------------------------------------------+-----------+
ניתוח סנטימנטים מבוסס-היבטים
אם סנטימנט כללי כמו חיובי או שלילי לא מספיק לתרחיש השימוש שלכם, אתם יכולים לנתח היבט ספציפי של משמעות הטקסט. לדוגמה, יכול להיות שתרצו להבין מה דעת המשתמש על איכות המוצר, בלי להתייחס לדעתו על המחיר. אפשר אפילו לבקש ערך מותאם אישית כדי לציין שהיבט מסוים לא רלוונטי.
בדוגמה הבאה מוצג אופן השימוש בפונקציה AI.SCORE כדי לדרג את סנטימנט המשתמשים מ-1 עד 10 על סמך מידת החיוביות של כל ביקורת בטבלה customer_feedback כלפי המחיר, שירות הלקוחות והאיכות. הפונקציה מחזירה את הערך המותאם אישית -1 במקרים שבהם היבט מסוים לא מוזכר בביקורת, כדי שתוכלו לסנן את הביקורות האלה בהמשך.
SELECT
review_id,
review_text,
AI.SCORE(
("Score 0.0 to 10 on positive sentiment about PRICE for review: ", review_text,
"If price is not mentioned, return -1.0"),
endpoint => 'gemini-2.5-pro') AS price_score,
AI.SCORE(
("Score 0.0 to 10 on positive sentiment about CUSTOMER SERVICE for review: ", review_text,
"If customer service is not mentioned, return -1.0"),
endpoint => 'gemini-2.5-pro') AS service_score,
AI.SCORE(
("Score 0.0 to 10 on positive sentiment about QUALITY for review: ", review_text,
"If quality is not mentioned, return -1.0"),
endpoint => 'gemini-2.5-pro') AS quality_score
FROM
my_dataset.customer_feedback
LIMIT 3;
התוצאה אמורה להיראות כך:
+-----------+------------------------------------------+--------------+---------------+---------------+ | review_id | review_text | price_score | service_score | quality_score | +-----------+------------------------------------------+--------------+---------------+---------------+ | 4 | "I'm so happy with this purchase! It | -1.0 | -1.0 | 9.5 | | | arrived early and exceeded all my | | | | | | expectations. The quality is top-notch, | | | | | | although the setup was a bit tricky." | | | | +-----------+------------------------------------------+--------------+---------------+---------------+ | 8 | "The shipping was delayed, but the | 9.0 | 8.5 | 9.0 | | | support team was very helpful and kept | | | | | | me informed. The product itself is | | | | | | great, especially for the price." | | | | +-----------+------------------------------------------+--------------+---------------+---------------+ | 6 | "Absolutely furious! The item arrived | -1.0 | 1.0 | 0.0 | | | broken, and getting a refund is proving | | | | | | impossible. I will never buy from them | | | | | | again." | | | | +-----------+------------------------------------------+--------------+---------------+---------------+
זיהוי רגשות
בנוסף לניתוח סנטימנט חיובי או שלילי, אפשר לסווג טקסט לפי רגשות ספציפיים שתבחרו. התכונה הזו שימושית כשרוצים להבין טוב יותר את התשובות של המשתמשים, או לסמן משוב עם רגשות חזקים לבדיקה.
SELECT
review_id,
review_text,
AI.CLASSIFY(
review_text,
categories => ['joy', 'anger', 'sadness', 'surprise', 'fear', 'disgust', 'neutral', 'other'],
endpoint => 'gemini-2.5-pro'
) AS emotion
FROM
my_dataset.customer_feedback;
התוצאה אמורה להיראות כך:
+-----------+------------------------------------------+---------+ | review_id | review_text | emotion | +-----------+------------------------------------------+---------+ | 2 | "Customer support was a nightmare. It | anger | | | took three weeks for my order to | | | | arrive, and when it did, the box was | | | | damaged. Very frustrating!" | | +-----------+------------------------------------------+---------+ | 7 | This new feature for account access is | anger | | | confusing. I can't find where to update | | | | my profile. Please fix this bug! | | +-----------+------------------------------------------+---------+ | 4 | "I'm so happy with this purchase! It | joy | | | arrived early and exceeded all my | | | | expectations. The quality is top-notch, | | | | although the setup was a bit tricky." | | +-----------+------------------------------------------+---------+ | 1 | "The battery life is incredible, and | joy | | | the screen is gorgeous! Best phone I've | | | | ever had. Totally worth the price." | | +-----------+------------------------------------------+---------+ | 8 | "The shipping was delayed, but the | joy | | | 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 | sadness | | | 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." | | +-----------+------------------------------------------+---------+ | 6 | "Absolutely furious! The item arrived | anger | | | broken, and getting a refund is proving | | | | impossible. I will never buy from them | | | | again." | | +-----------+------------------------------------------+---------+
סיווג ביקורות לפי נושא
אפשר להשתמש בפונקציה AI.CLASSIFY כדי לקבץ ביקורות לנושאים מוגדרים מראש.
לדוגמה, אתם יכולים:
- לגלות נושאים נפוצים במשוב מלקוחות.
- ארגון מסמכים לפי נושא.
- הפניית כרטיסי תמיכה לפי נושא.
בדוגמה הבאה מוצגות דרכים לסווג משוב מלקוחות לסוגים שונים, כמו בעיה בחיוב או גישה לחשבון, ואז לספור כמה ביקורות משתייכות לכל קטגוריה:
SELECT
AI.CLASSIFY(
review_text,
categories => ['Billing Issue', 'Account Access',
'Product Bug', 'Feature Request',
'Shipping Delay', 'Other'],
endpoint => 'gemini-2.5-pro') AS topic,
COUNT(*) AS number_of_reviews,
FROM
my_dataset.customer_feedback
GROUP BY topic
ORDER BY number_of_reviews DESC;
התוצאה אמורה להיראות כך:
+----------------+-------------------+ | topic | number_of_reviews | +----------------+-------------------+ | Other | 5 | | Shipping Delay | 2 | | Product Bug | 1 | +----------------+-------------------+
זיהוי ביקורות דומות מבחינה סמנטית
אפשר להשתמש בפונקציה AI.SCORE כדי להעריך את הדמיון הסמנטי בין שני קטעי טקסט. לשם כך, צריך לבקש ממנה לדרג את הדמיון במשמעות. הוא יכול לעזור לכם במשימות כמו:
- למצוא רשומות כפולות או כמעט כפולות.
- קיבוץ של משוב דומה.
- הפעלת אפליקציות חיפוש סמנטיות.
השאילתה הבאה מוצאת ביקורות שבהן מוזכרות בעיות בהגדרת המוצר:
SELECT
review_id,
review_text,
AI.SCORE(
(
"""How similar is the review to the concept of 'difficulty in setting up the product'?
A higher score indicates more similarity. Review: """,
review_text),
endpoint => 'gemini-2.5-pro') AS setup_difficulty
FROM my_dataset.customer_feedback
ORDER BY setup_difficulty DESC
LIMIT 2;
התוצאה אמורה להיראות כך:
+-----------+------------------------------------------+------------------+ | review_id | review_text | setup_difficulty | +-----------+------------------------------------------+------------------+ | 4 | "I'm so happy with this purchase! It | 3 | | | arrived early and exceeded all my | | | | expectations. The quality is top-notch, | | | | although the setup was a bit tricky." | | +-----------+------------------------------------------+------------------+ | 7 | This new feature for account access is | 1 | | | confusing. I can't find where to update | | | | my profile. Please fix this bug! | | +-----------+------------------------------------------+------------------+
אפשר גם להשתמש בפונקציה AI.IF כדי למצוא ביקורות שקשורות לטקסט:
SELECT
review_id,
review_text
FROM my_dataset.customer_feedback
WHERE
AI.IF(
(
"Does this review discuss difficulty setting up the product? Review: ",
review_text),
endpoint => 'gemini-2.5-pro');
שילוב פונקציות
כדאי לשלב את הפונקציות האלה בשאילתה אחת. לדוגמה, השאילתה הבאה מסננת קודם את הביקורות לפי סנטימנט שלילי, ואז ממיינת אותן לפי סוג התסכול:
SELECT
review_id,
review_text,
AI.CLASSIFY(
review_text,
categories => [
'Poor Quality', 'Bad Customer Service', 'High Price', 'Other Negative'],
endpoint => 'gemini-2.5-pro') AS negative_topic
FROM my_dataset.customer_feedback
WHERE
AI.IF(
("Does this review express a negative sentiment? Review: ", review_text),
endpoint => 'gemini-2.5-pro');
יצירת פונקציות מוגדרות על ידי המשתמש (UDF) של הנחיות לשימוש חוזר
כדי שהשאילתות יהיו קלות לקריאה, אפשר ליצור פונקציות בהגדרת המשתמש ולעשות בהן שימוש חוזר. השאילתה הבאה יוצרת פונקציה לזיהוי סנטימנט שלילי על ידי קריאה ל-AI.IF עם הנחיה בהתאמה אישית. לאחר מכן, היא מפעילה את הפונקציה הזו כדי לסנן לפי ביקורת שלילית.
CREATE OR REPLACE FUNCTION my_dataset.is_negative_sentiment(review_text STRING)
RETURNS BOOL
AS (
AI.IF(
("Does this review express a negative sentiment? Review: ", review_text),
endpoint => 'gemini-2.5-pro')
);
SELECT
review_id,
review_text
FROM my_dataset.customer_feedback
WHERE my_dataset.is_negative_sentiment(review_text);
הסרת המשאבים
כדי להימנע מחיובים, אתם יכולים למחוק את הפרויקט שמכיל את המשאבים שיצרתם, או להשאיר את הפרויקט ולמחוק את המשאבים הספציפיים.
מחיקת פרויקט
כדי למחוק את הפרויקט:
- במסוף Google Cloud , נכנסים לדף Manage resources.
- ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
- כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.
מחיקת מערך נתונים
כדי למחוק את מערך הנתונים ואת כל המשאבים שהוא מכיל, כולל כל הטבלאות והפונקציות, מריצים את השאילתה הבאה:
DROP SCHEMA my_dataset CASCADE;