Sentiment extraction¶
Note
AI_SENTIMENT is the updated version of ENTITY_SENTIMENT (SNOWFLAKE.CORTEX). For the latest functionality, use AI_SENTIMENT.
The AI_SENTIMENT function provides state-of-the-art quality sentiment classification across diverse markets and languages. With AI_SENTIMENT, you can get both overall and granular, aspect based sentiment analysis for use cases like the following:
Social media monitoring
Detailed product analysis
Comprehensive brand perception studies
Advanced market intelligence
Employee engagement analysis
Customer experience journey mapping
Content performance analysis
Customer support optimization
Sentiment extraction quality¶
AI_SENTIMENT uses a custom Snowflake large language model that delivers industry-leading overall sentiment and aspect-based sentiment accuracy. The following table provides information on how AI_SENTIMENT performs on Overall Sentiment and Aspect Based Sentiment (ABSA-mix) benchmarks compared to popular models. The languages evaluated in the multilingual benchmark are English, Spanish, French, German, Hindi, Italian, and Portuguese.
Note
Some of the models benchmarked are not available in Snowflake Cortex.
Model
|
Aspect based sentiment
accuracy (
ABSA-mix) |
Aspect based sentiment
accuracy (
ABSA-multilingual) |
Overall sentiment
accuracy
|
Overall sentiment
accuracy (multilingual)
|
|---|---|---|---|---|
Cortex AI |
0.92 |
0.81 |
0.83 |
0.83 |
|
0.84 |
0.79 |
0.75 |
0.82 |
|
0.83 |
0.80 |
0.77 |
0.78 |
|
0.83 |
0.73 |
0.80 |
0.78 |
|
0.82 |
0.79 |
0.71 |
0.76 |
|
0.82 |
0.79 |
0.71 |
0.76 |
AWS |
0.62 |
0.64 |
Calling the AI_SENTIMENT function¶
By default, Cortex AI_SENTIMENT returns overall sentiment scores for the overall content. However, AI_SENTIMENT can also capture a spectrum of customer opinions beyond overall positive, negative, and neutral buckets. For this optional aspect-based sentiment analysis, specify the content (such as a customer comment or a review) and the aspects (also called entities or categories) for which you want to analyze sentiment. AI_SENTIMENT returns sentiment for each entity as well as an overall sentiment. To obtain only the overall sentiment, specify the content without aspects.
English examples¶
The following example uses AI_SENTIMENT to get the sentiment classification of a product review.
Return value:
The following example uses AI_SENTIMENT to get the sentiment classification for specific aspects of a restaurant review.
Return value:
If some aspects that you specify do not apply to the text you provide, AI_SENTIMENT returns “unknown” for those aspects, as shown for Professionalism and Brand in the following example.
Return value:
Multilingual examples¶
As shown in the following two similar examples, AI_SENTIMENT can analyze sentiment in multiple languages, so you don’t need to translate the text and risk losing an essential part of its meaning. You do not need to specify the language of the text. Aspects can be specified in the language of the text, as shown in the following example, or in English, as shown in the second example.
Note
AI_SENTIMENT supports English, French, German, Hindi, Italian, Spanish, and Portuguese.
Example with both text and labels in Spanish:
Return value:
Example with text in German and labels in English:
Return value:
Model restrictions¶
All large language models (LLMs) 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. Inputs exceeding the context window limit result in an error. Output which would exceed the context window limit is truncated.
The context window for AI_SENTIMENT is set such that the model can sustain a high level of accuracy. AI_SENTIMENT was trained and optimized for text inputs of 2,048 tokens (roughly 1,600 words). You can specify a maximum of ten aspects, each no longer than thirty characters.
Function |
Context window (tokens) |
Maximum number of entity labels |
|---|---|---|
AI_SENTIMENT |
2,048 |
10 |