HamiltonGPT: Exploring the musical with sentiment analysis
Hamilton was one of the greatest musicals of all time. Much has been said about it already, I want to reorient the critical gaze by looking at it through the lens of sentiment analysis & data science
Hamilton was first released on Disney+ during India's intermittent lockdown phase. I, casually wanting to make my lunch hour TV time enjoyable, decided to watch this musical instead of rewatching the usual soap drama. Twenty minutes in, I shut it. I got a taste of something magnificent and made the call that it does not deserve to be screened on a little 13' laptop screen. With this call, I also made the promise to only watch it in its most authentic form – At Broadway in New York City. I don't know if it was due to the magnificence of the moment, or was it one of those dramatic promises one makes to themselves when life gets too mundane.
Anyway, I only slightly deviated from the promise. I discovered the original soundtrack on Spotify, which became my daily pluck from the gingerbread house. With each song, I inadvertently tried to piece together America's struggle for independence and the exciting lives of its founding fathers in a unique blend of hip-hop and rap.
The pandemic summer was also when I discovered many of my intellectual interests. I learned R, a programming language that social scientists love but economists hate, and all the cool things I could do with this tool in my kit. One of those was sentiment analysis of text. With this, one can mathematically summarize the emotions that evoke while reading books or any text for that matter. So, in this essay, I want to find the intersection of my musings during the pandemic by performing sentiment analysis on the lyrics of the musical 'Hamilton'.
If you are math-anxious, listen up: Sentiment analysis is a love story between statistics and literature. It does not take away from the lived experience of humans but adds to it the mathematical prowess of machines to discern patterns which would otherwise be overlooked. I will also be explaining the process of sentiment analysis while I analyze this masterpiece with data science.
Hamilton is a total of 45 different songs which amounts to 20729 words. The process of sentiment analysis starts with tokenizing words, which means breaking sentences into chunks of single words. Then we remove all the stop words from the corpus which do not convey a sentiment. For example: 'a' 'an' and conjunctions like 'and' 'for' 'so'.
After getting the corpus ready, we match it with an English language emotional lexicon called 'AFINN'. AFINN is a compilation of words and its sentiment. These words are classified as either 'positive emotion' or 'negative emotion'. Apart from this classification, it also gives a polarity score for the emotion. For example: 'I am happy' will yield a score of +3, and 'I am ecstatic' will yield a score of +5.
After running this library against the Hamilton Corpus, we get the most used positive and negative words. The y-axis count is the polarity score multiplied by the number of times that particular word has occurred in the text. So, these charts show the top 10 words that drive the musical's positive and negative sentiments, respectively.
Spoiler Alert: The Musical is the to-be founding fathers’ struggle for independence from the British. So it is no surprise, but interesting, that Freedom makes the cut for the top 10 words driving positive sentiment in the musical.
The word, or more aptly, the emotion, ‘love’, ranks 4th. This might be gesturing towards phrases where the speakers emote love for the country. Here are few lines where love is used
King George: I will send a fully armed battalion to remind you of my love!
Hamilton: My love, take your time
I’ll see you on the other side
Raise a glass to freedom…
Interestingly, words associated with conflict (die, died, war, fight) yield the highest negative emotion (see plot 2 in Figure 1). This might suggest that even though the statesmen knew that the revolution would be brutal and bloody, the intense negative emotion around these words show that the real costs of war weren't lost on them.
Now, in the interest of expressing and understanding more emotions, let’s explore Hamilton using the NRC emotion lexicon.
The NRC emotion lexicon is similar to AFINN. Still, instead of quantifying only binary emotions like AFINN, it allows us to explore a broader range of emotional states like ‘disgust’, ‘joy’, ‘anticipation’, etc. To better identify the words that are driving emotions in the essay, the algorithm also inspects the surrounding words and phrases.
For example, in the sentence, ‘Akshar has been feeling very motivated off-late', ‘Akshar’ will be assigned a ‘joy’ sentiment. Although ‘Akshar’ does not convey any emotion in the English language per se, the words surrounding it are associated with the ‘joy’ emotion in the NRC lexicon.
When looking at the words that evoke ‘disgust’, it is more funny than interesting to note that Congress ranks first in the list. I guess feelings of anti-establishment also date back to the struggle for American freedom. It could be the case that the disdain toward Congress arises from the bureaucratic chaos it is/was. And many of these words are from the song ‘Cabinet Battle #1’; the title sufficiently explains this phenomenon, doesn't it? Here are a few verses from that song.
Hamilton: What happens if I don't get congressional approval?
Hamilton: I lose my job if we don't get this plan through Congress
The word, or rather the name, 'John', seems to contribute to the feelings of disgust in this musical. This can be attributed to Alexander Hamilton's heavy critique of President John Adams's administration. Let's look at a few verses which might place this emotion into some context.
Hamilton: Angelica, tell my wife John Adams doesn't have a real job anyway
Hamilton: Sit down, John, you fat mother-BLEE
Jefferson: John Adams shat the bed. I love the guy, but he's in traction
Given the emotional valence of the verses above, Gen-Z would classify this as a ‘diss’. Maybe these words were inspired by the 2020 Presidential Debates. BTW there is a whole song dedicated to John Adams’ administration in the musical called The Adams Administration. That song can really be a new episode in YouTube’s Epic Rap Battles.
When we classify a movie or a book as gripping, dull, or neutral, a lot of it is driven by the variance of emotions we experience during the length of it. Some movies begin on a very positive note and maintain that range of emotion. For some books, the plot thickens at the end so we would notice a lot of emotional variance during the end of the story. But, as humans, we only have recall at our disposal, and due to hindsight bias, fading memory, partial recall, and other fun proclivities, we can’t objectively know the emotional timeline of a book/movie/song.
So, in the interest of discovering some patterns in Hamilton which humans can’t, I calculated the net emotion in each song of the musical and plotted it in the same timeline as the musical. In the graph below, each bar shows the net sentiment of each song chronologically.

Looking at the crests and the troughs, we notice that the musical overall is more positive than negative. We see high variance in the first 15 songs; after that, it tapers down. The musical does not have an emotional climactic end, at least none that our algorithm can detect. The song with the highest negative sentiment is titled Helpless – no shit, Sherlock. And the one with the most heightened positive emotion is titled ‘The Schuyler Sisters’.
Much has been written about Hamilton by critics, scholars and bloggers. Still, with this analysis, I aimed to reorient the critical gaze by looking for implicit patterns using statistics. The stats convey much about the musical that would have been impervious to the human senses.
The sentiment analysis process becomes challenging when the written word is stylized by idiomatic expressions, dated references, and narratorial consciousness. Such was the case with Hamilton. So, it was difficult to make inferences without being sufficiently cognizant of the context. I had to revisit the songs and look for lyrics and keywords manually to understand the nuance of each result. Without context, sentiment analysis would have only offered a partial or even an inaccurate understanding of Hamilton.
So, by combining human senses and sentiment analysis, what emerges is more than the sum of parts – it is more than math + romance. It bridges the gap between cold hard numbers and the richness of human expression.
Never thought I'd see something like this! Exciting read. I would love to see better visualizations and have fun writing the CS-y parts a bit. Amazing read!