Open In App

Sentiment Analysis using VADER - Using Python

Last Updated : 10 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Sentiment analysis helps in finding the emotional tone of a sentence. It helps businesses, researchers and developers to understand opinions and sentiments expressed in text data which is important for applications like social media monitoring, customer feedback analysis and more. One widely used tool for sentiment analysis is VADER which is a rule-based tool. In this article, we will see how to perform sentiment analysis using VADER in Python.

What is VADER?

VADER (Valence Aware Dictionary and sEntiment Reasoner) is a sentiment analysis tool which is designed to analyze social media text and informal language. Unlike traditional sentiment analysis methods it is best at detecting sentiment in short pieces of text like tweets, product reviews or user comments which contain slang, emojis and abbreviations. It uses a pre-built lexicon of words associated with sentiment values and applies specific rules to calculate sentiment scores.

How VADER Works?

VADER works by analyzing the polarity of words and assigning a sentiment score to each word based on its emotional value. These individual word scores are then combined to calculate an overall sentiment score for the entire text.

It uses compound score which is a normalized value between -1 and +1 representing the overall sentiment:

  • Compound score > 0.05: Positive sentiment
  • Compound score < -0.05: Negative sentiment
  • Compound score between -0.05 and 0.05: Neutral sentiment

Implementation of Sentiment Analysis using VADER

Step 1: Installing the vaderSentiment Library

We need to install vaderSentiment library which is required for sentiment analysis. We can use the following command to install it:

pip install vaderSentiment

Step 2: Importing the SentimentIntensityAnalyzer Class

VADER uses the SentimentIntensityAnalyzer class for analyzing sentiment. This class provides the functionality to find sentiment scores of a given text.

Python
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

Step 3: Creating a Function to Calculate Sentiment Scores

The function sentiment_scores() will take a sentence as input and calculate the sentiment scores using VADER.

Python
def sentiment_scores(sentence):
    sid_obj = SentimentIntensityAnalyzer()
    sentiment_dict = sid_obj.polarity_scores(sentence)

    print(f"Sentiment Scores: {sentiment_dict}")
    print(f"Negative Sentiment: {sentiment_dict['neg']*100}%")
    print(f"Neutral Sentiment: {sentiment_dict['neu']*100}%")
    print(f"Positive Sentiment: {sentiment_dict['pos']*100}%")
    
    if sentiment_dict['compound'] >= 0.05:
        print("Overall Sentiment: Positive")
    elif sentiment_dict['compound'] <= -0.05:
        print("Overall Sentiment: Negative")
    else:
        print("Overall Sentiment: Neutral")

Step 4: Test the Sentiment Analysis Function

Now let’s check the sentiment_scores() function with some example sentences. We will call the function with different sentences to see how VADER analyzes the sentiment.

Python
if __name__ == "__main__":

    print("\n1st Statement:")
    sentence = "Geeks For Geeks is an excellent platform for CSE students."
    sentiment_scores(sentence)

    print("\n2nd Statement:")
    sentence = "Shweta played well in the match as usual."
    sentiment_scores(sentence)

    print("\n3rd Statement:")
    sentence = "I am feeling sad today."
    sentiment_scores(sentence)

Output : 

sentiments-using-vader
Result

Step 5: Understanding the Output

  • 1st Statement: The text has 20.7% negative, 51.9% neutral and 27.4% positive sentiment. The compound score of 0.4404 shows a positive sentiment.
  • 2nd Statement: With 0% negative, 47.1% neutral and 52.9% positive. The compound score of 0.5423 also shows a positive sentiment.
  • 3rd Statement: The text has 40.8% negative, 39.5% neutral and 19.7% positive with a compound score of -0.3818 indicating a negative sentiment.

VADER is a great tool for efficiently analyzing sentiment in various types of user-generated content which helps businesses and researchers to gain deeper insights into public opinions and emotions expressed in short-form texts.


Next Article
Article Tags :
Practice Tags :

Similar Reads