The objective of this assignment is to reproduce and extend the sentiment analysis example presented in Chapter 2, Sentiment Analysis with Tidy Data, of Text Mining with R by Julia Silge and David Robinson.
The first part of the assignment will reproduce the sentiment analysis workflow demonstrated in the book using text from Jane Austen’s novels. This analysis will apply three established sentiment lexicons: Bing, NRC, and AFINN. The goal is to understand how tidy text mining techniques can be used to identify and examine sentiment patterns in literary works.
The second part will extend the original analysis by applying the same techniques to a different text corpus: the IMDb Movie Reviews dataset. In addition to the three original sentiment lexicons, the Syuzhet sentiment lexicon will be incorporated to provide another perspective on sentiment classification.
By analyzing two different types of text and comparing multiple sentiment lexicons, this assignment will demonstrate how sentiment analysis results can vary depending on the nature of the text and the sentiment dictionary used.
The primary reference for this assignment is Chapter 2, “Sentiment Analysis with Tidy Data,” from Text Mining with R: A Tidy Approach by Julia Silge and David Robinson.
The chapter introduces important techniques for performing sentiment analysis using tidy text principles. These include:
The original Jane Austen example will serve as the foundation for the first part of this assignment. The implementation and visualizations will follow the methodology presented in the chapter, with appropriate references to the book and its supporting online materials included in the final report.
For the second part of the assignment, I will use the IMDb Movie Reviews dataset, which contains approximately 50,000 movie reviews classified as either positive or negative.
The dataset is available from Kaggle:
https://www.kaggle.com/datasets/lakshmi25npathi/imdb-dataset-of-50k-movie-reviews
The dataset contains two primary variables:
This dataset is appropriate for sentiment analysis because it contains a large collection of opinion-based text. Unlike literary works, where sentiment may change gradually throughout a narrative, movie reviews generally express direct opinions about movies.
The existing positive and negative labels will also provide an opportunity to evaluate how closely lexicon-based sentiment analysis agrees with the original classifications.
For reproducibility, a copy of the dataset will be uploaded to my GitHub repository. The Quarto report will access the dataset through its raw GitHub URL, allowing the analysis to be executed without manually importing the file.
The assignment will be divided into two major parts.
The first part will follow the methodology presented in Chapter 2 of Text Mining with R.
The planned steps are:
unnest_tokens().This section will establish a baseline for understanding how tidy text mining techniques can be used to analyze sentiment in literary text.
The second part will apply the same sentiment analysis approach to the IMDb Movie Reviews dataset.
The planned steps are:
unnest_tokens().The extension will help determine whether sentiment lexicons designed for general English text perform similarly when applied to movie reviews.
Data preparation will follow tidy text mining principles throughout both parts of the assignment.
For the Jane Austen novels, the original text will be organized by book and divided into individual word tokens. The book identifier and word position will be retained so that sentiment changes can be examined throughout each novel.
For the IMDb dataset, the review text will be converted into individual word tokens. The original review classification will be preserved so that the sentiment analysis results can be compared against the actual positive or negative labels.
The data preparation process will include:
Because sentiment dictionaries do not contain every word in the English language, some words will not match any lexicon. Differences in vocabulary coverage will be considered when interpreting the results.
The analysis will also distinguish between word-level sentiment scores and overall review classifications. This is important because a review may contain both positive and negative language, even when its original classification is clearly positive or negative.
Four sentiment lexicons will be used in this assignment.
The Bing lexicon classifies words into two sentiment categories: positive and negative. It will be used to identify the balance of positive and negative language in both Jane Austen’s novels and the IMDb reviews.
The NRC lexicon identifies positive and negative sentiment as well as eight emotional categories: anger, anticipation, disgust, fear, joy, sadness, surprise, and trust. It will provide a broader understanding of the emotions expressed in the text.
The AFINN lexicon assigns numerical sentiment scores to words, generally ranging from -5 to +5. Negative values indicate negative sentiment, while positive values indicate positive sentiment. These scores will be used to calculate overall sentiment values.
The Syuzhet lexicon provides another method for identifying sentiment in text. It will be incorporated as an additional lexicon to examine whether using a different sentiment dictionary produces results similar to or different from those obtained with Bing, NRC, and AFINN.
Comparing these four lexicons will help demonstrate how different approaches to sentiment classification can influence the interpretation of the same text.
The assignment will examine sentiment patterns in both literary text and movie reviews.
For the Jane Austen novels, I expect to observe changes in sentiment throughout the narrative. These changes may reflect different events, character interactions, conflicts, and developments in the stories.
For the IMDb movie reviews, I expect the sentiment patterns to be more directly associated with reviewers’ opinions. Positive reviews may contain a greater proportion of positive words, while negative reviews may contain more negative words.
The comparison will focus on three main areas:
The analysis will compare sentiment patterns in Jane Austen’s novels with those found in IMDb movie reviews. This will demonstrate how sentiment analysis behaves differently when applied to literary narratives and opinion-based reviews.
The Bing, NRC, AFINN, and Syuzhet lexicons will be compared to determine whether they produce consistent sentiment results. Differences may occur because the lexicons use different vocabularies, scoring methods, and classification approaches.
Because the IMDb dataset includes original positive and negative labels, the lexicon-based results can be evaluated against these classifications.
For example, I will examine whether reviews labeled positive generally receive higher sentiment scores than reviews labeled negative. I will also consider the percentage of reviews for which the lexicon-based predictions agree with the original labels.
This comparison will provide a practical evaluation of the strengths and limitations of dictionary-based sentiment analysis.
The expected outcome is a reproducible Quarto report that demonstrates the application of tidy text mining techniques to two different text collections.
The completed report will:
Overall, this assignment will demonstrate that sentiment analysis is influenced by both the characteristics of the text being analyzed and the sentiment lexicon selected. It will also illustrate the advantages and limitations of using dictionary-based methods to analyze natural language.
Kaggle. (n.d.). IMDb dataset of 50K movie reviews. https://www.kaggle.com/datasets/lakshmi25npathi/imdb-dataset-of-50k-movie-reviews
Robinson, D., & Silge, J. (n.d.). Sentiment analysis with tidy data. Text Mining with R. https://www.tidytextmining.com/sentim
Silge, J., & Robinson, D. (2017). Text mining with R: A tidy approach. O’Reilly Media. https://www.tidytextmining.com/