<?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 Fuaad Coovadia on Medium]]></title>
        <description><![CDATA[Stories by Fuaad Coovadia on Medium]]></description>
        <link>https://medium.com/@fuaadcoovadia?source=rss-e6febec22b06------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2-AdM7aoXyxx2nj1</url>
            <title>Stories by Fuaad Coovadia on Medium</title>
            <link>https://medium.com/@fuaadcoovadia?source=rss-e6febec22b06------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:31:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fuaadcoovadia/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[Bot building for the broken-hearted]]></title>
            <link>https://medium.com/@fuaadcoovadia/bot-building-for-the-broken-hearted-df9de5afd0a8?source=rss-e6febec22b06------2</link>
            <guid isPermaLink="false">https://medium.com/p/df9de5afd0a8</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[heartbreak]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <dc:creator><![CDATA[Fuaad Coovadia]]></dc:creator>
            <pubDate>Thu, 21 Oct 2021 19:35:12 GMT</pubDate>
            <atom:updated>2021-10-21T19:35:12.112Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide to channeling all that rage, sadness and confusion into making a kick-ass AI agent.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhkrHbmR60e76AlojOKNKw.jpeg" /><figcaption>Photo by <a href="https://burst.shopify.com/@matthew_henry?utm_campaign=photo_credit&amp;utm_content=Browse+Free+HD+Images+of+Vintage+Blue+Robot+With+A+Shadow&amp;utm_medium=referral&amp;utm_source=credit">Matthew Henry</a> from <a href="https://burst.shopify.com/api-tech?utm_campaign=photo_credit&amp;utm_content=Browse+Free+HD+Images+of+Vintage+Blue+Robot+With+A+Shadow&amp;utm_medium=referral&amp;utm_source=credit">Burst</a></figcaption></figure><blockquote><em>The questions we ask ourselves after a break-up are exactly the sort of questions that make for great bot-building;</em> ‘where did things go wrong?’<em>, ‘</em>why did I act that way?’<em> and</em> ‘what could I have done differently?’. <em>The broken-hearted may be the perfect candidates for building bots, and building bots may be the perfect outlet for the broken-hearted.</em></blockquote><p>I recently stumbled upon the <a href="https://www.kaggle.com/c/lux-ai-2021">Lux AI challenge</a> on Kaggle (a website which hosts data science competitions among other things). The challenge involves coding a set of AI agents to collect resources and build cities in a pre-provided game environment. I was struck by how much joy creating a little agent to do my bidding gave me and thought; ‘ya know who this would be perfect for? The brokenhearted, the discarded, the sadsacks who let another human fondle their heartbags until squish, the nasty heathen you trusted squashed it in front of you’. So, I’m leaning into that cliché role we all know and love-to-hate of the sassy bestfriend who tries to help you through a break-up by saying you just need to get back out there and experience the transformative power of AI course through your veins. As Brené Brown probably says “<em>The 4th industrial revolution will relieve all human suffering!”</em></p><p>Thus, the following is <strong>a practical, hands-on guide which walks you through the 7 stages of grief and how to process these emotions through creating your own bot</strong> for the Lux AI challenge — so put away the tissues, put down the hand-mirror you use for self-loathing, and let’s begin!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FWT9BQdEbdqk7jMbN4T%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FWT9BQdEbdqk7jMbN4T%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FWT9BQdEbdqk7jMbN4T%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca8d534933b19af6fe992480d249b2a7/href">https://medium.com/media/ca8d534933b19af6fe992480d249b2a7/href</a></iframe><p><em>Note: this guide can also be used by regular non-brokenhearted folk who are interested in entering the Lux AI competition, or who just want to know more about the mechanics of agent-building in Python, but just know that you aren’t the target audience so this may slap differently for y’all.</em></p><h3>Stage 1: Shock and denial</h3><p>It’s Friday night, you thought you were going out. You’ve already tried 3 different t-shirts before finally settling on this one. You’re waiting for them to pick you up. Instead, a text arrives… they need space. From what, it doesn’t say. What do you do?</p><p>Well, first you visit <a href="https://www.kaggle.com/c/lux-ai-2021">this link</a>, it provides all the details of the Kaggle competition and walks you through how to install the necessary packages to get your notebook file setup where you can tinker with the code. I’m using a Jupyter Notebook and coding the bot in Python.</p><p>Great, you’re doing well — lean into the denial. Next we’re going to visualize the challenge:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*CRDERN2SUFDG-ECTRkELGw.gif" /><figcaption>An example of gameplay in the Lux world — Source: Kaggle Lux AI competition</figcaption></figure><p>The aim of the challenge is to grow your city, and end the game (360 turns) with more city tiles than your opponent. To do this, you control those little orange agents, who can gather resources, refuel your existing cities to make sure they don’t collapse, build new cities or attack the road networks of your opponent. Your role, sweet damaged child of yesterday’s romance, is to tell those orange agents what to do, and under what conditions to do them. However, what makes this an AI challenge and not a simple video game (like Age of Empires), is that you don’t get to instruct your agents what to do each turn; you need to code the instructions upfront for what your agents need to do for the entire game (and for a randomly-generated game map).</p><h3>Stage 2: Pain and guilt</h3><p>Alone and unsure where to go. Even the simplest of tasks feels difficult. An endless loop of work, home, work, home, work, home. The night draws near.</p><p>Congratulations, you’ve just met something which feels as aimless as you do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*-pPmykVnUAkEmnir0TpYXg.gif" /><figcaption>The initial starter kit agent which Lux AI provides is coded only with the basic functions of gathering resources and returning these to the city when their cargo is full</figcaption></figure><p>You’re probably going to feel some guilt right now. <em>Is there something more you could have done?</em></p><p>In terms of your relationship, this is a dangerous question, a question without bounds— just a loop of your thoughts where you, like your little Sisyphus above, move back and forth with neither progress nor defeat.</p><p>In terms of your code, you could absolutely have done more! <strong>There are very clear next steps about what needs to happen to improve this bot.</strong> If our goal is to end the game with more cities than our opponent, an easy next step would be to figure out when is a good time to build another city and then instruct our agent to go build the city when that moment arrives during the game.</p><h3>Stage 3: Anger and bargaining</h3><p>They left a few things behind at your place when moving out. A pair of socks which you fished out from beneath the couch, the set of oil paints which you gave them for their birthday, and the knot in your stomach which may never go away. All of these things are probably yours now, and you use the paints to streak black claw marks across your face, crisscrossing over yesterday’s tear trails and leaving you lookin’ how you supposed to, like a mutha’ fumblin’ bad ass!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o6fIRA6rsqNy178Fq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcartoonhangover-cat-cartoon-hangover-3o6fIRA6rsqNy178Fq&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F3o6fIRA6rsqNy178Fq%2Fgiphy.gif%3Fcid%3D790b76119d01de2c41816cec8658cb0cbc6860045f4327fb%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/a12a7f68175380c31264be4bde256037/href">https://medium.com/media/a12a7f68175380c31264be4bde256037/href</a></iframe><p><strong>It is in this state, that you are now ready to code.</strong> The <a href="https://github.com/Lux-AI-Challenge/Lux-Design-2021/tree/master/kits">Lux AI documentation</a> gives us a breakdown of what actions our units can do. Your agent can be made more ‘intelligent’ by coding instructions for what each unit needs to do when given a particular situation during a turn of the game. Thus, the code which runs your agent is no more than a set of <em>if-then</em>, <em>or-else</em> statements.</p><p>The code block below is the snippet of the code which programs the way that our AI agent will choose the set of ‘actions’ for the <strong>worker </strong>each turn. First, it checks whether the worker has any extra cargo space— if they do, this means that they can still gather more resources and the code sends them off to do so [the ‘action’ variable saved is what the game will take as the move our AI has decided upon for this turn]. Alternatively, if they have a full cargo space, we check whether an existing city is at risk of collapse (cities collapse if they do not have enough resources when night-time sets in). If the existing cities have enough resources, the worker can build a new city, if not, the worker must return to deposit their resources in an existing city.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a854939bd69df23259e9adefd056456/href">https://medium.com/media/6a854939bd69df23259e9adefd056456/href</a></iframe><p>With this change, our agent is able to build more cities! Hurrah!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*1cID0Kta3tnzdRlbXr-lHQ.gif" /><figcaption>Notice in turn 95, we finally have enough resources to build a new city! This city collapses during the next night-time due to insufficient resources. We then end up rebuilding the new city over and over each time it collapses — until the game ends and we’re caught in a moment between the new city having collapsed and us not having rebuilt it in time — and we’re back to, literally, square 1.</figcaption></figure><p>Coding in this <em>if-then</em>, <em>or-else</em> way is essentially bargaining. It is navigating your way through the complex set of conditions life can throw at you, and finding a suitable adjustment within this. In the case of heartbreak, bargaining can come in the form of prayer, where you may try strike a deal with a higher power such as: <strong>if </strong>they bring your dearly beloved back into your life, <strong>then</strong> you won’t burn their prize garden gnome, Gerald, in front of their apartment building.</p><p>Perhaps consider using this burning desire to bargain to improve the <em>if-then</em> statements within your bot.</p><h3>Stages 4–5: From depression, reflection and loneliness to the upward turn</h3><p>The loneliness is setting in for your little worker. If a worker falls in the woods with no one to hear it, did it really make the noise “<em>you could have saved me Medium reader — I thought you knew how loneliness felt”</em>?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1oTgGH1xyw9V3zXOfB%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fchristmas-tree-orgasm-doggy-style-1oTgGH1xyw9V3zXOfB&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2F1oTgGH1xyw9V3zXOfB%2Fgiphy.gif%3Fcid%3D790b7611635b34d21a4ece8cc330840cf47e9b5e83a82404%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="573" frameborder="0" scrolling="no"><a href="https://medium.com/media/decf1011179cf67d47e26ddbb394d4e1/href">https://medium.com/media/decf1011179cf67d47e26ddbb394d4e1/href</a></iframe><p>We can turn this situation around by giving our worker a friend. <strong>New workers are created by the cities.</strong> So we need to add to our code to instruct the city tiles to create a new worker in turns where certain conditions are met.</p><p>According to the rules of the Lux AI game, we can only have a number of workers equal to or less than the number of city tiles. So in our earlier simulation where we had 2 city tiles at some point, we could have then created another worker — which would have really helped in keeping that second city alive by providing it with resources, like the first worker did for the first city.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92cfa236146bea14a56761ea4187885a/href">https://medium.com/media/92cfa236146bea14a56761ea4187885a/href</a></iframe><p>This is starting to look better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*PGIqpi1uAuoFHgrG4fCO9A.gif" /><figcaption>From A’I’ to A’WE’</figcaption></figure><h3>Stages 6–7: Reconstruction, then acceptance and hope</h3><p>With some minor tweaks added in to make sure that workers don’t collide into each other by trying to move to the same cell in a turn, we now have a piece of code which gets us more cities than when we started! Hurrah! 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*9vVkfc2LjovEBvmCjRDfSQ.gif" /><figcaption>I like big bots and I cannot lie</figcaption></figure><p>However, our efforts don’t always translate into success in the way we hope — sometimes even after all our self-work and reconstruction, surgical or emotional, they don’t come back. They ignore our texts about how much fun we’re having while making our AI bot. They don’t seem attracted back by how cool our Python code is. They really are gone.</p><p>And to add salt to the wound, it turns out our code is really, quite shit. Perhaps unsurprisingly to anyone who knows anything about coding or Kaggle, we didn’t even crack the top 600 on the Lux AI competition leaderboard.</p><p>Please Lorde, give me the strength to accept the things I cannot change.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FEppBP2BzMYQlq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fmoney-student-royals-EppBP2BzMYQlq&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FEppBP2BzMYQlq%2Fgiphy.gif%3Fcid%3D790b76114342b72234521d4f09e5d747c68d037dc548b780%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="187" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d8f3d09fc88fa92e6512f8f2a86d211/href">https://medium.com/media/6d8f3d09fc88fa92e6512f8f2a86d211/href</a></iframe><p>And Lorde, while we have you here, do you have any thoughts on hope?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fb3uy8g8PwhgvC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Florde-royals-b3uy8g8PwhgvC&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fb3uy8g8PwhgvC%2Fgiphy.gif%3Fcid%3D790b76119e1eb4a6bd46ce5be334c255a04dad44aaea1bee%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="266" frameborder="0" scrolling="no"><a href="https://medium.com/media/15280328ce64dd887b7ae5c58091e4cc/href">https://medium.com/media/15280328ce64dd887b7ae5c58091e4cc/href</a></iframe><p>So well put! Hope is a complex, mysterious force for us humans that sometimes is found in places you weren’t expecting to find it. Like under the couch when you’re fishing out a pair of socks left behind by some horrid angel with a perfect bod who you’re totes over, and you stumble upon a note you had scribbled down in a time when you were a different you, when you were just starting to fall for that person. The note captures the emotions which were only beginning to fizz, the electric unknown you were about to step into. The note is written in the voice of someone wondering about what the future would look like with that person; a collection of ‘if’ statements, hidden in plain sight.</p><p>You put down the note. The same you who was a whole person when they wrote that exploration into the unknown is the same you who now realizes that they had been living in only one of many possible ‘if’ statements.</p><p>It’s time to find out what’s after ‘else’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT0GqCtADHkzNUcO1W%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcolbertlateshow-stephen-colbert-samuel-l-jackson-late-show-xT0GqCtADHkzNUcO1W&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2FxT0GqCtADHkzNUcO1W%2Fgiphy.gif%3Fcid%3D790b761199f64143865ccffb21846533b393daeb53096738%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/81a1a49fcf6e469a5c60d7cd2030113a/href">https://medium.com/media/81a1a49fcf6e469a5c60d7cd2030113a/href</a></iframe><p>Source code for the bot:</p><p><a href="https://github.com/fuaadness/Lux-Design-2021/tree/master/kits/python">Lux-Design-2021/kits/python at master · fuaadness/Lux-Design-2021</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df9de5afd0a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rhymin’ nerdy: network analysis of rhyme pairs in rap lyrics]]></title>
            <link>https://medium.com/@fuaadcoovadia/rhymin-nerdy-network-analysis-of-rhyme-pairs-in-rap-lyrics-3e70f22da488?source=rss-e6febec22b06------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e70f22da488</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[hip-hop]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[network-visualization]]></category>
            <category><![CDATA[rap]]></category>
            <dc:creator><![CDATA[Fuaad Coovadia]]></dc:creator>
            <pubDate>Fri, 08 Oct 2021 20:55:05 GMT</pubDate>
            <atom:updated>2021-10-09T04:40:52.780Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zbD9jBfIjueR-9B5FdbCKw.jpeg" /><figcaption>Network visualization of the relationship between words in rap lyrics produced using NetworkX and PyVis</figcaption></figure><p>There is nothing the internet loves more than unlikely companions: <a href="https://www.boredpanda.com/unusual-animal-friendships-interspecies/?utm_source=google&amp;utm_medium=organic&amp;utm_campaign=organic">Labradors and duckling</a>s, <a href="https://www.youtube.com/watch?v=8W3FPxz-cEE">babies and chickens</a>, or <a href="http://npr.org/sections/thesalt/2015/12/03/457124796/death-by-coconut-a-story-of-food-obsession-gone-too-far">early 20th century sun-worship cults and coconuts</a>. Another unlikely pair is that of hip-hop and quantitative analysis: from popular analyses such as <a href="https://pudding.cool/projects/vocabulary/index.html">this one</a> by the Pudding which ranks rappers by size of their vocabularies, to journal articles, like the one by Finnish computer scientists entitled ‘<a href="https://www.researchgate.net/publication/276922934_DopeLearning_A_Computational_Approach_to_Rap_Lyrics_Generation">DopeLearning: A Computational Approach to Rap Lyrics Generation</a>’. The internet is aflush with nerds trying to show love for a genre they’re not cool enough to join, the best way they know how — by swinging around their Pythons screaming “I think rap is really cool, nice and awesome!”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GwYRobT-1pS5ScyEJ_rHA.png" /><figcaption>My favorite footnote from the DopeLearning paper.</figcaption></figure><p>I thought I had buried my own urges to walk the line between hip-hop and nerdiness a decade ago, when teenage-me hit billboard rock-bottom with this <a href="https://www.youtube.com/watch?v=dLNvLjqBD2s">banger</a>. But then last week I was listening to the radio and heard Megan Thee Stallion rhyme ‘wine’ with ‘fine’ (<em>“Lookin’ fine, sippin’ wine” — Beautiful Mistakes by Maroon 5 ft. Megan Thee Stallion).</em></p><p>Like a sleeper-agent with a trigger-phrase lodged unknowingly between the folds of their cortex, I was awake; aware that this rhyme between ‘fine’ and ‘wine’ must have been done dozens of times before, surely. Which made me wonder; <strong>which rhyming pairs are most popular in rap? Which are the least popular? And, could we visualize the rhyme choices of artists to answer the above two questions?</strong></p><p>To figure this out, I gathered the all-time top 500 rap songs from the Genius.com API, gathered their 47 439 rows of lyrics, and used Python to analyze the relationship between rhymes¹. I extracted only the last word in the line from these 47k rows, to get the end-of-line rhyming word. The goal was to produce a visualization of the relationship between rhyming words.</p><h3><strong>Networks: its all about who you node</strong></h3><p>Below is my first attempt at this; a gigantic, indecipherable web which plots every ‘end-of-line word’ as a point (called a <em>node</em>) in the network and draws a line between words (called an <em>edge</em>) if they appear together one line apart in lyrics. For example, in Cardi B’s <em>Bodak Yellow </em>lyrics, the end-of-line words ‘shoes’ and ‘choose’ would get a line drawn between them because they appear one line apart.</p><blockquote>These expensive, these is red bottoms, these is bloody <strong>shoes</strong><br>Hit the store, I can get ’em both, I don’t wanna <strong>choose</strong></blockquote><p>I feel you Cardi, we shouldn’t need to choose between the left or right shoe. I don’t know who needs to hear this but: please 👏🏾 sell 👏🏾 shoes 👏🏾by 👏🏾the 👏🏾pair!</p><p>Anyways, that’s all networks are folks, a collection of ‘nodes’ and the relationship between them, ‘edges’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GjHbT0Q26wQearYCZRogw.gif" /><figcaption>The word wide web</figcaption></figure><p>However, just because a word is at the end of a line doesn’t necessarily mean it will rhyme with the word at the end of the next line. For example, if the verse has the rhyming structure AABB, then at least one of those relationships (AB — the end word of line 2 and the end word of line 3) is a non-rhyming relationship.</p><p>This was the first major challenge that presented itself; <strong>how could we isolate only the rhyming pairs?</strong></p><p>One answer is to use the <a href="http://www.speech.cs.cmu.edu/cgi-bin/cmudict">CMU Pronouncing Dictionary</a> which is an:</p><blockquote>“open-source machine-readable pronunciation dictionary for North American English that contains over <strong>134,000 words</strong> and their pronunciations.”</blockquote><p>In practice, this meant downloading the entire dictionary as a JSON file and writing a function which determined whether any two words were a rhyming pair by checking if their <a href="https://en.wikipedia.org/wiki/Phoneme">phoneme set </a>matched up².</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSTOP3duiVqtKArFrz6K4g.png" /><figcaption>The first block shows the output of the CMU Pronouncing dictionary — a list of <a href="https://en.wikipedia.org/wiki/Phoneme">phonemes</a> for the word ‘fox’. The second block tests the working of the function which checks whether words rhyme (i.e. word1 ‘glue’ does indeed rhyme with ‘flu’ therefore it gets an output of True).</figcaption></figure><p>The function worked ‘phoneme-nally’ (I’m so sorry, I had to) and from a total of 47 439 end-of-line words, the function revealed that only 6 136 were actually rhyming pairs according to standard pronunciation (including half-rhymes like ‘stopped’ and ‘wept’). Now, as any good rap fan will tell you, there are plenty of ways to make words rhyme beyond ‘standard pronunciation’. I’d like to draw the class’ attention to Kanye West trying as hard as he can to make this point in ‘Hold My Liquor’ where he rhymed ‘in October’ with ‘Deepak Chopra’ (a non-rhyme according to the function I used here):</p><blockquote><a href="https://genius.com/Kanye-west-hold-my-liquor-lyrics#note-1904593">one cold night in October</a><br><a href="https://genius.com/Kanye-west-hold-my-liquor-lyrics#note-1871219">Pussy had me floatin’, feel like Deepak Chopra</a></blockquote><p>Another great example of unlikely companions is Kanye West and this cat he speaks so highly of.</p><h3><strong>Words of a feather plot together</strong></h3><p>Using only rhyming pairs to create the network led to a very different network structure. In the picture shown above, we have a dense network with lots of connections, but as you can imagine, when you only link words that rhyme, then you limit the scope for cross-network linkages, and instead you are left with many isolated mini-networks as can be seen below (there must be a technical term for this? Hit me up if you’re actually a Graph Theorist reading this with gritted teeth).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*at7_EvagSPsYEPgphQFRNQ.jpeg" /><figcaption>Network of rhyming pairs from the top 500 rap songs</figcaption></figure><p>In the above, clusters of many words which rhyme together form constellation-type shapes, words which only rhyme with one or two other words in the lyrics considered appear as short line segments, and the single points are words which are only observed as rhyming with themselves — like Pitbull’s infamous rhyming of “Kodak” with “Kodak” in <em>Give Me Everything — </em>and for this reason we shall henceforth call these nodes “Pointbulls”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C0xJYIHBoL_yZEHF2r5Ayw.gif" /><figcaption>Exploration of the rhyming pair network pictured above</figcaption></figure><h3><strong>Getting edgy: interactive plot to see frequency of rhyme pair occurrence</strong></h3><p>Going through these constellation structures gave me an idea for the kind of common rhyme patterns which appear in the lyrics but it still didn’t give me a good indication about which ones were the most popular. How many times have wine and fine been rhymed in this dataset?</p><p>For this we need to apply ‘weights’ to the edges which connect the nodes. The weights here are simply the number of times a rhyming pair appears across all of the lyrics considered. The below plot includes these weighted edges — they’re not visible at first sight but the plot is interactive so swim around a bit. You may even find some new rhyme ideas for that next chart-topper you’ve got bouncing around your noggin’.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Efuaadness%2F1.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Efuaadness%2F1%2F&amp;image=https%3A%2F%2Fchart-studio.plotly.com%2Fstatic%2Fwebapp%2Fimages%2Fplotly-logo.8d56a320dbb8.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2380c7a02a17c5b22f03be9111d513ff/href">https://medium.com/media/2380c7a02a17c5b22f03be9111d513ff/href</a></iframe><h3><strong>What have I learnt?</strong></h3><p>Well, that I owe Ms. Thee Stallion an apology, the rhyme between ‘fine’ and ‘wine’ did not appear once in these top 500 rap songs (only ‘fine’ and ‘whine’ appeared one time). Moreover, I owe her a further apology for being so judgy about her rhyme choices. Even if it did turn out that it was a very popular rhyme, like that of ‘bed’ and ‘head’ which *feigns surprise* is the most popular rhyming pair at 20 instances across the 500 songs, that wouldn’t relegate it to being a bad rhyme.</p><p>I started off believing that there were some rhymes which shouldn’t be in use anymore because they’re overused and tired, but this may imply that rap is nothing but an exercise in searching for new, interesting, ever more obscure rhymes. Left in the hands of myself, and my other quantitatively questioning quest-mates, rap may be reduced to a mere optimization problem where each new song tries to find the least-used rhyming pair.</p><p>So if this exercise has taught me anything, it is that trying to quantify hip-hop has made me ever more attentive to the kind of beauty which cannot be validated or invalidated with rational analysis. Seeing that Drake’s <a href="https://genius.com/Drake-hotline-bling-lyrics"><em>Hotline Bling</em></a> barely has any rhyming pairs (‘bling’ and ‘thing’ are doing the real heavy-lifting) makes me even more appreciative of a song I really enjoy because I can’t simply explain away why I like it, with math or fancy pictures.</p><p>What lies beyond the reach of quantification is wonder, and I think each attempt like this exposes the gap between what we know about hip-hop and what we feel when we listen to hip-hop. So may the unlikely companionship of rap and rigor continue, and for those who would like to play around and pick-up where I’ve left off, I’ve linked my truly shoddy code below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F75ZaxapnyMp2w%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F75ZaxapnyMp2w&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2F75ZaxapnyMp2w%2Fgiphy.gif%3Fcid%3D790b76116e95a0d65ae4f8af93c70157b528ae83825a901d%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad738262ebb9f2d98b0760552587c88c/href">https://medium.com/media/ad738262ebb9f2d98b0760552587c88c/href</a></iframe><p><strong>Links</strong></p><p>Plotly interactive network visualization: <a href="https://plotly.com/~fuaadness/1/">https://plotly.com/~fuaadness/1/</a></p><p>Github code for this project: <a href="https://github.com/fuaadness/rap_rhymes">https://github.com/fuaadness/rap_rhymes</a></p><p><strong>Notes</strong></p><p>[1] I only considered end-of-line rhymes, so no within-line rhymes. This is certainly something to add if anyone were to expand this analysis.</p><p>[2] Huge thanks to Ouflak from this <a href="https://stackoverflow.com/questions/25714531/find-rhyme-using-nltk-in-python/39312114">StackOverflow </a>thread, whose suggested answer became the basis for the function I ended up using to test rhyming pairs.</p><p>[3] Another huge thanks to <a href="https://medium.com/u/52f42f78df5a">Rebecca Weng</a> whose code for visualizing <a href="https://towardsdatascience.com/tutorial-network-visualization-basics-with-networkx-and-plotly-and-a-little-nlp-57c9bbb55bb9?source=user_profile---------0----------------------------">Shakespeare character appearances</a> helped me with the trickier interactive Plotly stuff.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FWI4A2fVnRBiYE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FWI4A2fVnRBiYE&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FWI4A2fVnRBiYE%2Fgiphy.gif%3Fcid%3D790b7611180bcf416a04f550105fb58359cbb8a56c4a1c58%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/739529ac1ab73f1a1aeb9003156c0a68/href">https://medium.com/media/739529ac1ab73f1a1aeb9003156c0a68/href</a></iframe><p><em>But I’m not a computer scientist — so there is no doubt an easier, more code-efficient way of going about this. I undertook this project because I wanted to learn about network analysis, so the code is perfect for those of you who want to see a beginner muddle their way towards an answer.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e70f22da488" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>