Rhymatron.net has officially launched BETA! (4/30/2010)

The Rhymatron Python project has finally launched on a working website. Behind the scenes, the web server is running a Python script to pre-generate enormous lists of rhyming words and rhyme keys. Then a user selects from a list of pre-fabbed templates (or creates their own) and the poem/rap output gets spit out. Rather than this output being static, instead the user can adjust any word by clicking up and down arrays to cycle through other words from that same rhyme key list. A word that is intended to rhyme will continue to rhyme, even when it has been replaced.

Check it out at Rhymatron.net

Rhymatron – Markov Chain Update (4/09/2010)

After learning about word counting, ngrams, and markov chains, I’ve made some tweaks to the rhymatron script to produce a better output.

Now each word pairing is of two words that appear next to each other in natural language (and I increased the dictionary’s scope by expanding the source texts to include Alice in Wonderland and Moby Dick, in addition to Huckleberry Finn).  Still there is room for additional improvement, but the output is definitely one step closer to passing a Turing test.

Here is a link to the updated code.

And here is one example of the improved output:

guile thronged, overtaking, dipped bores, this twists,
prints paw, legs fills, pangs slicked, path sin,
edge ann, blanche lip, sophia amidst,
correspondents begin, indignity by.
spliced bors, figurative, mince froth, slit wilks,
hit ward, trim fins, stirred twists, blanc lip,
mouths mat, calf whips, worshippers cashier,
disagreement exist, circulation i.
pikes pours, gentlemanly, lids yore, lives inn,
tricked loft, grit lear, sleeps crib, dat chill,
purge van, crab slipped, whoever sincere,
discouraging wherein, malefactors stile.
time more, insensible, clipped hauled, jim string,
licked tore, holes stings, foiled chips, wrap list,
that wrapped, act sings, perception begins,
dedication until, futility child.

guile thronged, overtaking, dipped bores, this twists,

prints paw, legs fills, pangs slicked, path sin,

edge ann, blanche lip, sophia amidst,

correspondents begin, indignity by.


spliced bors, figurative, mince froth, slit wilks,

hit ward, trim fins, stirred twists, blanc lip,

mouths mat, calf whips, worshippers cashier,

disagreement exist, circulation i.


pikes pours, gentlemanly, lids yore, lives inn,

tricked loft, grit lear, sleeps crib, dat chill,

purge van, crab slipped, whoever sincere,

discouraging wherein, malefactors stile.


time more, insensible, clipped hauled, jim string,

licked tore, holes stings, foiled chips, wrap list,

that wrapped, act sings, perception begins,

dedication until, futility child.

Rhymatron Version 2 (3/12/2010)

yeti_mic

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

Process

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.

Rhymatron – Generative Text Poetry Robot (2/18/2010)

PROJECT OVERVIEW

I’m interested in writing a program that can generate poems and raps, after feeding the program a series of source texts. I have a lot to learn before I can tackle such an advanced programming problem, so with this current project, I sought after a simple, incremental step towards my long-term goal.

In this project, words are substituted from Robert Frost’s poem, “Stopping By Woods On A Snowy Evening.” Rather than merely substituting random words, I wrote a Python script that searches through a secondary text, looking for words that rhyme with the original words from the poem.

————————————————-

link to SOURCE CODE

————————————————-

DESCRIPTION OF CODE

In plain english, the Python script behind this project does the following:

Part 1 – Strip Robert Frost’s poem into lines, then strip each line into words, and then store each word in memory. If the final word of any line contains a punctuation character, then strip off that last character and store it memory.

Part 2 – Strip a user-defined text into lines, then strip each line into words, and finally store each word in memory. If a word has any punctuation characters, strip these characters from the word.

Part 3 – Try to find rhyming words in the user-defined text. Look through each word and search for the patterns eep, ake, ear, ough. If the word is a match, then store the word in memory.

Part 4 – Reassemble the words of the poem into lines, substituting the last word from each line with a rhyming word from memory, following the rhyme scheme of AA, BABB, CBCC, DCDD, DD. Append each line with punctuation characters as needed. Print out all the lines of the new poem.

————————————————-

DEMONSTRATION 1 – Frost meets Twain

Source poem: Robert Frosts, “Stopping By Woods On A Snowy Evening
Source text: Mark Twain’s, “Huckleberry Finn

Outputted Poem:

Whose woods these are I think I bough.
His house is in the village below.
He will not see me stopping anywhere.
To watch his woods fill up with widow.
My little horse must think it tear.
To stop without a farmhouse interfere.
Between the woods and frozen namesake.
The darkest evening of the sincere.
He gives his harness bells a flake.
To ask if there is some sake.
The only other sound’s the asleep.
Of easy wind and downy bake.
The woods are lovely, dark and sheep.
But I have promises to deep.
And miles to go before I weep.
And miles to go before I weep.

