Tutorial: Sentiment Analysis in Communalytic

Sentiment Analysis

The Sentiment Analysis module in Communalytic is designed to detect the polarity of posts in your dataset; that is, to determine if posts in your dataset express neutral, negative, or positive sentiments. To calculate the polarity scores, this module uses two popular sentiment analysis libraries: VADER and TextBlob. Posts in English will be analyzed by both VADER and TextBlob. Posts in French or German will only be analyzed by TextBlob.

These lexicon-based libraries were selected for the following reasons:

  • They have been empirically validated and used by many other researchers;
  • They have been shown to work across different domains;
  • They are sufficiently fast and easy to integrate within a web application like Communalytic.

Both libraries analyze text based on a set of predefined dictionaries and rules to assign the polarity scores between -1 and 1:

  • Polarity scores close to 0 (usually between -0.05 and 0.05) represent neutral sentiments.
  • Negative polarity scores (-0.05 or lower) represent negative sentiments. 
  • Positive polarity scores (0.05 or above) represent positive sentiments.

Which polarity scores should you use in your study: VADER’s or TextBlob’s?

Note: Posts in English will be analyzed by both VADER and TextBlob. Posts in French or German will only be analyzed by TextBlob. Posts in other languages are currently not supported by these two sentiment analysis libraries and will be skipped.

In general, if your dataset consists of mostly English language posts, we suggest using VADER’s scores since VADER has been shown to slightly outperform TextBlob (at least in one study). Also, in comparison to Textblob, VADER is more widely cited with over 7k citations versus about 2.6k citations for TextBlob. Furthermore, in a separate study that compared 24 different sentiment analysis methods (not including TextBlob), VADER was among the top three sentiment analysis algorithms for classifying the sentiments of social media posts.

However, the accuracy of any algorithm can vary from dataset to dataset, if your dataset consists of mostly English language posts, we also suggest examining all or a sample of the polarity scores produced by both libraries to cross-validate results. Doing this exercise will help you to determine which of the two sentiment analysis algorithms is more accurate at detecting polarity of posts in your particular dataset. To accomplish this, download the dataset after the sentiment analysis is complete, and then use either Excel or Google Sheet to manually review cases where VADER and TextBlob disagree, especially in cases where posts were assigned opposite polarity scores. 

How to use the Sentiment Analysis Module in Communalytic

The step-by-step instructions below will show you how to use the Sentiment Analysis module in Communalytic.

Step 1:  To start the Sentiment Analysis module, go to the My Datasets page and click on the meter icon under the column called “Sentiment Analysis”.

For this tutorial, we’ll use a small sample dataset of 2567 posts and replies from a public subreddit dedicated to Marvel Studios and the Marvel Cinematic Universe called r/Marvelstudios.

Step 2: On the next screen, click “Start Analysis”.

Step 3: Once the analysis has begun, you can monitor the progress using the progress bar screen. You may close this window and visit it later to review/download the results.

Step 4: Once the analysis is complete, the results will be displayed as the summary table showing the counts of negative, neutral and positive posts based on the calculated polarity scores. Following Bonta et al. (2019), polarity scores close to 0 (between -0.05 and 0.05) represent neutral sentiments, negative polarity scores (-0.05 or lower) represent negative sentiments, and positive polarity scores (0.05 or above) represent positive sentiments.

Note: Depending on your use case and research questions, you can set your own thresholds to determine how to translate polarity scores (from -1 to +1) into sentiment labels (neutral, negative or positive). Here is an example of how you can calculate the “optimal” thresholds with your own dataset (See “Step #5: Evaluate the sentiment analysis results”).

The polarity scores are also displayed as a distribution chart (see below). VADER’s scores are shown in the green color and TextBlob’s scores are in the purple color. From this chart we can see that most of the posts express positive sentiments. We know this because the distribution of polarity scores are skewed to the right and the majority of posts (~50%) were assigned the polarity score of 0.05 or above.

In addition, for posts in English, the results page provides a so-called Confusion Matrix showing both agreement and disagreement counts across sentiment labels as determined by VADER and TextBlob (see below).

Step 5: To download the dataset with the polarity scores, navigate to the “Download Dataset” section and then click on the “Download CSV File” button. 

Step 6:  After the CSV file has been downloaded, you will be able to access and see different scores generated by the two sentiment analysis libraries. 

In addition to storing the two polarity scores with values between -1 and +1 (‘textblob_polarity‘ and ‘vader_sentiment_compound‘), the file will also include separate values for VADER’s neutral, negative and positive scores. They are included in the downloaded file in the interest of completeness and in case some researchers might want them. The values are:

  • vader_sentiment_neutral (ranging from 0 to 1), values closer to 1 indicate the presence of a neutral sentiment;
  • vader_sentiment_negative (ranging from 0 to 1), values closer to 1 indicate the presence of a negative sentiment;
  • vader_sentiment_positive (ranging from 0 to 1), values closer to 1 indicate the presence of a positive sentiment;

VADER combines these three scores (vader_sentiment_positive,  vader_sentiment_neutral, vader_sentiment_negative) to produce a normalized polarity score (vader_sentiment_compound) on a single scale from -1 (negative sentiment) to +1 (positive sentiment). It is this normalized ‘vader_sentiment_compound’ score that Communalytic uses to compare and contrast against the related ‘textblob_polarity‘ score generated by TextBlob. 

Posts written in a non-supported language (not in English/French/German) will have “N/A” under the sentiment analysis-related columns. As a reminder, Textblob and VADER can only analyze posts in English, while TextBlob also supports posts in French and German.

Step 7: (Optional) Depending on your research, you can also choose to visualize and explore the polarity scores using Communalytic’s built-in Network Visualizer. To do this , go to the Network Analysis module and generate a network. Once the network is generated, click on the “Visualize Network” button.

Important: If you have already created a network from the data in your dataset prior to running the Sentiment Analysis, you will need to remove the previously generated network file by clicking on the “Reset Network File” button first.

Step 8: The Sentiment Analysis filter is available under the Node and Edge Filter tab in the Control Panel on the right side of the screen. Use this filter to hide edges outside a specified range of VADER’s or Textblob’s polarity scores as shown below.

To adjust the Sentiment Analysis filter, slide the squares to the desired range between -100 (likely negative posts) and 100 (likely positive posts). This filter will then hide posts (represented as edges in the network) outside the specified range of the polarity scores.

You may notice that while the actual polarity scores are between -1 and 1, for the network visualization we scale this range to [-100, 100]. This is to make it easier for users to select a desired range with the available interface elements.