In this Quickstart guide, you will be help the fictitious food truck company, Tasty Bytes, to identify where their customer experience may be falling short at the truck and business level by leveraging Snowflake Cortex. The company gathers customer reviews across multiple sources and languages to assess their food truck operations. This comprehensive feedback helps them identify areas for improvement, ultimately boosting customer satisfaction and loyalty. Leveraging Snowflake Cortex's advanced language AI capabilities, they can automatically process reviews through real-time translation, generate actionable insights through intelligent summarization, and analyze customer sentiment at scale – transforming diverse, unstructured feedback into strategic business decisions that drive their food truck operations forward.

Prerequisites

What You'll Need

You will need the following things before beginning:

What You'll Learn

In this quickstart, you will learn:

What You'll Build

Overview

You will use Snowsight, the Snowflake web interface, to:

Creating Objects, Loading Data, and Joining Data

Overview

You will use Snowsight, the Snowflake web interface, to create Snowflake notebook by importing notebook.

Overview

You will leverage Translate - one of the Snowflake Cortex specialized LLM functions are available in Snowpark ML:

Hear what your international customers are saying

This is done within the notebook using following code snippet in cell CORTEX_TRANSLATE.

Python

# Conditionally translate reviews that are not english using Cortex Translate
reviews_df = reviews_df.withColumn('TRANSLATED_REVIEW',when(F.col('LANGUAGE') != F.lit("en"), \
                                                            cortex.Translate(F.col('REVIEW'), \
                                                                            F.col('LANGUAGE'), \
                                                                            "en")) \
                                  .otherwise(F.col('REVIEW')))

reviews_df.filter(F.col('LANGUAGE') != F.lit("en")).select(["REVIEW","LANGUAGE","TRANSLATED_REVIEW"]).show(3)

SQL

 -- Add the TRANSLATED_REVIEW column with conditional translation
 WITH TRANSLATED_REVIEWS AS (
     SELECT 
         REVIEW,
         LANGUAGE,
         CASE 
             WHEN LANGUAGE != 'en' THEN SNOWFLAKE.CORTEX.TRANSLATE(REVIEW, LANGUAGE, 'en') 
             ELSE REVIEW
         END AS TRANSLATED_REVIEW
     FROM TRUCK_REVIEWS_V
 )

 -- Filter rows where the LANGUAGE is not English and select the desired columns
 SELECT 
     REVIEW, 
     LANGUAGE, 
     TRANSLATED_REVIEW
 FROM TRANSLATED_REVIEWS
 WHERE LANGUAGE != 'en'
 LIMIT 3;

Overview

In this section, you will leverage Snowflake Cortex LLM - Summarize to quickly understand what the customers are saying:

We want to get a insight on what people are saying

Python

  summarized_reviews_df = session.table("CONCATENATED_REVIEWS").select(
      F.col("TRUCK_BRAND_NAME"),
      cortex.Summarize(F.col("ALL_REVIEWS_TEXT")).alias("SUMMARY")
  )

  summarized_reviews_df.select(["TRUCK_BRAND_NAME", "SUMMARY"]).show(3)

SQL

  -- Generate summaries for each truck brand
  WITH SUMMARIZED_REVIEWS AS (
      SELECT 
          TRUCK_BRAND_NAME,
          SNOWFLAKE.CORTEX.SUMMARIZE(ALL_REVIEWS_TEXT) AS SUMMARY
      FROM CONCATENATED_REVIEWS
  )

  SELECT * FROM SUMMARIZED_REVIEWS;

Overview

In this section, you will make use of Snowflake Cortex LLM - ClassifyText to categories reviews to understand:

Get intention to recommend based on review with Cortex ClassifyText

Python

# To understand whether a customer would recommend food truck based on their review 
text_description = """
Tell me based on the following food truck customer review, will they recommend the food truck to \
their friends and family? Answer should be only one of the following words - \
"Likely" or "Unlikely" or "Unsure".
"""

reviews_df = reviews_df.withColumn('RECOMMEND', cortex.ClassifyText(F.col('REVIEW'),["Likely","Unlikely","Unsure"], test_description))\
.withColumn('CLEAN_RECOMMEND', when(F.contains(F.col('RECOMMEND'), F.lit('Likely')), \
                                                            F.lit('Likely')) \
                                      .when(F.contains(F.col('RECOMMEND'), F.lit('Unlikely' )), \
                                                            F.lit('Unlikely')) \
            .when(F.contains(F.col('RECOMMEND'), F.lit('Unsure' )), \
                                                            F.lit('Unsure')))

reviews_df.select(["REVIEW","CLEAN_RECOMMEND"]).show(3)

SQL

WITH CLASSIFIED_REVIEWS AS (
  SELECT 
      REVIEW,
      PARSE_JSON(SNOWFLAKE.CORTEX.CLASSIFY_TEXT(
          REVIEW, 
          ['Likely', 'Unlikely', 'Unsure'], 
          OBJECT_CONSTRUCT('task_description', 
              'Tell me based on the following food truck customer review, will they recommend the food truck to their friends and family?'
          )
      )):label::TEXT AS RECOMMEND
  FROM TRUCK_REVIEWS_V
)

SELECT * From CLASSIFIED_REVIEWS limit 3;

Overview

In this section, you will leverage Snowflake Cortex LLM - Complete to get answers to your specific questions:

Answer specific questions you have

Python

  question = "What is the number one dish positively mentioned in the feedback?"

  summarized_reviews_df = session.table("CONCATENATED_REVIEWS").select(
      F.col("TRUCK_BRAND_NAME"),
      cortex.Complete(
          "mistral-large2",
          F.concat(
              F.lit("Context: "),
              F.col("ALL_REVIEWS_TEXT"),
              F.lit(f" Question: {question} Answer briefly and concisely and only name the dish:")
          )
      ).alias("NUMBER_ONE_DISH")
  )

  summarized_reviews_df.show(3)

SQL

  -- Gain Learnings from a specific question
  WITH GAIN_LEARNINGS AS (
      SELECT 
          TRUCK_BRAND_NAME,
          SNOWFLAKE.CORTEX.COMPLETE(
          'mistral-large2', 
          'Context:' || ALL_REVIEWS_TEXT || ' Question: What is the number one dish positively mentioned in the feedback? Answer briefly and concisely and only name the dish:'
      ) AS NUMBER_ONE_DISH
      FROM CONCATENATED_REVIEWS
  )
  SELECT TRUCK_BRAND_NAME, NUMBER_ONE_DISH FROM GAIN_LEARNINGS LIMIT 3;

Overview

Next, you will look at another task specific LLM function in Cortex - Sentiment.

Understand sentiment with Cortex Sentiment

Python

# Understand the sentiment of customer review using Cortex Sentiment
reviews_df = reviews_df.withColumn('SENTIMENT', cortex.Sentiment(F.col('REVIEW')))

reviews_df.select(["REVIEW","SENTIMENT"]).show(3)

SQL

SELECT 
    REVIEW, 
    SNOWFLAKE.CORTEX.SENTIMENT(REVIEW) AS SENTIMENT
FROM TRUCK_REVIEWS_V
LIMIT 3;

Congratulations! You've mastered powerful customer analytics using Snowflake Cortex, processing multilingual reviews and extracting valuable insights – all while maintaining data security within Snowflake's ecosystem. By leveraging these built-in AI capabilities, you've eliminated the complexity of managing external infrastructure while keeping sensitive customer feedback protected within Snowflake's secure environment.

What we've covered

With the completion of this quickstart, you have now:

Related Resources

Want to learn more about the tools and technologies used in this quickstart? Check out the following resources: