Tekstclassificatie

Introductie tot Generatieve AI in Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Uitdagingen bij tekstclassificatie

Het probleem

$$

  • Beoordelingen kunnen van alles bevatten

$$

  • Handmatig categoriseren kost tijd en schaalt niet

De oplossing

$$

  • Automatiseer met Snowflake Cortex!

$$

  • classify_text()
Introductie tot Generatieve AI in Snowflake

Categorieën definiëren

# Categorieën definiëren
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Introductie tot Generatieve AI in Snowflake

Tekst classificeren

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"  
}
Introductie tot Generatieve AI in Snowflake

Resultaten omzetten naar dictionary

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Introductie tot Generatieve AI in Snowflake

De workflow opschalen

  • Classificatie-pijplijn die beoordelingen voor een maand categoriseert
# Python-code
month = 5
-- SQL-query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Introductie tot Generatieve AI in Snowflake

classify_text() toepassen

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"]
Introductie tot Generatieve AI in Snowflake

classify_text() toepassen

# Classificatie toepassen op de DataFrame
df["category"] = reviews["DESCRIPTION"].apply(classification)

# Voorspelde categorie van de eerste rij printen print(df["category"].head(1))
0    overall_experience  
Name: category, dtype: object
Introductie tot Generatieve AI in Snowflake

Sentimentanalyse

  • Alleen geïnteresseerd in de sentimenten van reviews

AI_SENTIMENT in een SQL-cel

Introductie tot Generatieve AI in Snowflake

Sentimentanalyse

AI_SENTIMENT - sentiment extraheren

$$

  • Beschikbare sentimenten: positive, negative, neutral, mixed en unknown
Introductie tot Generatieve AI in Snowflake

Laten we oefenen!

Introductie tot Generatieve AI in Snowflake

Preparing Video For Download...