Developing a tweet sentiment classification model

To develop a tweet sentiment classification model, we need labels for each tweet. However, getting labels that accurately reflect tweet sentiment is challenging. Let's take a look at some existing lexicons for sentiment classification and see why it isn't easy to get appropriate labels. With just five tweets, it isn't possible to develop a sentiment classification model. However, the idea here is to look at the process of arriving at an appropriate label for each tweet. This will help us appreciate the challenges involved in obtaining accurate labels. To automatically extract sentiment scores for each tweet, we will make use of the syuzhet package. We will also make use of commonly used lexicons for this purpose. The National Research Council (NRC) lexicon helps capture various emotions based on certain words. We will use the following code to obtain a sentiment score for the five tweets:

library(syuzhet) 
get_nrc_sentiment(tweets)
anger anticipation disgust fear joy sadness surprise trust negative positive
1 1 0 0 1 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0
3 1 1 1 1 1 1 1 0 1 1
4 0 1 0 0 0 0 0 0 0 0
5 1 0 0 0 0 0 0 0 1 0

The first tweet results in a score of 1 for both anger and fear. Although it contains the word 'bearish', if we were to read this tweet, we would determine that it's actually positive.

Let's look at the following code, which contains sentiment scores for the words 'bearish', 'death', and 'animated':

get_nrc_sentiment('bearish') 
anger anticipation disgust fear joy sadness surprise trust negative positive
1 1 0 0 1 0 0 0 0 0 0

get_nrc_sentiment('death')
anger anticipation disgust fear joy sadness surprise trust negative positive
1 1 1 1 1 0 1 1 0 1 0

get_nrc_sentiment('animated')
anger anticipation disgust fear joy sadness surprise trust negative positive
1 0 0 0 0 1 0 0 0 0 1

From the preceding code, we can determine the following:

  • The overall score for the first tweet is based on the word italics, and nothing else.
  • The third tweet has a score of 1 for each category except trust.
  • From reading the tweet, it is obvious to us that the person writing this tweet actually feels that animated emojis will be positive for Apple and will be negative for Snapchat.
  • The sentiment scores are based on two words in this tweet: death and animated. They fail to capture the real sentiment that's expressed in the third tweet, which is very positive for Apple.

When we manually label each of the five tweets with a negative sentiment, which is represented by 0, and a positive sentiment, which is represented by 1, we are likely to arrive at 1, 0, 1, 1, and 1 for our scores. Let's use the following code to arrive at these sentiment scores by using the syuzhet, bing, and afinn lexicons:

get_sentiment(tweets, method="syuzhet")
[1] 0.00 0.80 -0.35 0.00 -0.25

get_sentiment(tweets, method="bing")
[1] -1 0 -1 -1 0

get_sentiment(tweets, method="afinn")
[1] 4 0 -2 0 0

Looking at results from the syuzhet, bing, and afinn lexicons, we can observe the following:

  • The results vary significantly from the actual sentiments contained in the tweets. Thus, trying to automatically label a tweet with an appropriate sentiment score is difficult.
  • We saw that automatically labeling text sequences is a challenging problem. However, one solution is to label a very large number of text sequences, such as tweets, manually and then use that to develop a sentiment classification model.
  • In addition, it is important to note that such a sentiment classification model will only be helpful for the specific types of text data that were used to develop the model.
  • It isn't possible to use the same model for different text sentiment classification applications.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset