<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/whats-in-the-words-comparing-artists-and-lyrics-with-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rcrastinate.blogspot.com/2017/03/whats-in-words-comparing-artists-and.html"> Rcrastinate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>It’s been a while since I had the opportunity to post something on <a target="_blank" rel="nofollow" href="http://rcrastinate.blogspot.de/2013/03/peace-through-music-country-clustering.html">music</a>. Let’s get back to that.</p>
<p>I got my hands on some song lyrics by a range of artists. <span>(I have an R script to download all lyrics for a given artist from a lyrics website. Since these lyrics are protected by copyright law, I cannot share the download script here, but I can show some of the analyses I made with the lyrics.)</span><br><span><br></span>My main question is: What can we learn about an artist, or several artists, when we have a corpus of lyrics. I gonna analyze lyrics by the following artists:</p>
<ul>
<li>Beck</li>
<li>Bob Dylan</li>
<li>Britney Spears</li>
<li>Leonard Cohen</li>
<li>Lou Reed</li>
<li>Metallica</li>
<li>Michael Jackson</li>
<li>Modest Mouse</li>
<li>Nick Cave and TBS</li>
<li>Nikka Costa</li>
<li>Nine Inch Nails</li>
<li>Nirvana</li>
<li>PJ Harvey</li>
<li>Prince</li>
<li>Radiohead</li>
<li>Rihanna</li>
<li>The Cure</li>
<li>The Doors</li>
<li>The National</li>
</ul>
<p>Let’s start with an easy one. I wanna know which artist has the longest songs. The more words there are in the respective lyrics, the longer the song.
<div></div>
<p>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i0.wp.com/3.bp.blogspot.com/-VWObZuRd5jk/WM_3oQokkeI/AAAAAAAAC2E/AwSo2dAsm5cy9lUasf4J-PtJ_ysobKz2QCLcB/s1600/lyr_lengths.png?ssl=1"><img src="https://i2.wp.com/3.bp.blogspot.com/-VWObZuRd5jk/WM_3oQokkeI/AAAAAAAAC2E/AwSo2dAsm5cy9lUasf4J-PtJ_ysobKz2QCLcB/s400/lyr_lengths.png?resize=400%2C325&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Mean length of songs in words (click to enlarge).</td>
</tr>
</tbody>
</table>
<p>That’s quite a surprise (at least for me). Rihanna and Britney Spears, certainly the most prototypical actual pop artists in the list, have actually pretty long lyrics. Another measure from linguistics is the type-token ratio where the number of different words (types) is divided by the total number of words (tokens). This measure is often interpreted as “lexical diversity” because the vocabulary is more diverse if there are only a few words that are repeated very often. Suppose you have a song that only consists of the words “oh yeah” and this is repeated 10 times, you will have 2 types and 20 tokens, which would lead to a type-token ratio of 2/20=0.1.<br>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i0.wp.com/1.bp.blogspot.com/-v2lH7m9Pd1U/WM_3Q7hKmDI/AAAAAAAAC2Y/MoS8YIfohTUh-TU1IJ3mauWZbyF4UWbJACEw/s1600/lyr_TTRs.png?ssl=1"><img src="https://i2.wp.com/1.bp.blogspot.com/-v2lH7m9Pd1U/WM_3Q7hKmDI/AAAAAAAAC2Y/MoS8YIfohTUh-TU1IJ3mauWZbyF4UWbJACEw/s400/lyr_TTRs.png?resize=400%2C325&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Mean type-token ratio of songs (higher means more diverse vocabulary, click to enlarge).</td>
</tr>
</tbody>
</table>
<p>Well, look at that – Nikka Costa, one of my favorite funk/soul artists comes out on top in this list, followed by Beck and The Doors. Rihanna and Britney obviously have a lot of words in their songs, but with regard to lexical diversity, they rank last within the artists analysed here.</p>
<p>Let’s try something content-related. Obviously, it’s quite hard to tackle the content (or even meaning) of songs. But we can do some really easy stuff. The first thing I want to try is what I want to call the “self-centered ratio”. I simply define a list of keywords (or better: sequences of characters) that are referencing the first person: “i”, “me”, “i’ve”, “i’m”, “my”, “mine”, “myself”. Now I calculate for each song how many of the words in the lyrics are in this list and divide this number by the number of words in the song. Suppose you have a song with these lyrics: “i’m my enemy and my enemy is mine” (I really don’t know what that would mean but that’s just an example, right?). The “self-centered ratio” would be 4/8 = 0.5 because we have “i’m”, “my”, “my” and “mine” and 8 words altogether (“i’m” is counted as one word here because it is not separated by a space). Here is the result.<br>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i2.wp.com/1.bp.blogspot.com/-N0O46j5HtOM/WM_3o3FCaUI/AAAAAAAAC2c/jwOHeA216W4M8O3n9TUtwO7SHaBPT0NXACEw/s1600/lyr_selfcentered.png?ssl=1"><img src="https://i1.wp.com/1.bp.blogspot.com/-N0O46j5HtOM/WM_3o3FCaUI/AAAAAAAAC2c/jwOHeA216W4M8O3n9TUtwO7SHaBPT0NXACEw/s400/lyr_selfcentered.png?resize=400%2C325&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Mean self-centered ratio of songs (click to enlarge)</td>
</tr>
</tbody>
</table>
<p>Britney and the Nine Inch Nails are definitely not very similar in terms of their music (that’s a wild guess, I only know very few songs by Britney Spears!), but they are quite similar when it comes to singing about stuff that concerns themselves.</p>
<p>Next up is sentiment analysis. Professionally, I don’t like it very much because in my opinion, it has a lot of empirical and methodological problems. But why not give it a try for this application here? We’re not here for the hard science side of things, are we? So, what I did was basically the same as for the self-centered ratio but only with much bigger keyword lists for positive words and negative words (so, actually I did it twice, one time with positive words and one time with negative words). I got the word lists from <a target="_blank" rel="nofollow" href="https://github.com/jeffreybreen/twitter-sentiment-analysis-tutorial-201107/blob/master/data/opinion-lexicon-English/negative-words.txt">here (for negative words)</a> and from <a target="_blank" rel="nofollow" href="https://github.com/jeffreybreen/twitter-sentiment-analysis-tutorial-201107/blob/master/data/opinion-lexicon-English/positive-words.txt">here (for positive words)</a>.</p>
<p>I show you two plots, one where you can see both ratios and one where I combined both ratios per song to get one value (positive value + negative value). These are the results:<br>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i0.wp.com/1.bp.blogspot.com/-G7FRkU2fQbs/WM_3ppx2-DI/AAAAAAAAC2c/shr7vpeOzsIqtxHGxnOpuk42puOw1nQggCEw/s1600/lyr_sentiment.png?ssl=1"><img src="https://i1.wp.com/1.bp.blogspot.com/-G7FRkU2fQbs/WM_3ppx2-DI/AAAAAAAAC2c/shr7vpeOzsIqtxHGxnOpuk42puOw1nQggCEw/s400/lyr_sentiment.png?resize=400%2C325&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Mean ratio of positive and negative words of songs (click to enlarge). </td>
</tr>
</tbody>
</table>
<p>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i2.wp.com/2.bp.blogspot.com/-hutIgjXPaac/WM_3py566xI/AAAAAAAAC2c/nOLxkWoeT2ouYTSqFmrXWkwpzWhGof9WwCEw/s1600/lyr_sentiment2.png?ssl=1"><img src="https://i2.wp.com/2.bp.blogspot.com/-hutIgjXPaac/WM_3py566xI/AAAAAAAAC2c/nOLxkWoeT2ouYTSqFmrXWkwpzWhGof9WwCEw/s400/lyr_sentiment2.png?resize=400%2C325&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Mean combined measure for sentiment of songs (click to enlarge).</td>
</tr>
</tbody>
</table>
<p>Actually, this seems to make sense. I’m no expert for Metallica, but for Nine Inch Nails, Nirvana and Radiohead, this second plot seems to make sense. Also, Prince, Michael Jackson, Nikka Costa, Rihanna and Britney Spears getting an overall positive score works for me. Nick Cave is sometimes called the “Prince of Darkness”. In this analysis, however, this is not really confirmed. Or the “dark” aspects of his lyrics are just hidden from this quite coarse approach. Just think of the song “People just ain’t no good”. Here, each occurence of “good” is counted as positive because my simple word list approach is simply not sensitive for the negation in this line.</p>
<p>One last thing: I wanted to know if artists can be clustered (grouped) just with the use of their lyrics. What we need is a measure of dissimilarity for each artist-artist combination. There are several ways to do that and I experimented with a few (e.g. cosine distance or correlation of frequency vectors). It turns out, there is an even easier measure to do this: Let’s take the first 500 most frequent word each artist uses in their lyrics. With the other artist, we do the same. Then, we intersect these two sets of word lists and divide it by 500. What we get is the ratio of words that are present in both top-500 vocabularies, which is essentially a similarity measure. If we do 1 minus this value, we get a dissmilarity measure which we can use as input to a hierarchical cluster analysis. This is what we get.<br>
<table align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a target="_blank" rel="nofollow" href="https://i1.wp.com/4.bp.blogspot.com/-QzOalbyvVXs/WM_3Rso3huI/AAAAAAAAC2Y/tUCuZbR8X_4-o_IamBFUj3UVfaFY6PwuQCEw/s1600/lyr_Clustering.png?ssl=1"><img src="https://i0.wp.com/4.bp.blogspot.com/-QzOalbyvVXs/WM_3Rso3huI/AAAAAAAAC2Y/tUCuZbR8X_4-o_IamBFUj3UVfaFY6PwuQCEw/s400/lyr_Clustering.png?resize=400%2C320&ssl=1" border="0" data-recalc-dims="1"></a></td>
</tr>
<tr>
<td>Dendrogram for a hierarchical cluster analysis of overlapping top-500 words.</td>
</tr>
</tbody>
</table>
<p> Look at that, I think it works quite nice: We get a “pop” cluster on the left with Nikka Costa, Britney Spears, Rihanna, Michael Jackson and Prince. Feel free to interpret the other clusters in the comments. As I said, I think it works quite OK.</p>
<p>R CODE is coming soon!</p>
<p>LOOK, <a target="_blank" rel="nofollow" href="https://www.dropbox.com/s/r6o9dvqwel2d5of/frequency_plots.zip?dl=1">there are frequency plots available here</a> for all the artists!</p>
<p></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://rcrastinate.blogspot.com/2017/03/whats-in-words-comparing-artists-and.html"> Rcrastinate</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Onb8jUbtalY"></a></div>