I was reading the Wikipedia entry for the Rolling Stone’s 500 Greatest Songs of All Time, and while it contains a lot of interesting statistics (shortest and longest songs, decades, covers, etc.), I’ve decided to do some “API-based data-science” and see what insights we can learn from this top-500.

#15: London Calling – One of the 5 songs from the Clash in the top 500

I’ll split this into multiple posts, in order to showcase how different APIs bring multiple perspectives to the data-set, such as acoustic features with the Echo Nest, mood recognition with Gracenote, or artist and genre data with seevl (disclosure – I’m the main responsible for this one).

Here’s the first one, investigating lyrics from those top-500 songs. The first part is rather technical, so if you’re interested only in the insights, just skip it. And here’s an accompanying playlist, featuring the songs mentioned in this post – all from the top 500, except the opening one.

[spotify id=”spotify:trackset:PREFEREDTITLE:1PwB9EADXS90I8LoewLXfl,5jzma6gCzYtKB1DbEwFZKH,66gcFTSvJmIkh2hVSJFYmh,6fgjU6IfBOXHI3OKtndEeE,6P0b9HhIaeofQWfBwZSjE3,6jx7pKjpXKuQdXXPI3H8qY,7eb36d69DQC3Msq46DceT0,5DeXQ3qADuDmqsosnZAK3o,7qAfwYKo98krLHrJ4okp6T,4pdLyulbYLCrPmDzWWeJIZ,0vLwL4xuJ3s7SeaCdvMqkY,7tiNOIcsnmTFUjVzgSd1aJ,4ugIloQYMfDhN7lOtEWezy,6Vcwr9tb3ZLO63F8DL8cqu,1vFVOr0psCHVWjjK2Jp298,1ZA8L9IOkRhmmz4nPXXx7h,49hrn0lqJYigpFGJ66swjf,6Rcv8LeOnK2i2MZ19n2fl4,5Lf74o9BFFGIZDWNUtAIap,2oF7FZHIJbzjeEXZ3D0Ku4,2tfIe0cUBzs0PB8RDXuNSw,6XAcmxPbCfMzLBvjBd2G0H,7F0yUq9x2gz8TAeFdCITTc,2VX2QRAGKPyqMZU8cFZ3Ib,69uJi5QsBtqlYkGURTBli8,1nn4dKQNOzqGN4fyCeaZWA,3OeX4IyrnpwkElW5iS8leo,13FkFPnKX1eC2V3nwSy5YB,771L440a1283WimX8EzkpG”]

Come together

Before going through the insights, here’s the process I used to gather the data:

Regarding that last step, I’ve used the PunktWordTokenizer, which gave better results than the default word_tokenize. As most of the lyrics are in English and the Punkt tokenizer is already trained for it, no additional work was required. Stemming was done with the Snowball algorithm – more about it below. Here’s a quick snippet of how it works

from nltk.tokenize.punkt import PunktWordTokenizer
from nltk.stem.snowball import SnowballStemmer

elvis = """
Here we go again
Asking where I've been
You can't see these tears are real
I'm crying (Yes I'm crying)

sb = SnowballStemmer('english')
pk = PunktWordTokenizer()

print [sb.stem(w) for w in pk.word_tokenize(elvis)]

Leading to:

['here', 'we', 'go', 'again', 'ask', 'where', 'i', "'ve", 'been', 
'you', 'can', "'t", 'see', 'these', 'tear', 'are', 'real', 'i', 
"'m", 'cri', '(', 'ye', 'i', "'m", 'cri', ')']

As you can see, there are a few issues: “me” is stemmed to “m”, and “crying” to “cri” and not to “cry” – as one could expect. Yet, “cried”, “cry”, “cries” are all stemmed to this same root with Snowball, which is OK in order to group words together. However, no stemming algorithm is perfect. Snowball identified different roots for “love” and “lover”, while the Lancaster algorithm matched both to “lov”, but fails for the previous cry example.

>>> from nltk.stem.snowball import SnowballStemmer
>>> from nltk.stem.lancaster import LancasterStemmer
>>> sb = SnowballStemmer('english')
>>> lc = LancasterStemmer()
>>> cry = ['cry', 'crying', 'cries', 'cried']
>>> [lc.stem(w) for w in cry]
['cry', 'cry', 'cri', 'cri']
>>> [sb.stem(w) for w in cry]
[u'cri', u'cri', u'cri', u'cri']
>>> love = ['love', 'loves', 'loving', 'loved', 'lover']
>>> [lc.stem(w) for w in love ]
['lov', 'lov', 'lov', 'lov', 'lov']
>>> [sb.stem(w) for w in love ]
[u'love', u'love', u'love', u'love', u'lover']

That being said, on the full corpus, the top-10 stems were the same whatever the algorithm was (albeit a different count and different syntaxes). Hence, I’ll report on the Snowball extraction in the remainder of this post.

Baby love

So, it appears that the most popular word variation in the corpus is “love”. It’s mentioned 1057 times in 219 songs (43.8%), followed by:

One could probably write lyrics with “Oh yeah baby I got you, yeah I’m in love with you, yeah!” and easily fits here (well, look at that opening line). Sorting by song ranking also brings “like” in the top list, included in 194 of those top-500 songs.

I wanna be anarchy

Looking at the top-5 3-grams and we still have a sense of a general “you-and-me” feeling that occur in those songs:

Follower by other want / don’t want combinations. Once again, most of the want-list is love-related. While some want to hold her hand,  know if she loved them or simply know what love is, other prefer to be your dog, while some just want to be free.

There was no real pattern on the 4-grams and 5-grams, besides that Blondie, Jimmy Hendrix and 7 others “don’t know why”, and that the B-52’s, Bob Dylan and Jay-Z have something to do on “the other side of the road”.

Hotel California

As a short-list compiled by a rock magazine, you could expect a few tracks falling under the sex, drugs and rock-n-roll stereotype. Well, not really. On the top-500, only 13 songs contain the word sex, 5 drug and 4 rock’n’roll, none of them combining all.

Looking deeper into the drug-theme, and using a Freebase query to a list of abused substances and their aliases, we find 7 occurrences for cocaine and 4 for heroin – three times for the first one in the eponym song, while grass and pot appear a few times, even though it would require more analysis to see in which context they’re used. Of course, a simple token analysis like this one could not capture the full songs messages, and we miss classics like the awesome Comfortably numb or White Rabbit by Jefferson Airplane.

Querying Freebase to find drugs and their aliases

The more details about drugs in this top-500 are in the review themselves – often including background stories about the song. Heroin it mentioned 11 times, acid 3, alcohol 3, and cocaine twice.

Good vibrations

Last but not least, I’ve used AlchemyAPI for topic extraction and sentiment analysis. Nothing very relevant came up from the entity extraction phase, but here are the most negative songs from the list according to their sentiment analysis module.

And the most positive ones

For both, it seems there’s a clear bias towards the words used in the song (e.g. “shame” or “love”), rather than extracting sentiments from the proper song’s meaning. It would be more interesting to use a data-set from SongMeanings or Songfacts to run a proper analysis – this might be for another post.

That’s it for today!

NB: Update 13/05 – If you’re looking for more lyrics-data-mining, here’s an interesting study on Rap lyrics by Matt Daniels.