VADER_SENTIMENT
Overview
The VADER_SENTIMENT
function performs sentiment analysis on text using the VADER (Valence Aware Dictionary and sEntiment Reasoner) lexicon, which is specifically attuned to sentiments expressed in social media. VADER is a rule-based model that combines a sentiment lexicon with five heuristics to account for punctuation, capitalization, degree modifiers, conjunctions, and negation. For more details, see the official VADER documentation .
This implementation uses the NLTK package, which provides a Python interface to the VADER algorithm. For more information, see the NLTK documentation .
The final sentiment is calculated as a normalized, weighted composite score called the compound score, which ranges from -1 (most negative) to +1 (most positive). This score is computed as follows:
where is the sum of valence scores and is a normalization constant (default ).
This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=VADER_SENTIMENT(text)
text
(string, required): The text to analyze.
The function returns a single value (float): the compound sentiment score between -1 (most negative) and +1 (most positive), or 0.0 for invalid or empty input.
Examples
Example 1: Positive Product Review
Input:
Text |
---|
I absolutely love this product! It exceeded all my expectations and I would highly recommend it to anyone. |
Excel formula:
=VADER_SENTIMENT("I absolutely love this product! It exceeded all my expectations and I would highly recommend it to anyone.")
Expected output:
Compound Score |
---|
0.8214 |
Example 2: Negative Customer Feedback
Input:
Text |
---|
The customer service was terrible. I waited for hours and my issue was never resolved properly. |
Excel formula:
=VADER_SENTIMENT("The customer service was terrible. I waited for hours and my issue was never resolved properly.")
Expected output:
Compound Score |
---|
-0.56 |
Example 3: Neutral Business Statement
Input:
Text |
---|
Our company will be conducting the annual inventory count on June 15th. All departments will participate as scheduled. |
Excel formula:
=VADER_SENTIMENT("Our company will be conducting the annual inventory count on June 15th. All departments will participate as scheduled.")
Expected output:
Compound Score |
---|
0.0 |
Example 4: Mixed Sentiment
Input:
Text |
---|
While the product quality is excellent, the shipping was delayed which was disappointing. |
Excel formula:
=VADER_SENTIMENT("While the product quality is excellent, the shipping was delayed which was disappointing.")
Expected output:
Compound Score |
---|
-0.1027 |
Python Code
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
nltk.download('vader_lexicon')
def vader_sentiment(text):
"""
Analyze sentiment of text using VADER.
Args:
text: The text to analyze (string).
Returns:
The compound sentiment score (float) between -1 (most negative) and +1 (most positive), or 0.0 for invalid or empty input.
This example function is provided as-is without any representation of accuracy.
"""
if not isinstance(text, str) or not text.strip():
return 0.0
sia = SentimentIntensityAnalyzer()
sentiment = sia.polarity_scores(text)
return round(sentiment['compound'], 4)
Live Notebook
Edit this function in a live notebook .