Last Updated : 11 Jul, 2025
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:
We need to install vaderSentiment library which is required for sentiment analysis. We can use the following command to install it:
Step 2: Importing the SentimentIntensityAnalyzer Classpip install vaderSentiment
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 :
Result Step 5: Understanding the OutputVADER 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4