Sentiment Analysis

Overview

Sentiment analysis classifies text as having positive or negative overall sentiment, and is commonly used in customer support, market research, finance, etc. Click on a buttons below to get started with the Excel or Sheets extension.

Apps

Both of these apps currently use simple classification models as outlined below.

Classification Models

Traditional sentiment analysis is performed using transformer machine learning models which have been trained on datasets (e.g. movie reviews, tweets, etc.) where the sentiment (e.g. positive, negative) has been labeled by human annotators. The accuracy of the model depends on how similar your text is to the data the model was trained on. The pretrained sentiment analysis models currently available are shown in the table below:

Name Model Training Data Output Labels Language
Movie Reviews distilbert-base-uncased-finetuned-sst-2-english Movie review phrases from the Stanford Sentiment Treebank dataset. Positive, Negative English
Finance News finbert Financial phrases from the financial phrasebank dataset. Positive, Negative, Neutral English
Twitter Messages twitter-roberta-base-sentiment-latest ~124M tweets from the TweetEval dataset. Positive, Negative, Neutral English
Product Reviews bert-base-multilingual-uncased-sentiment Trained on multilingual product reviews. 1 - 5 stars English, Dutch, German, French, Spanish, and Italian

Note the following limitations:

  • Accuracy: Sentiment analysis is far from an exact science. The presence of sarcasm, irony, negation, and emojis often confuses sentiment analysis models and leads to errors.
  • Text length: The models have a maximum input length of about 500 tokens (400 words), so any additional text may be truncated. Sentence splitting may be a workaround for this limitation.
  • Accuracy: Sentiment analysis is far from an exact science. The presence of sarcasm, irony, negation, and emojis often confuses sentiment analysis models and leads to errors.
  • Text length: The models have a maximum input length of about 500 tokens (400 words), so any additional text may be truncated. Sentence splitting may be a workaround for this limitation.
  • Language: The models are mostly trained on English text, except where noted, so the accuracy of sentiment analysis will be lower for other languages.

Aspect-Based Sentiment Analysis

Aspect-based sentiment analysis (ABSA) is a more advanced form of sentiment analysis that identifies the sentiment of specific aspects or entities within a text. For example, in the sentence “The food was great, but the service was terrible”, the aspects are “food” and “service”, and the sentiment is positive for “food” and negative for “service”. The following tools can be used for aspect-based sentiment analysis:

  • Azure AI Language provides sentiment analysis and opinion mining at the document, sentence, and aspect levels. For more details on how we implemented sentiment analysis using Azure AI Services, see our blog post.

  • InstructABSA is an instructional learning approach for Aspect-Based Sentiment Analysis. It can be used to run inference on your datasets directly or be trained from scratch. The tool can classify sentiment at the aspect level, providing detailed sentiment analysis.

  • SetFit is a framework for few-shot fine-tuning of Sentence Transformers. It achieves high accuracy with minimal labeled data and is efficient for sentiment analysis tasks, making it a suitable choice for integrating sentiment analysis into various applications.

An example output of aspect-based sentiment analysis using the Azure AI Language service is shown in the figure below.

flowchart TD
    Doc["Document: 'The **food** and **service** were **unacceptable**. The **concierge** was **nice**, however.'<br>Sentiment: mixed<br>pos:0.3 neu:0.17 neg:0.52"]
    
    Doc --> S1[Sentence: 'The **food** and **service** were **unacceptable**.'<br>Sentiment: negative<br>pos:0.0 neu:0.0 neg:1.0]
    Doc --> S2[Sentence: 'The **concierge** was **nice**, however.'<br>Sentiment: positive<br>pos:0.61 neu:0.35 neg:0.05]
    
    S1 --> A1[Aspect: **food**<br>Sentiment: negative<br>pos:0.01 neg:0.99]
    S1 --> A2[Aspect: **service**<br>Sentiment: negative<br>pos:0.01 neg:0.99]
    S2 --> A3[Aspect: **concierge**<br>Sentiment: positive<br>pos:1.0 neg:0.0]
    
    A1 --> O1[Opinion: **unacceptable**<br>Sentiment: negative<br>pos:0.01 neg:0.99]
    A2 --> O2[Opinion: **unacceptable**<br>Sentiment: negative<br>pos:0.01 neg:0.99]
    A3 --> O3[Opinion: **nice**<br>Sentiment: positive<br>pos:1.0 neg:0.0]

    style Doc fill:#f9f,stroke:#333,stroke-width:2px
    style S1 fill:#bbf,stroke:#333,stroke-width:2px
    style S2 fill:#bbf,stroke:#333,stroke-width:2px
    style A1 fill:#bfb,stroke:#333,stroke-width:2px
    style A2 fill:#bfb,stroke:#333,stroke-width:2px
    style A3 fill:#bfb,stroke:#333,stroke-width:2px
    style O1 fill:#fbf,stroke:#333,stroke-width:2px
    style O2 fill:#fbf,stroke:#333,stroke-width:2px
    style O3 fill:#fbf,stroke:#333,stroke-width:2px

Applications

  • Customer Support: Automatically categorize incoming support tickets as positive, negative, or neutral.
  • Market Research: Analyze social media posts to gauge public sentiment about a product or service.
  • Finance: Monitor news articles for sentiment about a company or industry.
  • Education: Analyze student feedback to improve course content and delivery.
  • Healthcare: Analyze patient feedback to improve services and patient outcomes.

Cloud Services

If you need to integrate sentiment analysis into a real-time workflow (e.g. analyze sentiment of support tickets for routing), you’ll need to use an API which processes the text and returns the sentiment analysis results.

The open source models we use in our tools are downloaded from Hugging Face, which provides a large collection of pre-trained models for natural language processing tasks, including sentiment analysis. They also offer Inference Endpoints whereby the same models can be used via API. This is a good option if you want to use the same models we use in our tools, but need to integrate them into your own applications.

Here are some additional API providers which offer sentiment analysis: