<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alessandro Calmanovici on Medium]]></title>
        <description><![CDATA[Stories by Alessandro Calmanovici on Medium]]></description>
        <link>https://medium.com/@ale.calmanovici?source=rss-4fc28d7e4af5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*X2njzbYD1nXNbPu6kyiGNg.jpeg</url>
            <title>Stories by Alessandro Calmanovici on Medium</title>
            <link>https://medium.com/@ale.calmanovici?source=rss-4fc28d7e4af5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:49:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ale.calmanovici/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generating rap lyrics with AI]]></title>
            <link>https://medium.com/musixmatch-blog/generating-rap-lyrics-with-ai-13fb8d33ab5e?source=rss-4fc28d7e4af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/13fb8d33ab5e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[rap]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[lyrics]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Alessandro Calmanovici]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 16:05:08 GMT</pubDate>
            <atom:updated>2020-05-07T14:28:30.848Z</atom:updated>
            <content:encoded><![CDATA[<p>I worked on rap lyrics generation for my Master’s Thesis, proposing a neural rap generation model with focus on rhyming. In this article I summarize my experience and the achieved results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8k0pOxEC1iC3QSYcT-B8-A.jpeg" /></figure><h3><strong>3, 2, 1… Go!</strong></h3><p>Six months ago I was sitting at my desk, looking for proposals for my Master’s Thesis, suddenly I got a notification on my phone, it was an email from a PhD student of the <a href="https://www.ini.uzh.ch/en.html">Institute of Neuroinformatics</a> (INI):</p><blockquote><em>We are starting a new project, we want to generate rap lyrics with AI, if you want to write your Master’s Thesis about it, please let us know.</em></blockquote><p>“Wow, that’s the sort of intriguing, out-of-the-box project I need, let me reply and check it out”.</p><p>One week later, I was already dealing with rap lines, rhyming and related papers. Two weeks later, I had the first meeting with the whole team:</p><p><a href="https://ninikolov.github.io/"><strong>Nikola Nikolov</strong></a>, finishing his PhD at INI with a focus on Natural Language Processing (<strong>NLP</strong>).</p><p><a href="https://users.ics.aalto.fi/emalmi/"><strong>Eric Malmi</strong></a>, working at Google Zurich, with a PhD in data mining.</p><p><a href="https://www.curtisnorthcutt.com/md/research.html"><strong>Curtis Northcutt</strong></a>, PhD student in EECS at MIT and <a href="https://www.phdrapper.com/">rapper</a>.</p><p><a href="https://www.linkedin.com/in/loretoparisi/?originalSubdomain=it"><strong>Loreto Parisi</strong></a><strong>, </strong>director of machine learning at <a href="https://www.musixmatch.com/">Musixmatch</a> and his team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*AplX2vQAnaUxuML_EyqQ4w.png" /><figcaption>Top left: <strong>Nikola </strong>- Top right: <strong>Curtis </strong>- Bottom left: <strong>Eric </strong>- Bottom right: <strong>Loreto</strong>.</figcaption></figure><p>They are all amazing guys with incredible minds: I think there is no better introduction for them than their accomplishments.</p><h3><strong>Text generation</strong></h3><p>Generating machine text which is almost indistinguishable from human text is a very challenging task in <strong>NLP</strong>. We address a specific form of creative text generation, <strong>rap lyrics generation</strong>: when producing new lyrics, we also have to take into account the stylistic features of rap text, like flow, metric and rhyming, besides the other properties of natural language, for instance coherence and grammatical correctness.</p><p>Not only is the task fun and fascinating, allowing to explore the limits of AI, but also the outputs of such models may be helpful and inspirational for different artists and writers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bn80_J8s8ERbaM4dQui3Dg.jpeg" /></figure><h3><strong>Rhyme </strong>Density</h3><p>We focus on generating lyrics which contain more rhymes: to measure the rhyme technicality of a rap text, we use Rhyme Density (<strong>RD</strong>), a metric introduced by Malmi et al. in the “<a href="https://arxiv.org/abs/1505.04771">Dopelearning</a>” paper.</p><p>The metric captures the amount of assonance rhymes in a given piece of text by computing the longest matching vowel sequences (<strong>LVS</strong>) for every word of the text.</p><blockquote>“<em>This is a job, I get paid to </em><strong><em>sling some raps</em></strong><em>,</em></blockquote><blockquote><em>What you made last year was less than my </em><strong><em>income tax</em></strong>”</blockquote><p>In the example, the LVS for the word <em>tax </em>is 3.</p><p>The LVS of a text is the average of the LVS of all the words in the text.</p><p>The artist with the highest rhyme density per song is <em>Inspectah Deck</em> with an average of 1.187, <em>Eminem</em> is 39th with 1.04, <em>The Lonely Island</em> is 94th with 0.870.</p><h3>Dataset</h3><p><a href="https://blog.musixmatch.com/">Musixmatch</a> provided us with a dataset composed by 60k songs whose genre is rap or very close to rap. We have 24k different artists and an average of 70 lines per song.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9x0NXM2pwJhXYiEJQNMnUg.png" /></figure><p>We measured the average rhyme density of a lyric in the dataset, which is 1.045. We also use a repetition rate (<strong>RR</strong>) metric to evaluate the amount of unique n-grams in a text: RR ranges from 0 to 100%, where 0 means no repetition and 100 means full repetition. The average RR of a song in the dataset is 22.3%.</p><p>The songs go through a preprocessing pipeline to improve regularization and remove unwanted words. The final dataset is a text file where songs are appended to each other and separated by an “end of song” token.</p><h3>GPT2 fine-tuning</h3><p>To generate rap lyrics we use the state of the art language model released by OpenAI, <a href="https://openai.com/blog/better-language-models/">GPT2</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsHh3HVfy4OQP-zDafQoqA.png" /><figcaption>Image taken from the blog post “<a href="http://jalammar.github.io/illustrated-gpt2/">Illustrated GPT2</a>”</figcaption></figure><p>GPT2 is a stack of decoders: given an input context, it outputs a vector which is then multiplied by the whole vocabulary embedding matrix. This operation produces a score for each word in the vocabulary. The higher the score, the higher the probability of that word to be the next word.</p><p>We work with the smallest GPT2 version released by OpenAI, the one with <strong>117M </strong>parameters. In our experiments we realized that our dataset is not big enough to take advantage of the more complex models, which are additionally much slower to train.</p><p>The GPT2 version released by OpenAI has already been trained on 40GB of human text extracted from the web. We want to exploit that knowledge and adapt it to our task: rap generation.</p><p>We fine-tuned the pretrained 117M model on our 60k rap songs dataset: we trained the network for 200k iterations which took around 40 hours on our single GeForce GTX 1080 GPU. Below we report the perplexity scores of the best model. Perplexity is a measure of how well our model predicts a word, the lower the better. Test and validation sets are composed by 1000 random songs extracted from the dataset.</p><blockquote><strong>Training</strong> <strong>Perplexity</strong>: 22,873</blockquote><blockquote><strong>Test Perplexity</strong>: 27,473</blockquote><blockquote><strong>Validation Perplexity</strong>: 24,894</blockquote><p>We produced 300 songs with the fine-tuned GPT2, our <strong>baseline </strong>model, and evaluated them quantitatively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4jilclbA07iPusTcyEmvQ.png" /></figure><p>The longest matching sequence is the longest substring in common between the generated song and the whole training dataset, measured as total number of consecutive characters in common. We compute it to make sure there is no overfitting and thus no copying from the original lyrics: an average of 23 characters means that just few consecutive words are copied from a song in the dataset.</p><p>These are two interesting verses generated by the network:</p><h4><strong>Verse 1 - Baseline model</strong></h4><blockquote>I’ve had a lot of chances and I’ve lost a lot of battles</blockquote><blockquote>I’ve lost a lot of friends, I’ve lost myself</blockquote><blockquote>I don’t know why I haven’t lost all the rage</blockquote><blockquote>I’ve lost the power to fight, I’ve lost the power to move</blockquote><blockquote>I’ve got so much on my mind, I think I’m just caught in between</blockquote><h4><strong>Verse 2 - Baseline model</strong></h4><blockquote>Once you take my hand, you’ll understand</blockquote><blockquote>Sometimes I feel like I’m walking on a tightrope</blockquote><blockquote>I feel like I’m running from my past</blockquote><blockquote>I feel like I’m running from who I am</blockquote><blockquote>But I’ll be okay, ’cause I’m out here with you, you, you</blockquote><blockquote>We’ll make it through whatever comes our way</blockquote><blockquote>’Cause we are one, we are one</blockquote><blockquote>Even when you go down I’ll hold you up</blockquote><blockquote>And I know there’s nothing that I can say</blockquote><blockquote>To convince you to stay</blockquote><blockquote>Maybe I am too abstract</blockquote><p>The RD of the first verse is 0.784, the one of the second verse is 0.807.</p><h3>Rhyme density biased sampling</h3><p>The average rhyme density of the generated songs is 0.932; we want to improve it by biasing the probabilities of the next word estimated by the model.</p><p>We call the model probability of a specific word <strong>P </strong>and we modify it according to the formula:</p><blockquote><strong><em>P = P * (1 + alpha * RD)</em></strong></blockquote><p>where <strong>RD </strong>is the resulting rhyme density of the generated text if that word was chosen as next word, and <strong>alpha </strong>is a new hyperparameter we introduce to regulate the rhyme component<strong>.</strong></p><p>We generated 300 songs for different alpha values ranging from 0 to 100 and evaluated rhyme density, perplexity and repetition rate for each of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vcHZ1GGN4VlCscR9qsSk4A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7s1k1R3dgf2mL6vioKouYQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0f0OVrILjfY8rLjyNlBUvw.jpeg" /></figure><p>They all have a strong positive correlation with alpha, so there is a trade-off between improvements on rhyme density and general language quality of the produced lyrics. For small enough alpha values, we manage to improve rhyme density while keeping the other metrics almost stable.</p><p>For alpha = 1, we have a 120% improvement in RD but just a 10% perplexity increase and a 18% RR increase.</p><p>We report two other verses generated with the new rhyme biased GPT2 model.</p><h4><strong>Verse 1 - Biased model</strong></h4><blockquote>I don’t play a lot of games</blockquote><blockquote>So let me play my game</blockquote><blockquote>If y’all ain’t got patience, all I got play</blockquote><blockquote>Take my away from stressers, put my name on my playlist</blockquote><blockquote>All my time, I will not waste my time</blockquote><blockquote>They try to take my shine, they lie to take my time</blockquote><h4>Verse 2 - Biased model</h4><blockquote>If I die tonight</blockquote><blockquote>Will my baby survive as a daughter?</blockquote><blockquote>And by the time I die</blockquote><blockquote>Will my baby survive as a child?</blockquote><blockquote>I mean in this life it looks like</blockquote><blockquote>If she dies</blockquote><blockquote>Will she be my wife?</blockquote><blockquote>Or is she in the street</blockquote><blockquote>And she gon die with me?</blockquote><p>Here we have a RD of 2.615 for the first verse and a RD of 2.755 for the second.</p><p>Curtis produced a demo song out of the two verses, which you can listen to by clicking the play button down here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F729801943%26show_artwork%3Dtrue&amp;url=https%3A%2F%2Fsoundcloud.com%2Fthephdrapper%2Fname-on-the-playlist&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-000654074143-6a2oym-t500x500.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/f99397b22b50aedee47ff03b83ba98fa/href">https://medium.com/media/f99397b22b50aedee47ff03b83ba98fa/href</a></iframe><h3>What’s next?</h3><p>We showed an effective way of using AI to produce human-like rap lyrics, although many improvements are still possible. We are working on enforcing words diversity in a lyric, upgrading the size and quality of the dataset and experimenting with different architectures, not only GPT2.</p><p>Is Slim Tensor, Lil’ Miner or AI - West going to dominate the Billboard charts in the next years?</p><p>Who knows! In the meantime, <strong><em>stay fine-tuned</em></strong>.</p><p><em>I want to thank again the whole team for helping me through the last months.</em></p><p><em>For more details, I’m sharing the full thesis and a brief video of my defense where I play the song produced by Curtis. If you like it, follow him on </em><a href="https://open.spotify.com/artist/6aQOMHXGZ2ErNJGPPDpCxa"><em>Spotify</em></a><em> and </em><a href="https://www.youtube.com/channel/UC6FtSJ4Qz3FzYIEwbFVLYFA"><em>YouTube</em></a><em>!</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2FI5RLpz0JYL4YTN&amp;url=https%3A%2F%2Fwww.slideshare.net%2FAlessandroCalmanovic%2Fmaster-thesis-alessandro-calmanovici&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Fmasterthesiscalmanovici-200107164019-thumbnail-4.jpg%3Fcb%3D1578415354&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="640" frameborder="0" scrolling="no"><a href="https://medium.com/media/f625c9e768cc8f1c3ee3875fbc52967a/href">https://medium.com/media/f625c9e768cc8f1c3ee3875fbc52967a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13fb8d33ab5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/musixmatch-blog/generating-rap-lyrics-with-ai-13fb8d33ab5e">Generating rap lyrics with AI</a> was originally published in <a href="https://medium.com/musixmatch-blog">Musixmatch Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>