0% found this document useful (0 votes)
73 views5 pages

Twitter Sentiment Analysis Using Natural Language Toolkit and VADER Sentiment

This document discusses analyzing sentiment in tweets related to the 2016 US election using the Valence Aware Dictionary for sEntiment Reasoner (VADER) tool. It provides background on Twitter sentiment analysis and describes related work applying tools like VADER and LIWC to classify tweet sentiment. The document then outlines the method used to collect tweets, preprocess the data, and apply VADER for multiclass sentiment classification of tweets regarding the 2016 US presidential candidates.

Uploaded by

Nicholas Junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views5 pages

Twitter Sentiment Analysis Using Natural Language Toolkit and VADER Sentiment

This document discusses analyzing sentiment in tweets related to the 2016 US election using the Valence Aware Dictionary for sEntiment Reasoner (VADER) tool. It provides background on Twitter sentiment analysis and describes related work applying tools like VADER and LIWC to classify tweet sentiment. The document then outlines the method used to collect tweets, preprocess the data, and apply VADER for multiclass sentiment classification of tweets regarding the 2016 US presidential candidates.

Uploaded by

Nicholas Junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Proceedings of the International MultiConference of Engineers and Computer Scientists 2019

IMECS 2019, March 13-15, 2019, Hong Kong

Twitter Sentiment Analysis Using Natural


Language Toolkit and VADER Sentiment
Shihab Elbagir and Jing Yang

 messages called tweets [4]. Therefore, Twitter provides a


Abstract— The sentiment analysis of Twitter data has gained rich source of data that are used in the fields of opinion
much attention as a topic of research. The ability to obtain mining and sentiment analysis. Recently, the sentiment
information about a public opinion by analyzing Twitter data analysis of Twitter data has attracted the attention of
and automatically classifying their sentiment polarity has
attracted researchers because of the concise language used in
researchers in these fields. However, most state-of-the-art
tweets. In this study, we aimed to use the Valence Aware studies have used sentiment analysis to extract and classify
Dictionary for sEntiment Reasoner (VADER) to classify the information about the opinions expressed on Twitter
sentiments expressed in Twitter data. However, because most concerning several topics, such as predictions, reviews,
previous studies were oriented to binary classification, in this elections, and marketing.
study, we propose a multi-classification system for analyzing Currently, many tools, such as Linguistic Inquiry and
tweets. We used VADER to classify tweets related to the 2016
US election. The results showed good accuracy in detecting
Word Count (LIWC) [5], offer the means of extracting
ternary and multiple classes. advanced features from texts. However, most of these tools
require some programming knowledge. In the present work,
Index Terms— Natural Language Toolkit (NLTK), Twitter, the Valence Aware Dictionary and sEntiment Reasoner
sentiment analysis, Valence Aware Dictionary and sEntiment (VADER) [6] is used to determine the polarity of tweets and
Reasoner (VADER) to classify them according to multiclass sentiment analysis.
The remainder of this paper is structured as follows: section
2 provides a brief description of related studies in the
I. INTRODUCTION literature. In section 3, we present in detail the proposed

S OCIAL media technologies exist in several different


forms, such as blogs, business networks, photo sharing,
forums, microblogs, enterprise social networks, video
method, and we describe the tool used in this study. In
section 4, we discuss the results. In section 5, we conclude
and provide recommendations for future work.
sharing networks, and social networks. As the number of
social media technologies has increased, various online
social networking services, such as Facebook, YouTube, II. RELATED WORK
and Twitter, have become popular because they allow Recently, researchers have shown increasing interest in
people to express and share their thoughts and opinions the field of sentiment analysis, particularly regarding
about life events. Twitter data. The following are previous studies that have
These networks enable users to have discussions with contributed to the field of sentiment analysis in the past few
different people across the world and to post messages in the years. Wagh et al. [7] developed a general sentiment
forms of texts, images, and videos [1], [2]. Moreover, social classification system for use if no label data are available in
media are enormous sources of information for companies the target domain. In this system, labeled data in a different
to monitor the public opinion and receiving polls about the domain are used. Moreover, this system was used to
products they manufacture. Microblogging services have calculate the frequency of each term in a tweet. In this study,
become the best known and the most commonly used a dataset containing four million tweets that were publicly
platforms. Furthermore, they have evolved to become available by Stanford University was analyzed. This dataset
significant sources of different types of information [3]. was used to predict the polarity of sentiments expressed in
Twitter is a popular microblogging service that allows users people’s opinions. Traditional classification algorithms can
to share, deliver, and interpret real-time, short, and simple be used to train sentiment classifiers from manually labeled
text data, but the manually labeling work is expensive and
Manuscript received December 17, 2018; revised January 08, 2019. time-consuming. The study found that if a classifier trained
This work was supported by National Natural Science Foundation
of China (Nos. 61672179, 61370083, 61402126), Heilongjiang Province Na
in one domain is applied directly to other domains, the
tural Science Foundation of China (No. F2015030), Science Fund for Yout performance is extremely low. The work showed the
hs in Heilongjiang Province (No. QC2016083) and Postdoctoral Fellowship accuracy of different algorithms for different numbers of
in Heilongjiang Province (No. LBHZ14071). tweets, such as the following: Naive Bayes, Multi-nominal
Shihab Elbagir is now with the College of Computer Science and
Technology, Harbin Engineering University, Heilongjiang, 150001, China NB, Linear SVC, Bernoulli NB classifier, Logistic
(corresponding author phone: 187-046-00712; e-mail: shihabsaad@ Regression, and the SGD classifier. The results showed that
yahoo.com). He was with Faculty of Computer Science and Information the proposed system was more efficient than the existing
Technology, Shendi University, Shendi, Sudan
Jing Yang is with College of Computer Science and Technology, Harbin systems.
Engineering University, Heilongjiang, 150001, China (e-mail:
yangjing@hrbeu.edu.cn).

ISBN: 978-988-14048-5-5 IMECS 2019


ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online)
Proceedings of the International MultiConference of Engineers and Computer Scientists 2019
IMECS 2019, March 13-15, 2019, Hong Kong

Gilbert [6] developed VADER, which is a simple rule- publicly available raw tweets. To gather the data, we used
based model for general sentiment analysis and compared its Network Overview Discovery and Exploration for Excel
effectiveness to 11 typical state-of-the-practice benchmarks, (NodeXL) [10]. We collected a total of 2,430 political
including Affective Norms for English Words(ANEW), tweets concerning the 2016 US presidential election, which
Linguistic Inquiry and Word Count (LIWC), the General were published on Twitter’s public message board and
Inquirer, Senti WordNet, and machine learning-oriented posted from 22 to 24 November 2016. Also, NodeXL, set
techniques that rely on the Naive Bayes, Maximum Entropy, the limit to a maximum of 2,000 tweets, from which we
and Support Vector Machine (SVM) algorithms. The study obtained a reduced data set. In order to collect the most
described the development, validation, and evaluation of relevant tweets, we used hashtags containing the candidates’
VADER. The researcher used a combination of qualitative names, Hillary and Trump. These names and “Election”
and quantitative methods to produce and validate a were used as keywords to retrieve tweets, such as #Election
sentiment lexicon that is used in the social media domain. Day results, #US Election 2016, #Election 2016, #Hillary
VADER is utilizing a parsimonious rule-based model to Clinton, #Donald Trump.
assess the sentiment of tweets. The study showed that A tweet is a microblog message posted on Twitter. It is
VADER improved the benefits of traditional sentiment limited to 140 characters. Most tweets contain text and
lexicons, such as LIWC. VADER was differentiated from embed URLs, pictures, usernames, and emoticons. They
LIWC because it was more sensitive to sentiment also contain misspellings. Hence, a series of preprocessing
expressions in social media contexts, and it generalized steps were carried out to remove irrelevant information from
more favorably to other domains. the tweets. The reason is that the cleaner the data, the more
Mane et al. [8] presented a sentiment analysis using suitable they are for mining and feature extraction, which
Hadoop, which quickly processes vast amounts of data on a leads to the improved accuracy of the results. The tweets
Hadoop cluster in real time. The researchers aimed to were also preprocessed to eliminate duplicate tweets and re-
determine whether the users expressed a positive or negative tweets from the dataset, which led to a final sample of 1,415
opinion. This approach was focused on the speed of tweets. Each tweet was processed to extract its main
performing sentiment analysis of real-time Twitter data message. To preprocess these data, we used Python’s
using Hadoop. The Hadoop platform was designed to solve Natural Language Toolkit (NLTK). First, a regular
problems that involved large, unstructured, and complex expression (Regex) in Python was run to detect and discard
data. It used the divide and rule method for processing such tweets special characters, such as URLs (“http://url”),
data. The overall accuracy of the project was determined by retweet (RT), user mention (@), and unwanted punctuation.
the time required to access from various modules. In the Because hashtags (#) often explain the subject of the tweet
analysis, the code yielded outstanding accuracy. The study and contain useful information related to the topic of the
used a numbering approach to rate the statements in multi- tweet, they are added as a part of the tweet, but the “#”
classes, which assigned a suitable range of different symbol was removed.
sentiments. Moreover, the approach could be used in other Next, various functions of NLTK were used to convert
social media platforms, such as movie reviews (e.g., IMDB the tweets to lowercase, remove stop words (i.e., words that
reviews) and personal blogs. Along the same line, Bouazizi do not express any meaning, such as is, a, the, he, them,
and Ohtsuki [9] introduced SENTA, which helps users etc.), tokenize the tweets into individual words or tokens,
select from a wide variety of features those that are the best and stem the tweets using the Porter stemmer. When the
fit for the application used to run the classification. The preprocessing steps are complete, the dataset was ready for
researchers used SENTA to perform the multi-class sentiment classification.
sentiment analysis of texts collected from Twitter. The study In phase three, the sentiments expressed in the tweets
was limited to seven different sentiment classes. The results were classified. VADER Sentiment Analyzer was applied to
showed that the proposed approach reached an accuracy as the dataset. VADER is a rule-based sentiment analysis tool
high as 60.2% in the multi classification. This approach was and a lexicon that is used to express sentiments in social
shown to be sufficiently accurate in both binary media [6]. First, we created a sentiment intensity analyzer to
classification and ternary classification. categorize our dataset. Then the polarity scores method was
used to determine the sentiment. The VADER Sentiment
III. METHODOLOGY Analyzer was used to classify the preprocessed tweets as
positive, negative, neutral, or compound. The compound
value is a useful metric for measuring the sentiment in a
A. Proposed Method given tweet. In the proposed method, the threshold values
The current study consists of three phases. Phase one used to categorize tweets as either positive, negative, or
concerns the acquisition of Twitter data. Phase two focuses neutral. Typical threshold values used in this study are Refer
on the initial preprocessing work carried out to clean and to “(1)”:
remove irrelevant information from the tweets. Phase three
deals with the use of the NLTK’s VADER analyzer as well
Positive sentiment: compound value > 0.001, assign
as the scoring method applied to the VADER results to
assess its ability to classify tweets on a five-point scale. score = 1
As aforementioned that, the purpose of the data Neutral sentiment: (compound value > -0.001) and
acquisition phase was to obtain Twitter data. The methods
used to extract Twitter data allowed real-time access to (compound value < 0.001), assign score =0

ISBN: 978-988-14048-5-5 IMECS 2019


ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online)
Proceedings of the International MultiConference of Engineers and Computer Scientists 2019
IMECS 2019, March 13-15, 2019, Hong Kong

Negative sentiment: compound value < -0.001, text processing libraries for classification, tokenization,
stemming, tagging, parsing, and semantic reasoning [13].
assign score = -1 (1)
3) Valence Aware Dictionary and sEntiment Reasoner
(VADER)
In the current study, a tweet with a compound VADER is a lexicon and rule-based sentiment analysis
value greater than the threshold was considered a tool that is specifically attuned to the sentiments expressed
positive tweet, and a tweet with a compound value less than in social media. It is an entirely free open-source tool.
the threshold was considered a negative tweet. In the VADER also takes into consideration word order and degree
remaining cases, the tweet was considered neutral. Next, we modifiers [6].
defined a scoring rule to determine whether the overall
sentiment polarity in each tweet was in one of five classes: IV. RESULTS AND DISCUSSION
high positive, positive, neutral, negative, and high negative
The results of a Twitter sentiment analysis using NLTK
Refer to “(2)”. In the proposed method, the scoring rule is
and VADER sentiment analysis tools are discussed in this
used to classify tweets into five sentiment classes as follows:
section. Fig. 1 shows the sentiment score of each tweet as
positive, negative, neutral, or compound as obtained by the
Test the overall sentiment of the tweet.
VADER Sentiment Analyzer.
If (score value) = 1:
Calculate the overall tweet polarity as: [{'compound': -0.1531,
If (positive value > 0.5) assign tweet polarity = +2 'neg': 0.164,
Else: (positive value < 0.5) assign tweet polarity = +1 'neu': 0.714,
If (score value) = -1: 'pos': 0.121,
Calculate the overall tweet polarity as: 'tweet': 'presid anti trump tshi 24hr ship small red amazon
If (negative value > 0.5) assign tweet polarity = -2 2016elect election result im with'},
Else: (negative value < 0.5) assign tweet polarity = -1 {'compound': -0.5859,
If (score value = 0) assign tweet polarity = 0 (2) 'neg': 0.352,
'neu': 0.648,
The polarity value gives the overall sentiment polarity of 'pos': 0.0,
the tweet. The polarity value is set between -2 (highly 'tweet': 'wtf americain 5 word wtf trump protest trump
negative) to +2 (highly positive). Positive tweets are presid trump train election2016 election result 'elect'},
classified as highly positive or positive depending on the {'compound': 0.0,
'neg': 0.0,
positive value; negative tweets are classified as highly
'neu': 1.0,
negative or negative depending on the negative value; in
'pos': 0.0,
other cases, tweets are classified as neutral.
'tweet': 'ask unifi behind un repent bigot election result'}]

B. Tools Fig. 1. Sentiment score of tweets using the Vader

Table 1 shows the classification of the tweets as positive,


1) NodeXL
neutral, or negative after the thresholds were applied. As
NodeXL Basic is a free and open-source network
shown in Table 1, if we chose an appropriate threshold
analysis and visualization software package that is used with
value, we could categorize tweets directly as positive,
Microsoft Excel [10]. This popular package is similar to
negative, or neutral by using VADER.
other network visualization tools, such as Pajek, UCINET,
Table 2 shows the overall sentiment scores value and
and Gephi. NodeXL allows the quick and accessible
polarity of every tweet, depending on the scoring rule.
collection of social media data through a set of import tools
Table 3 displays the total number of tweets and the
that gather data from social networks, such as Flickr,
percentages of each class of the five sentiment
YouTube, Facebook, and Twitter. NodeXL focuses on the
classifications in this dataset. Based on the results shown in
collection of publicly available data, such as Twitter
Table 3, most tweets in our dataset expressed negative or
statuses, and it follows the relationships of users who have
neutral opinions about the presidential election. However,
made their accounts public. These features allow NodeXL
interestingly, 29% of the tweets expressed positive opinions,
users to instantly retrieve relevant social media data and
and 22.89% of the tweets expressed negative opinions. As
integrate aspects of these data and their analysis into one
shown in Table 3, 46.7% of the tweets expressed neutral
tool [11].
opinions, and 1.48% expressed highly negative opinions.
The neutral percentage was the highest among all other
2) Natural Language Toolkit(NLTK)
classes because of the small volume of tweets, which led to
unbalanced data, and the assumption that the threshold value
NLTK is a free open-source Python package that provides
could provide a large number of neutral opinions. Also may
several tools for building programs and classifying data.
have been based on the use of a general lexicon to
NLTK is suitable for linguists, engineers, students,
categorize the political data.
educators, researchers, and developers who work with
textual data in natural language processing and text analytics
[12]. NLTK provides an easy way to use the interfaces of
over 50 corpora and lexical resources. It includes a group of

