텍스트 분류

Snowflake에서 시작하는 생성형 AI

James Cha-Earley

Senior Developer Advocate, Snowflake

텍스트 분류의 어려움

문제점

$$

  • 리뷰에는 다양한 정보가 담겨 있습니다

$$

  • 수동 분류는 시간이 많이 걸리고 확장성이 없습니다

해결책

$$

  • Snowflake Cortex로 자동화하세요!

$$

  • classify_text()
Snowflake에서 시작하는 생성형 AI

카테고리 정의하기

# Define categories
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Snowflake에서 시작하는 생성형 AI

텍스트 분류하기

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"  
}
Snowflake에서 시작하는 생성형 AI

결과물을 딕셔너리로 변환하기

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Snowflake에서 시작하는 생성형 AI

워크플로우 확장하기

  • 특정 월의 리뷰를 분류하는 분류 파이프라인
# Python code
month = 5
-- SQL query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Snowflake에서 시작하는 생성형 AI

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"]
Snowflake에서 시작하는 생성형 AI

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
Snowflake에서 시작하는 생성형 AI

감성 분석

  • 리뷰의 감성에만 관심이 있는 경우

SQL 셀에서 AI_SENTIMENT 사용하기

Snowflake에서 시작하는 생성형 AI

감성 분석

AI_SENTIMENT - 감성 추출하기

$$

  • 사용 가능한 감성: positive, negative, neutral, mixed, unknown
Snowflake에서 시작하는 생성형 AI

연습해 봅시다!

Snowflake에서 시작하는 생성형 AI

Preparing Video For Download...