การจำแนกข้อความ

การแนะนำ Generative AI ใน Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

ความท้าทายในการจำแนกข้อความ

ปัญหา

$$

  • รีวิวอาจมีข้อมูลหลากหลายรูปแบบ

$$

  • การจัดหมวดหมู่ด้วยมือใช้เวลานานและขยายขนาดไม่ได้

วิธีแก้ปัญหา

$$

  • ทำให้เป็นอัตโนมัติด้วย Snowflake Cortex!

$$

  • classify_text()
การแนะนำ Generative AI ใน Snowflake

การกำหนดหมวดหมู่

# Define categories
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
การแนะนำ Generative AI ใน Snowflake

การจำแนกข้อความ

from snowflake.cortex import classify_text

category = classify_text( str_input="The check-in was smooth and the staff were very friendly.", categories=categories )
print(category)
{  
  "label": "staff"  
}
การแนะนำ Generative AI ใน Snowflake

การแปลงผลลัพธ์ให้เป็นดิกชันนารี

print(type(category))
<class 'str'>
import json

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
การแนะนำ Generative AI ใน Snowflake

การขยายขนาดเวิร์กโฟลว์

  • ไปป์ไลน์การจำแนกประเภทสำหรับจัดหมวดหมู่รีวิวในเดือนที่กำหนด
# Python code
month = 5
-- SQL query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
การแนะนำ Generative AI ใน Snowflake

การใช้งาน classify_text()

df = dataframe_1.to_pandas()

def classification(text): result = classify_text( str_input=text, categories=labels ) result_dict = json.loads(result) return result_dict["label"]
การแนะนำ Generative AI ใน Snowflake

การใช้งาน classify_text()

# Apply classification to the DataFrame
df["category"] = reviews["DESCRIPTION"].apply(classification)

# Print the first row's predicted category print(df["category"].head(1))
0    overall_experience  
Name: category, dtype: object
การแนะนำ Generative AI ใน Snowflake

การวิเคราะห์ความรู้สึก

  • สนใจเฉพาะความรู้สึกของรีวิวเท่านั้น

AI_SENTIMENT ในเซลล์ SQL

การแนะนำ Generative AI ใน Snowflake

การวิเคราะห์ความรู้สึก

AI_SENTIMENT - การดึงความรู้สึก

$$

  • ความรู้สึกที่มีให้ใช้: positive, negative, neutral, mixed และ unknown
การแนะนำ Generative AI ใน Snowflake

มาฝึกกันเถอะ!

การแนะนำ Generative AI ใน Snowflake

Preparing Video For Download...