ISBN: 978-988-14048-5-5 IMECS 2019


ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online)
Proceedings of the International MultiConference of Engineers and Computer Scientists 2019
IMECS 2019, March 13-15, 2019, Hong Kong

TABLE I
50

PERCENTAGE OF TWEETS
THE TWEETS CLASSIFICATION
40
30
tweet score
20
1 wtf americain 5 word wtf trump protest trump presid... -1
2 ask unifi behind unrepent bigot election result… 0 10
3 trump say support practic big otri need stop via… 1 0

TABLE II
OVERALL SENTIMENT POLARITY FOR EVERY TWEET
TWEETS CATEGORY
Tweets label Polarity

Highly
first ignor laugh fight win gandhi everi true +2
Positive Fig. 3. Sentiment Polarity Percentage for Tweets in each Category
When ev sad sorrow come watch conanobrien Highly
-2
elect... Negative
Unit state hay election 2016 election result ima... 0 Neutral Fig. 5 shows the frequency distributions of positive,
tom obama pardon Clinton way president trump el... +1 Positive negative, and neutral words respectively. Here we examine
play dead soon cat election result -1 Negative the pattern of words; the plots show that the majority of
words appear less.
TABLE III
POLARITY COUNT FOR EACH CLASS 800
NUMBERS OF TWEETS 700
Polarity label Count Percentage 600
500
Highly Positive +2 34 2.402827 400
positive +1 375 26.501767 300
neutral 0 661 46.713781 200
negative -1 324 22.897527 100
0
Highly negative -2 21 1.484099

