An Analysis of Red Hot Chili Pepper’s Lyrics Using NLP

source

I heard Red Hot Chili Peppers for the first time about 10 years ago and I instantly became obsessed with them. They were (and still are) my #1 favorite band, right after Metallica, which I loved during my teenage years. Despite the fact that many people define RHCP as a typical “funk” band, their musical style has evolved over the years significantly. Early (pre-1999) RHCP’s songs stood out by their explosive slap bass riffs, while post-1999 Peppers had become more melancholic. Does the same relationship hold for their lyrics though? In this blog I will apply common NLP techniques to answer this question (full code is available at my GitHub).

For this analysis I crawled azlyrics.com and downloaded RHCP’s lyrics, organized by album. This resulted in every album from 1984 to 2016:

# sort albums by year
albums = sorted([d for d in os.listdir(os.curdir) if os.path.isdir(d) and d.endswith(‘)’)],
key=lambda x: re.search(“(\d{4})”, x).group(0))
albums

We’ll begin with typical text preprocessing steps. For this analysis I removed punctuation, converted to lower case, removed English stop-words and lemmatized the words. The reason why I chose lemmatization over stemming is simple: to preserve the meaning of the words so I can examine them later. In projects where the meaning doesn’t matter that much, however, we can apply stemming.

To start off, let’s display the number of unique words per album:

Looks like Stadium Arcadium is the most sophisticated album because it uses the most number of unique words! Or is it? Let’s weight them by the total word length

Let’s visualize them too

Now it doesn’t look so unambiguous anymore. In fact, the unique / total goes down from One Hot Minute to I’m With You! This is interesting, because RHCP produced their best songs during that era, arguably of course. Take a look at their discography rankings on Wikipedia. From Californication on, they absolutely dominated all the charts across different countries. Looks like they didn’t use too many different words to write amazing music though.

By The Way, if you’re wondering how I plotted this — it’s simply seaborn package with ‘fivethirtyeight’ style.

Now let’s take a look at the most used words, by total count, per album

Too bad. Lots of uninformative words, such as “get”, or “know”. Although some songs are clearly recognizable (e.g. “party”, “want”, “pussy” from Special Secret Song Inside). Let’s add a level of sophistication and apply TF-IDF.

For TF-IDF, I concatenate each song into a single string for each album.

tfidf = TfidfVectorizer(preprocessor=None, stop_words=None)
X = tfidf.fit_transform(tfidf_corpus)
X.A.shape

We have 12 rows, one per album and 4k unique words. The following code will generate top-5 words with the highest TF-IDF scores, per album:

vocab = {v: k for k, v in tfidf.vocabulary_.items()}
vocab = sorted(vocab.items(), key=lambda x: x[1])
vocab_df = pd.DataFrame(X.A, columns=[c[1] for c in vocab], index=albums)

May I say I LOVE the fact that the word “californication” finally appeared on Californication album! The way it should be. Looks like TF-IDF picked up on at least 3 different songs in Stadium Arcadium: Hump de Bump, Readymade, and Torture Me. We also have the word “funky” appearing for Mother’s Milk. Does it mean it’s the funkiest album? Well, I don’t know about you, but Mother’s Milk was the first album that I heard from RHCP back in the day. In fact, if you’re interested, check out my video where I played all the popular bass riffs from that album:

Anyway, TF-IDF clearly helped us to gain some insights about each album. Although useful, we would love for something that would generalize and pick up an overarching theme from each album, and TF-IDF clearly cannot do that. So how about LDA?

The main problem with LDA (or feature, depending on how you look at it) is that LDA needs lots of data to separate topics well. In fact, this paper claims the following:

The number of documents plays perhaps the most important role; it is theoretically impossible to guarantee identification of topics from a small number of documents, no matter how long.

Looks like our 12 albums won’t cut it. So let’s split them back into individual songs and hope for the best.

from gensim.corpora.dictionary import Dictionary
import gensim

Sometimes it’s useful to generate various n-grams for LDA — it just works better this way. “New_York” makes more sense rather than “New” and “York”.

bigram = gensim.models.Phrases(lda_corpus, min_count=5, threshold=100)
trigram = gensim.models.Phrases(bigram[lda_corpus], min_count=5, threshold=100)
bigram_mod = gensim.models.phrases.Phraser(bigram)
trigram_mod = gensim.models.phrases.Phraser(trigram)
lda_corpus = [trigram_mod[bigram_mod[doc]] for doc in lda_corpus]

