Sentiment dictionaries
1. Sentiment dictionaries
While word counts and visualizations suggest something about content, we can do more. In this chapter, we move beyond word counts alone to analyze the sentiment or emotional valence of text. The most straightforward way to conduct sentiment analysis is to use an existing sentiment lexicon or dictionary.2. Bing dictionary
The tidytext package includes four distinct sentiment dictionaries that can be accessed with the get_sentiments() function. The only argument is the name of the dictionary. Here we print the “bing” dictionary. As you can see, the sentiment dictionary is a tibble composed of two columns: the words in the dictionary and the sentiment that each word has been tagged with.3. Bing dictionary
We summarize the “bing” dictionary using a count() of sentiment. Here we see that there are more than twice the count of negative words in the "bing" dictionary than positive words.4. Afinn dictionary
The second dictionary is the “afinn” dictionary. Instead of each word being tagged as negative or positive, they are given a numeric score with a negative score indicating negative sentiment and a positive score indicating positive sentiment.5. Afinn dictionary
We summarize the “afinn” dictionary by calculating the min and max. We can see the scale goes from -5 to positive 5.6. Loughran dictionary
The third dictionary is the “loughran” dictionary. We summarize this dictionary by using count(), mutate(), and fct_reorder() so we can plot the sentiment counts in descending order. Here we use coord_flip() and, instead of ggtitle(), we use the labs() layer so we can change not just the title but also the labels for the x and y axis.7. Loughran dictionary
Here we can see that the “loughran” dictionary has not just negative and positive but a number of other sentiments that are used to tag each word. While negative is by far the most common sentiment in this dictionary, we also see very interesting sentiments like "litigious" and “superfluous”.8. Let's practice!
Each of these dictionaries was painstakingly created for specific uses, so your mileage using any one of them may vary depending on your text. There is one more sentiment dictionary included with the tidytext package. Let's explore it in the exercises!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.