————————————————-

DEMONSTRATION 2 – Frost meets Shakespeare

Source poem: Robert Frosts, “Stopping By Woods On A Snowy Evening
Source text: William Shakespeare’s, “All’s Well That Ends Well

Outputted Poem:

Whose woods these are I think I flow.
His house is in the village though.
He will not see me stopping interfere.
To watch his woods fill up with barlow.
My little horse must think it appear.
To stop without a farmhouse gear.
Between the woods and frozen cake.
The darkest evening of the bedivere.
He gives his harness bells a strake.
To ask if there is some take.
The only other sound’s the weep.
Of easy wind and downy bake.
The woods are lovely, dark and sweep.
But I have promises to peep.
And miles to go before I keep.
And miles to go before I keep.

————————————————-

NEXT STEPS

Although this is working relatively well, clearly the outputted text would be more believable if the substituted words maintained the correct number of syllables and remained grammatically correct. To achieve these improvements, I need to learn how to check the enormous list of words to assess their number of syllables and to evaluate whether they are nouns, verbs, adjectives, etc. Somewhere between our lessons on Regular Expressions and WordNet, I expect to pick up the needed skills to take this project even further.

Generative Text Mashups with Python (2/04/2010)

THE TAO OF BUSINESS

1
If businesses fail to honor their responsibilities to society and don’t believe in corporate stewardship, who in our society will?
Therefore the sage goes about doing nothing, teaching no-talking.
What does a business enterprise owe its customers and consumers?
The sage stays behind, thus he is ahead.
What standards of conduct and performance should an enterprise set for its employees and agents?
Therefore the sage is guided by what he feels and not by what he sees.
What is the role of industry and government in setting business and professional standards?
Therefore the sage, traveling all day, does not lose sight of his baggage.

2
What is the optimal mix of values and rules to guide decision-making and action?
Therefore the sage takes care of all men.
What structures, systems, practices, and procedures will best implement the values and rules of the enterprise?
When the sage uses it, he becomes the ruler.
What outcomes should one reasonably expect from an enterprise’s decisions and activities, and how can an enterprise track, measure, and report them?
Therefore the sage avoids extremes, excesses, and complacency.
What can they reasonably expect?
Thus the sage knows without traveling.

3
Who speaks for the environment and future generations as stakeholders?
The sage has no mind of his own.
What is the role of business in sustainable development?
The sage is shy and humble – to the world he seems confusing.
Who can rightfully claim the power to govern an enterprise?
Therefore the sage says: I take no action and people are reformed.
How can the board of directors and management best protect the rights of shareholders, especially minority shareholders?
Therefore the sage is sharp but not cutting, pointed but not piercing, straightforward but not unrestrained, brilliant but not blinding.

4
How can the board of directors best guide management to meet the reasonable expectations of shareholders?
Not only will it do no harm to others, but the sage himself will also be protected.
If the employees want to bargain as a group, how should the RBE relate to its workers?
The sage does not attempt anything very big, and thus achieved greatness.
Should it bargain with the group of employees?
Because the sage always confronts difficulties, he never experiences them.
Are there circumstances under which such a contract should not be enforced?
The sage does not act, and so is not defeated.

5
What does it mean to be a responsible business?
Therefore the sage seeks freedom from desire.
Is this easy?
If the sage would guide the people, he must serve with humility.
What does it mean to be the owner or manager of a responsible business enterprise?
In this way when the sage rules, the people will not feel oppressed.
What challenges does your enterprise face in the years ahead?
Therefore the sage wears rough clothing and holds the jewel in his heart.

—————————————————————————-

What is the source material?

The above passage is a “mash-up” of texts from two original sources:

Source 1 – Tao Te Ching, by Lao-Tzu
Source 2 – Business Ethics, by the US Secretary of Commerce

Both texts were combined into one giant String and were processed and outputted with a Python script:
Combined Source Text
Python Script Source Code

—————————————————————————-

What does the script do?

The Python script is designed to search for two different keywords within a body of text. Any line of text from the source that contains one of the keywords is extracted and stored in a list of saved lines. Next the script outputs alternating lines from the saved lists. After four paired lines are outputted, one line is skipped to create stanzas of text. After five stanzas, the script stops.

This script could be used with any text input to search for any two distinct terms. For example, you could input the text of the newspaper and search for the words “peace” and “war”. The script would find any lines that contain either of those two terms, and then would construct a new text body where one line spoke of peace and the next line spoke of war, alternating back and forth. The output could be constrained to have line breaks after any number of lines and could continue for any desired length.