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

Vấn đề

$$

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

$$

  • Phân loại thủ công tốn thời gian và 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

Xác định danh mục

# Define categories
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 đầu ra thành 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 các bài đánh giá trong một tháng cho trước
# Python code
month = 5
-- SQL query
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 = dataframe_1.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()

# 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
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 bài đánh giá

AI_SENTIMENT in a SQL cell

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

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

AI_SENTIMENT - extracting a sentiment

$$

  • Các nhãn cảm xúc: positive, negative, neutral, mixed, và unknown
Giới thiệu về Generative AI trong Snowflake

Cùng luyện tập nào!

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

Preparing Video For Download...