Let’s naively assume that every album has that “overarching theme” and that LDA can separate them perfectly into topics (I know, I know). We set the num_topics to 12:

from gensim.models.ldamulticore import LdaMulticore
from gensim.models import CoherenceModel

Is it a lot? Well, let’s examine the topics themselves:

from pprint import pprint

I don’t know about you, but I cannot figure out which one is which. It’s definitely not separating them based on the albums. Rather, it’s separating them based on the songs again — take a look at topic 10 for example.

LDA has 3 main hyperparameters: number of topics, alpha, and eta. Let’s tune them and see if we can get something meaningful. I use skopt for hyperparameter tuning, with Bayesian optimization using Gaussian Processes. We’ll do 100 iteration and see if we can improve on that coherence score.

from skopt.space import Real, Integer, Categorical
from skopt.utils import use_named_args
from skopt import gp_minimize

Well, looks like RHCP cover more than 12 topics in their songs (duh…). Also, our coherence score went up! Let’s train the model with these parameters and visualize our results

I use t-SNE for visualization, which compresses multi-dimensional data into the required # of dimensions (in our case — 2). Each color represents a separate topic. It looks like one category dominates a lot! Let’s plot them by their frequency

Category 0 and 4 are the most common. What are their corresponding words?

(0,'0.016*"know" + 0.016*"get" + 0.015*"love" + 0.014*"like" + 0.011*"make" + '
'0.011*"want" + 0.010*"say" + 0.010*"come" + 0.009*"go" + 0.009*"take"')
(4,'0.032*"get" + 0.009*"time" + 0.008*"love" + 0.007*"come" + 0.007*"give" + '
'0.006*"know" + 0.006*"good" + 0.006*"tell" + 0.006*"say" + 0.005*"right"')

Hmm… it still doesn’t look too different to me. May be ~190 documents is still too small of a number for LDA to separate topics. In fact, when I don’t set the random state, every time LDA generates a different set of topics, which suggest that ~190 documents is not enough for it to converge. Finally, let’s plot the topics for each album and see if we can spot any trends

Looks like early Peppers were pretty diverse in terms of their lyrics. We can see more categories for the early albums, and only 2 for their The Getaway.

Here are some other topics LDA generated:

(11,
'0.003*"king" + 0.003*"minor" + 0.003*"repeat" + 0.002*"backwoods" + '
'0.002*"yertle_turtle" + 0.002*"otherside" + 0.002*"throw" + '
'0.002*"television" + 0.002*"turtle" + '
'0.002*"dream_californication_dream_californication"')
(13,
'0.004*"blood" + 0.004*"well" + 0.003*"true_men_kill_coyote" + 0.003*"yeah" + '
'0.002*"feel" + 0.002*"true_men" + 0.002*"gon_na" + 0.002*"hollywood_hill" + '
'0.002*"dig_dirt_dig_dust" + 0.002*"paisley_dragon_hollywood_hill"')
(2,
'0.002*"stretch" + 0.001*"love" + 0.001*"dirty" + 0.001*"stain" + '
'0.001*"bird" + 0.001*"thirty" + 0.001*"earthworm" + 0.001*"burping" + '
'0.001*"chirp" + 0.001*"curb"')

Finally, let’s check one theory. When Anthony Kiedis was discussing the recording of Stadium Arcadium album, he said the following about their hit “Dany California” (watch from 0:30):

Basically, when writing “Dani California”, Anthony realized that it’s actually a continuation of a story he started earlier in “Californication” (1999) and continued in “By The Way” (2002). Let’s see if these 3 songs share any similarities in terms of lyrics!

scat_new = scat.copy()
scat_new.loc[:, ‘Label’] = “None”
scat_new.loc[89, ‘Label’] = ‘Californication’
scat_new.loc[109, ‘Label’] = ‘By The Way’
scat_new.loc[131, ‘Label’] = ‘Dani California’

They couldn’t be further apart. With that I will conclude my analysis. Please comment down below, what other techniques might have given better results. Thank you for reading!

CS PhD @ LSU. Passionate about statistics, ML, and NLP.