Klasifikace textu

Introduction to Generative AI in Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Výzvy při klasifikaci textu

Problém

$$

  • Recenze mohou obsahovat jakékoli informace

$$

  • Ruční kategorizace je časově náročná a neškalovatelná

Řešení

$$

  • Automatizace pomocí Snowflake Cortex!

$$

  • classify_text()
Introduction to Generative AI in Snowflake

Definování kategorií

# Define categories
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Introduction to Generative AI in Snowflake

Klasifikace textu

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"  
}
Introduction to Generative AI in Snowflake

Převod výstupů na slovník

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Introduction to Generative AI in Snowflake

Škálování pracovního postupu

  • Klasifikační pipeline kategorizující recenze pro daný měsíc
# Python code
month = 5
-- SQL query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Introduction to Generative AI in Snowflake

Použití 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"]
Introduction to Generative AI in Snowflake

Použití 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
Introduction to Generative AI in Snowflake

Analýza sentimentu

  • Zájem pouze o sentiment recenzí

AI_SENTIMENT v buňce SQL

Introduction to Generative AI in Snowflake

Analýza sentimentu

AI_SENTIMENT – extrakce sentimentu

$$

  • Dostupné sentimenty: positive, negative, neutral, mixed a unknown
Introduction to Generative AI in Snowflake

Lass uns üben!

Introduction to Generative AI in Snowflake

Preparing Video For Download...