การจำแนกประเภทข้อความ

การแนะนำ 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

การแปลงผลลัพธ์เป็น dictionary

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

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

การปรับขนาดเวิร์กโฟลว์

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

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

df = cell2.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

การวิเคราะห์ sentiment

  • สนใจเฉพาะ sentiment ของรีวิว

AI_SENTIMENT ใน SQL cell

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

การวิเคราะห์ sentiment

AI_SENTIMENT - การดึงค่า sentiment

$$

  • sentiment ที่รองรับ: positive, negative, neutral, mixed, และ unknown
การแนะนำ Generative AI ใน Snowflake

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

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

Preparing Video For Download...