Introduction to Generative AI in Snowflake
James Cha-Earley
Senior Developer Advocate, Snowflake
$$
$$
$$
$$
classify_text()
# Define categories
categories = ["overall_experience", "location", "staff", "food_beverages",
"facilities"]
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"
}
print(type(category))
<class 'str'>
import json
category_dict = json.loads(category)
print(type(category_dict))
<class 'dict'>
# Python code
month = 5
-- SQL query
SELECT *
FROM HOTELS.REVIEWS
WHERE EXTRACT(month FROM date) = '{{month}}'
df = cell2.to_pandas()
def classification(text): result = classify_text( str_input=text, categories=labels ) result_dict = json.loads(result) return result_dict["label"]
# 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
$$
positive
, negative
, neutral
, mixed
, and unknown
Introduction to Generative AI in Snowflake