Rhymatron Version 2 (3/12/2010)


Concept Overview

My interest in creating a fully-autonomous, generative rap-writing script has fully bloomed with this latest carnation of Rhymatron. One major component to the progress was my use of Carnegie Melon University’s phonetic dictionary. Although I did successfully create an automated web crawling script that would ping dictionary.com and extract its contents, I was advised that CMU’s dictionary already had this same information, and using it would not put me at any risk of shutting down a web server and getting into serious trouble.

Once the CMU dictionary was properly parsed and loaded, I used it to phonetically analyze a 4 verse rap by musical artist Mos Def, featured in the song “Two Words” by Kanye West. His original lyrics can be found here and a snippet from the song can be heard here. I distilled the lyrics down to syllables, and constructed a template generating new poems with the same meter and rhyme scheme.

Rhyme Template:

A B, – – – C, D B, D C,
D B, – C, E C, E C,
– E, E C, – – – EC,
– – – – EC, – – – – A


I approached the code writing portion of the project from numerous directions, and settled on this script. (Click for SOURCE CODE). Using custom functions, I am essentially plugging the above template directly into the program, which means that I can easily use the same program with different templates to get dramatically different results.

I played around with alliteration as well as rhyme, but this additional code would consistently cause errors from returning no matching words. I’d like to sort this out and implement the alliteration functionality, as well as adding in patterned parts of speech like adj-noun, noun-verb, etc, for more convincing word pairings.

Rather than feeding in the entire dictionary of words, instead I used Mark Twain’s, “Huckleberry Finn,” as a dictionary source so that only common language words would be used. I’d like to collect the lyrics from a few hundred hip hop songs to better acclimate the language of the outputted text to the genre from which the templates are derived.

Each time the script is run, entirely new content is made. Here are three different results from the script running:

(output one)

fished raise, embellishment, told bray, strokes numb,
folks brain, ones ones, pump wrung, shrunk crush,
licks flung, bulged skull, countenance enough,
ironical nonesuch, speculation drink.

spilt snakes, gratifying, shoals play, toes gusts,
strode shape, buts stubbed, bean crusts, frum crusts,
quaint nuts, hum mumps, occupied result,
altogether insult, hospitable jeer.

sink pay, circulation, broke knave, hoped lunch,
doan may, dad doves, blasts rush, jug buck,
phased ones, bluff rough, conclusions somewhat,
resurrected repulse, secondary if.

chips reigned, ultimately, low snake, jo pump,
dough rains, fished buzz, hens cuffed, crusts jumps,
fear huts, slough hump, bothersome construct,
prosecuted occult, indignity wrist.

(output two)

rows swam, animation, sniffs slapped, mere cul,
brings sag, guise dusk, white hunt, lined duds,
watched crime, stile buzzed, deliver discuss,
inquiries results, material so.

bolt slack, millennium, peer jabbed, quick mum,
bricks sass, clews crush, guy monk, chimed buzz,
thatch dried, buy hung, vacancy succumb,
execution nonesuch, tumultuous dough.

boat mapped, incognito, til snag, whip snug,
kin flags, beats snuffed, nines blood, live shunned,
style mild, twine sums, wantonly nonesuch,
memorable occult, unspeakable pope.

joke grabbed, comfortable, sting clang, lists us,
ing bang, whisked run, fist nub, time judge,
foe prime, sigh hum, augmented become,
testimony somewhat, astonishing yoked.

(output three)

flown sewed, resembling, laced poked, phased hill,
changed slowed, sheep crisp, toned thinks, grown winced,
gone goat, tote hilt, hurrying exist,
administered wherein, material owned.

cote bones, accomplishing, wail spoke, snakes cheers,
gray oaks, arms rigged, sock whip, owed springs,
floats knowed, smoke ridge, reasoning chagrin,
authorities wherein, military ode.

snow prose, recipients, brain ropes, waved ticks,
strange blow, trance pierced, blowed whips, rose pig,
sap holes, vogue fierce, occasioned severe,
unnatural admit, intelligent rome.

sew o, delivering, flayed growth, changed licked,
paint clothes, spilled its, been lip, strode stint,
nag stow, floats limp, palestine consist,
counterfeited appear, exhibited coaxed.

Source Code and Supporting Files

If you want to try running the source code yourself, here is a link to a zipped up file with all the necessary parts. (although its up to you to learn how to run python scripts from the command line.) LINK TO ZIPPED FILE.