Classification de texte

Introduction à l'IA générative dans Snowflake

James Cha-Earley

Senior Developer Advocate, Snowflake

Défis de la classification de texte

Le problème

$$

  • Les avis peuvent contenir n'importe quelle information

$$

  • Le classement manuel prend du temps et ne passe pas à l'échelle

La solution

$$

  • Automatisez avec Snowflake Cortex !

$$

  • classify_text()
Introduction à l'IA générative dans Snowflake

Définir des catégories

# Définir les catégories
categories = ["overall_experience", "location", "staff", "food_beverages",
              "facilities"]
Introduction à l'IA générative dans Snowflake

Classer du texte

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 à l'IA générative dans Snowflake

Convertir les sorties en dictionnaire

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

category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
Introduction à l'IA générative dans Snowflake

Faire passer l’exploitation à l’échelle

  • Chaîne de classification qui catégorise les avis pour un mois donné
# Code Python
month = 5
-- Requête SQL
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
Introduction à l'IA générative dans Snowflake

Appliquer 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 à l'IA générative dans Snowflake

Appliquer classify_text()

# Appliquer la classification au DataFrame
df["category"] = reviews["DESCRIPTION"].apply(classification)

# Afficher la catégorie prédite de la première ligne print(df["category"].head(1))
0    overall_experience  
Name: category, dtype: object
Introduction à l'IA générative dans Snowflake

Analyse de sentiment

  • Intérêt seulement pour le sentiment des avis

AI_SENTIMENT in a SQL cell

Introduction à l'IA générative dans Snowflake

Analyse de sentiment

AI_SENTIMENT - extraction d’un sentiment

$$

  • Sentiments possibles : positive, negative, neutral, mixed et unknown
Introduction à l'IA générative dans Snowflake

Passons à la pratique !

Introduction à l'IA générative dans Snowflake

Preparing Video For Download...