cd /news/natural-language-processing/sentiment-analysis-using-vader · home › topics › natural-language-processing › article
[ARTICLE · art-162104] src=dev.to ↗ pub= topic=natural-language-processing verified=true sentiment=↑ positive

Sentiment Analysis using VADER

A developer demonstrated a sentiment-analysis pipeline that uses NLTK's VADER lexicon and rule-based scorer to classify IMDB movie reviews from a CrowdFlower dataset as positive, negative or neutral. The workflow lowercases text, strips English stopwords, tokenizes sentences, and derives neg, neu, pos and compound scores, then maps compound values to labels using thresholds of 0.05 and -0.05.

by read3 min views1 publishedNov 1, 2026

Sentiment Analysis is a supervised Machine Learning technique used to determine if a chunk of text is positive, negative or neutral. In text analytics, natural

language processing (NLP) and machine learning (ML) techniques are combined to assign sentiment scores to topics, categories or entities within a phrase.

Sentiment analysis is a powerful tool that businesses can leverage to better understand the overall opinions of their customer, gain insights and make

data-driven decisions.

In this tutorial we will classify text articles using VADER on a dataset from CrowdFlower

import pandas as pd
import nltk
from nltk.corpus import stopwords
from nltk.probability import FreqDist
from nltk.tokenize import sent_tokenize, RegexpTokenizer
from nltk.sentiment.vader import SentimentIntensityAnalyzer
nltk.download('stopwords')
nltk.download('vader_lexicon')
nltk.download('punkt')

For the sake of this tutorial we’re going to use a simple dataset from CrowdFlower via data.world (IMDB Sentiment Sampled).

For more info visit the link: | https://data.world/robbertb/imdb-sentiment-sampled

The NLTK module is a massive tool kit, aimed to help you with the entire Natural Language Processing (NLP) methodology.

NLTK will aid you with everything from splitting sentences from paragraphs, splitting up words, recognizing the part of speech of those words.

In order to apply polarity score we need to prepare your data, we start by the converting our data to lowercase using the built-in function “lower”.

df['review'] = df['review'].apply(lambda txt: txt.lower())

Removing stop word using NLTK by down the english stopwords.

stop_words=stopwords.words('english')
df['review'] = df['review'].apply(lambda txt: ' '.join([word for word in txt.split() if word not in stop_words]))

Sentences Tokenization

df['review'] = df['review'].apply(lambda txt: sent_tokenize(txt))

Join the tokenized data into text.

df['review'] = df['review'].apply(lambda txt: ' '.join(txt))

VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed

in social media.

It is used for sentiment analysis of text which has both the polarities i.e. positive/negative. VADER is also used to quantify how much positive or negative

emotion the text has and also the intensity of emotion.

The VADER library returns 4 values such as:

Notice that the pos, neu and neg probabilities add up to 1. Also, the compound score is a very useful metric in case we want a single measure of sentiment.

Typical threshold values are the following:

Instantiate a new object with NLTK SentimentIntensityAnalyzer

sid = SentimentIntensityAnalyzer()

Now we can create a new column to the original DataFrame to store the polarity_scores dictionary, the scores extracted will have the keys “neg”, “neu”, “pos”,

“compound” derived from the composite score.

df['score'] = df['review'].apply(lambda txt: sid.polarity_scores(txt))
df['negative'] = df['score'].apply(lambda txt: txt['neg'])
df['neutral'] = df['score'].apply(lambda txt: txt['neu'])
df['positive'] = df['score'].apply(lambda txt: txt['pos'])
df['compound'] = df['score'].apply(lambda txt: txt['compound'])

We will follow by creating a function called “polarity_score” to calculate the accuracy test for each review in our dataframe. We can finally apply the function

by creating a new column called “sentiment”.

The reviews in this column will be classified into positive, negative and neutral.

def polarity_score(compound):
    if compound > 0.05:
        return "positive"
    elif compound < -0.5:
        return "negative"
    elif compound >= -0.05 and compound < 0.05:
        return "neutral"

df['sentiment'] = df['compound'].apply(lambda val: polarity_score(val))
df.head()
df['sentiment'].value_counts()

VADER classifies the sentiments very well. It is easy to use, the ready-made model which can be used across multiple domains, social-media texts.

Thanks for reading and happy web scraping everyone!

You can find my Jupyter Notebook for this on my Github.

Thank you for reading! ❤️

── more in #natural-language-processing 4 stories · sorted by recency
── more on @vader 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/sentiment-analysis-u…] indexed:0 read:3min 2026-11-01 · —