Sentiment task-specific AI functions

Snowflake Cortex AI offers two task-specific functions that provide the ability to easily perform sentiment analysis on text data such as customer comments or reviews.

ENTITY_SENTIMENT delivers both overall and granular entity-specific sentiment. It is ideal for use cases that require sentiment analysis for specific aspects of the text, or that require nuanced identification of sentiment: positive, negative, neutral, and mixed. For example:

  • Detailed product analysis

  • Comprehensive brand perception studies

  • Advanced market intelligence

  • Customer experience journey mapping

SENTIMENT returns a numeric sentiment score that identifies the degree negativity or positivity. It’s designed for use cases that prioritize speed and cost-effectiveness over granular entity-level analysis, such as:

  • Social sentiment monitoring and alerting

  • High-volume customer feedback triage

  • Content performance scanning

Sentiment quality

ENTITY_SENTIMENT delivers industry-leading aspect based and overall sentiment accuracy. The following table provides information on how popular models perform on the Aspect Based Sentiment (ABSA-mix) and Overall Sentiment benchmarks, including the models offered by Snowflake as well as other popular models.


Function or model
Aspect Based Sentiment
Accuracy (ABSA-mix)

Overall Sentiment Accuracy

Cortex AI ENTITY_SENTIMENT

0.91

0.86

claude-3-5-sonnet

0.84

0.72

mistral-large2

0.83

0.77

GPT-4 [*]

0.82

0.73

llama3.3-70b

0.81

0.72

llama3.1-8b

0.77

0.79

Cortex AI SENTIMENT

n/a

0.71

Tip

If you’e unsure which function is best for your needs, start with ENTITY_SENTIMENT to establish a baseline. Then try SENTIMENT to see whether the additional granularity and nuance provided by ENTITY_SENTIMENT is necessary for your use case.

ENTITY_SENTIMENT

Cortex AI ENTITY_SENTIMENT captures a spectrum of customer opinions beyond overall positive, negative, and neutral buckets. For aspect-based sentiment analysis, specify the content (such as a customer comment or a review) and the entities (aspects or categories) for which you want to analyze sentiment. ENTITY_SENTIMENT returns sentiment scores for each entity as well as an overall sentiment score.

The following example uses ENTITY_SENTIMENT to get the sentiment classification of a product review.

SELECT SNOWFLAKE.CORTEX.ENTITY_SENTIMENT('A tourist\'s delight, in low urban light,
  Recommended gem, a pizza night sight.  Swift arrival, a pleasure so right,
  Yet, pockets felt lighter, a slight pricey bite. 💰🍕🚀',
  ['Cost', 'Quality', 'Waiting Time']);
Copy

Response:

{
  "categories": [
    {
      "name": "overall",
      "sentiment": "mixed"
    },
    {
      "name": "Cost",
      "sentiment": "negative"
    },
    {
      "name": "Quality",
      "sentiment": "positive"
    },
    {
      "name": "Waiting Time",
      "sentiment": "positive"
    }
  ]
}

The following example “passes through” entities unrelated to the content of the product review, Professionalism and Brand, and classifies them as “unknown”.

SELECT SNOWFLAKE.CORTEX.ENTITY_SENTIMENT('A tourist\'s delight, in low urban light,
  Recommended gem, a pizza night sight. Swift arrival, a pleasure so right,
  Yet, pockets felt lighter, a slight pricey bite. 💰🍕🚀',
  ['Cost', 'Professionalism' ,'Brand']);
Copy

Response:

{
  "categories": [
    {
      "name": "overall",
      "sentiment": "mixed"
    },
    {
      "name": "Brand",
      "sentiment": "unknown"
    },
    {
      "name": "Cost",
      "sentiment": "negative"
    },
    {
      "name": "Professionalism",
      "sentiment": "unknown"
    }
  ]
}

If you want only the overall sentiment, specify the content without analysis entities.

SELECT SNOWFLAKE.CORTEX.ENTITY_SENTIMENT('I went to the store, bought the leggings and exact same as shorts...
  they are expensive but i heard such great things. After wearing them twice i noticed a string popping out already.
  And aince i believed that they were this amazing luxury brand i didnt keep the receipt 😭 ');
Copy

Response:

{
  "categories": [
    {
      "name": "overall",
      "sentiment": "mixed"
    }
  ]
}

SENTIMENT

The Cortex AI SENTIMENT function returns overal sentiment as a score between -1.0 to 1.0t. The closer to 1, the the more likely that the text has positive sentiment; the the closer to -1 the more likely the text has negative sentiment. The chart below provides guidance on how to interpret the sentiment scores:

Sentiment

Sentiment Score

Positive

0.5 to 1

Neutral

-0.5 to 0.5

Negative

-0.5 to -1

The following example uses SENTIMENT to get the sentiment classification of a food service review, which we can infer as positive given the probability score of 0.54.

SELECT SNOWFLAKE.CORTEX.SENTIMENT('A tourist\'s delight, in low urban light,
  Recommended gem, a pizza night sight. Swift arrival, a pleasure so right,
  Yet, pockets felt lighter, a slight pricey bite. 💰🍕🚀');
Copy

Response:

0.5424458

Model restrictions

All models available in Snowflake Cortex AI have limitations on the total number of input and output tokens, which is referred to as the model’s context window.

The Context Window for ENTITY_SENTIMENT is set such that the model can sustain a high level of accuracy. For more context, ENTITY_SENTIMENT was trained and optimized for text inputs of 2,048 tokens (roughly 1,600 words), and you can pass a maximum of 10 entity categories, each no greater than 30 characters.

Note

ENTITY_SENTIMENT and SENTIMENT are currently optimized for English.

Function

Context Window (tokens)

Max Entity Labels

ENTITY_SENTIMENT

2,048

10

SENTIMENT

512

n/a

Regional availability

ENTITY_SENTIMENT and SENTIMENT are available in the following regions:

Function
(Model)
AWS US West 2
(Oregon)
AWS US East 1
(N. Virginia)
AWS Europe Central 1
(Frankfurt)
AWS Europe West 1
(Ireland)
AWS AP Southeast 2
(Sydney)
AWS AP Northeast 1
(Tokyo)
Azure East US 2
(Virginia)
Azure West Europe
(Netherlands)
AWS
(Cross-Region)

ENTITY_SENTIMENT

SENTIMENT