Klasifikasi teks

Pengantar Generative AI di Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Tantangan mengklasifikasikan teks

Masalahnya

$$

  • Ulasan bisa memuat informasi apa pun

$$

  • Kategorisasi manual memakan waktu dan tidak skalabel

Solusinya

$$

  • Otomatiskan dengan Snowflake Cortex!

$$

  • classify_text()
Pengantar Generative AI di Snowflake

Menetapkan kategori

# Define categories
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Pengantar Generative AI di Snowflake

Mengklasifikasikan teks

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"  
}
Pengantar Generative AI di Snowflake

Mengonversi keluaran ke dictionary

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Pengantar Generative AI di Snowflake

Menskalakan alur kerja

  • Pipeline klasifikasi untuk mengategorikan ulasan pada bulan tertentu
# Python code
month = 5
-- SQL query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Pengantar Generative AI di Snowflake

Menerapkan 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"]
Pengantar Generative AI di Snowflake

Menerapkan 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
Pengantar Generative AI di Snowflake

Analisis sentimen

  • Hanya tertarik pada sentimen ulasan

AI_SENTIMENT in a SQL cell

Pengantar Generative AI di Snowflake

Analisis sentimen

AI_SENTIMENT - mengekstrak sentimen

$$

  • Sentimen yang tersedia: positive, negative, neutral, mixed, dan unknown
Pengantar Generative AI di Snowflake

Ayo berlatih!

Pengantar Generative AI di Snowflake

Preparing Video For Download...