Phân loại văn bản

Giới thiệu về Generative AI trong Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Thách thức khi phân loại văn bản

Bài toán

$$

  • Đánh giá có thể chứa mọi loại thông tin

$$

  • Gán nhãn thủ công tốn thời gian, không mở rộng được

Giải pháp

$$

  • Tự động hóa với Snowflake Cortex!

$$

  • classify_text()
Giới thiệu về Generative AI trong Snowflake

Định nghĩa danh mục

# Định nghĩa danh mục
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Giới thiệu về Generative AI trong Snowflake

Phân loại văn bản

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"  
}
Giới thiệu về Generative AI trong Snowflake

Chuyển đổi đầu ra sang dictionary

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Giới thiệu về Generative AI trong Snowflake

Mở rộng quy trình làm việc

  • Quy trình phân loại đánh giá theo tháng chỉ định
# Mã Python
month = 5
-- Truy vấn SQL
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Giới thiệu về Generative AI trong Snowflake

Áp dụng 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"]
Giới thiệu về Generative AI trong Snowflake

Áp dụng classify_text()

# Áp dụng phân loại cho DataFrame
df["category"] = reviews["DESCRIPTION"].apply(classification)

# In danh mục dự đoán của hàng đầu tiên print(df["category"].head(1))
0    overall_experience  
Name: category, dtype: object
Giới thiệu về Generative AI trong Snowflake

Phân tích cảm xúc

  • Chỉ quan tâm đến cảm xúc của đánh giá

AI_SENTIMENT trong ô SQL

Giới thiệu về Generative AI trong Snowflake

Phân tích cảm xúc

AI_SENTIMENT - trích xuất cảm xúc

$$

  • Cảm xúc hỗ trợ: positive, negative, neutral, mixed, và unknown
Giới thiệu về Generative AI trong Snowflake

Luyện tập nào!

Giới thiệu về Generative AI trong Snowflake

Preparing Video For Download...