Implementing Sentiment Analysis with quanteda

Learn how to use three popular lexicons to perform sentiment analysis in quanteda.

We'll cover the following

Sentiment analysis is a natural language processing technique used to determine the sentiment or emotional tone behind a piece of text. It involves analyzing the words, phrases, or sentences in text to understand whether the overall sentiment expressed is positive, negative, or neutral.

AFINN, NRC, and ANEW are three popular lexicons commonly used in sentiment analysis to assign sentiment scores to words. These lexicons contain predefined lists of words along with their associated sentiment scores.

AFINN

AFINN is a sentiment lexicon that assigns a numerical sentiment score to each word. The scores range from -5 to +5, where negative scores indicate negative sentiment and positive scores indicate positive sentiment. The AFINN lexicon is based on human ratings of words in terms of sentiment. For example, the word “good” might have a positive score of +3, while “bad” might have a negative score of -2. These values are referred to as the valence of the word. To calculate the sentiment score of a text, we sum up the scores (valence) of all the words in the text.

The AFINN sentiment dictionary is a list of precomputed sentiment scores for English words and phrases. It was created by Finn Årup Nielsen in 2011 and is widely used in natural language processing (NLP) and sentiment analysis tasks.

Get hands-on with 1200+ tech skills courses.