Fig. 2 shows the most common words used in the dataset.


We can observe that most of top words deal with election TWEETS CATEGORY
result, Trump, Clinton, and vote.

Fig. 4. Sentiment Polarity Count for Tweets in each Category


POSITIVE WORD NEGATIVE WORD NEUTRAL WORD
DISTRIBUTIONS: DISTRIBUTIONS: DISTRIBUTIONS:
The findings of the present study suggest that the
VADER Sentiment Analyzer could be used to measure
[('election result', [('election result', [('election result', sentiments expressed in tweets and classify them
381), 321), 633), accordingly, thereby producing good results.
('election2016', 97), ('trump', 76), ('election2016',
('trump', 73), ('election2016', 178),
('elect', 45), 63), ('trump', 127),
('vote', 44), ('protest', 48), ('elect', 63),
('like', 33), ('elect', 41), ('vote', 52),
('amp', 33), ('amp', 32), ('clinton', 28),
('popular', 26), ('people', 28), ('amp', 28),
('win', 24), ('vote', 26), ('not my presid',
('support', 21)] ('hillari', 21), 26),
('riot', 21)] ('trump protest',
24),
('us', 22)]

Fig. 2. Most Common Words

The classification percentages of the sentiment analysis


based on polarity are shown in Fig. 3. Fig. 4 displays the (a) Frequency Distributions of Positive
sentiment counts in the tweets in each class.

ISBN: 978-988-14048-5-5 IMECS 2019


ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online)
Proceedings of the International MultiConference of Engineers and Computer Scientists 2019
IMECS 2019, March 13-15, 2019, Hong Kong

REFERENCES
[1] B. J. Jansen, M. Zhang, K. Sobel, and A. Chowdury, “Twitter power:
Tweets as electronic word of mouth,” J. Am. Soc. Inf. Sci. Technol.,
vol. 60, no. 11, pp. 2169–2188, 2009.
[2] V. Kharde and P. Sonawane, “Sentiment analysis of twitter data: a
survey of techniques,” arXiv Prepr. arXiv1601.06971, 2016.
[3] P. Selvaperumal and D. A. Suruliandi, “a Short Message
Classification Algorithm for Tweet Classification,” Int. Conf. Recent
Trends Inf. Technol., pp. 1–3, 2014.
[4] T. Singh and M. Kumari, “Role of Text Pre-processing in Twitter
Sentiment Analysis,” Procedia Comput. Sci., vol. 89, pp. 549–554,
2016.
[5] Y. R. Tausczik and J. W. Pennebaker, “The psychological meaning of
words: LIWC and computerized text analysis methods,” J. Lang. Soc.
Psychol., vol. 29, no. 1, pp. 24–54, 2010.
[6] C. J. H. E. Gilbert, “Vader: A parsimonious rule-based model for
sentiment analysis of social media text,” in Eighth International
Conference on Weblogs and Social Media (ICWSM-14). Available at
(20/04/16)
(b) Frequency Distributions of Negative http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf, 2014.
[7] B. Wagh, J. V Shinde, and P. A. Kale, “A Twitter Sentiment Analysis
Using NLTK and Machine Learning Techniques,” Int. J. Emerg. Res.
Manag. Technol., vol. 6, no. 12, pp. 37–44, 2018.
[8] S. B. Mane, Y. Sawant, S. Kazi, and V. Shinde, “Real Time
Sentiment Analysis of Twitter Data Using Hadoop,” Int. J. Comput.
Sci. Inf. Technol., vol. 5, no. 3, pp. 3098–3100, 2014.
[9] M. Bouazizi and T. Ohtsuki, “A Pattern-Based Approach for Multi-
Class Sentiment Analysis in Twitter,” IEEE Access, vol. 3536, no. c,
pp. 1–21, 2017.
[10] M. A. Smith et al., “Analyzing (social media) networks with
NodeXL,” in Proceedings of the fourth international conference on
Communities and technologies, 2009, pp. 255–264.
[11] D. L. Hansen, B. Shneiderman, and M. A. Smith, Analyzing social
media networks with NodeXL: Insights from a connected world.
Morgan Kaufmann, 2010.
[12] S. Bird, E. Klein, and E. Loper, Natural language processing with
Python: analyzing text with the natural language toolkit. “ O’Reilly
Media, Inc.,” 2009.
[13] Natural Language Toolkit http://www.nltk.org/ (Date Last Accessed,
November 20, 2018).
(c) Frequency Distributions of Neutral

Fig. 5. Frequency Distributions of Positive, Negative, and Neutral


Words

V. CONCLUSION
In this study, the NLTK and the VADER analyzer were
applied to conduct a sentiment analysis of Twitter data and
to categorize tweets according to a multi-classification
system. The case study was the 2016 US presidential
election. The results indicated that the VADER Sentiment
Analyzer was an effective choice for sentiment analysis
classification using Twitter data. VADER easily and quickly
classified huge amounts of data. However, the present study
has the following limitations. First, a small volume of data
was used. Second, a general lexicon was used to categorize
specific data. Third, the data were not trained. In future
work, we will improve our system by using large volumes of
data, a specific lexicon, and a corpus for training the data to
obtain good results.

ISBN: 978-988-14048-5-5 IMECS 2019


ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy