Cap'n Refsmmat Posted March 10, 2010 Posted March 10, 2010 So, for fun, I put together a program to make computer-generated poetry. It uses a rhyming dictionary and Markov chains to throw together words in a way that works. Brief summary of how it works: I take some source text (the Bible, the novels of Mark Twain, whatever) and have the program go through and observe what word often comes after what three words. So if there's "the quick brown fox," the program will observe that "fox" can come after "the quick brown." It also does this in reverse, which will come in handy later. For the lines that don't have to rhyme, I just pick a random three words and choose any random word that can come after them, and work my way down the line. For lines that do, I find the word I have to rhyme with, look it up in the rhyming dictionary, and find a rhyme in my Markov chains. Then I work backwards through the line, making a line that makes sense and has a rhyming word on the end. Here's a few samples: I am the Alpha and the Omegaof love, knowing that I am Yahweh. Saul struck the Amalekites, from Havilah as was soulful, with a bit of jazz-- as though she was wearing a THONG. (I can change the "personality" in the middle of the poem, switching from the Bible to, well, other things...) Miscellaneoussupersedes and replaces all prior or contemporaneous If you are under 18, you may stare in fascination at the sexy display (using legalese and a few other things) He ambled Dollard, bulky slops,Carysfort Avenue and those shops Bloom of Crawford's journal sitting His unremitting square hat above large slops (Using Ulysses) So, here's my question to SFN: How can I improve this monster? My rhyming dictionary knows how many syllables each word has, so I can conceivably make poems that are restricted to certain numbers of syllables in each line. I can also attempt to make rhyming words have certain numbers of syllables, and so on. I can input my own rhyme schemes and have the program switch between "personalities" for different lines. What processing and cleverness would make this beast better? Think of what makes good poetry, then think of how a computer might do it... Merged post follows: Consecutive posts mergedAlso, what source texts would you recommend for good poetry? I have Ulysses, the Kamasutra, the Bible, some Mark Twain, some erotica, some Kafka, some legal documents, the Unabomber manifesto, and one or two others.
Mr Skeptic Posted March 10, 2010 Posted March 10, 2010 Have you tried feeding your program an actual poem to see what it spits out? Regardless, this is pretty neat. I think making it make sense would require some seriously advanced AI though.
Cap'n Refsmmat Posted March 10, 2010 Author Posted March 10, 2010 For good poetry, my input text needs to be 50,000 words or more. Otherwise, each word only has one rhyme or two in the source text, and so I end up just repeating chunks of the source text and using the same word to rhyme multiple times. I could crawl some website of amateur poetry and use that for text, though. Merged post follows: Consecutive posts mergedAlso, does anyone know how I could make poetry with meter and rhythm? I'd need a way of telling between stressed and unstressed syllables. I have a database of IPA pronunciations of words, which may help.
insane_alien Posted March 10, 2010 Posted March 10, 2010 feed in the mcrosoft windows EULA and see what pops out.
Cap'n Refsmmat Posted March 10, 2010 Author Posted March 10, 2010 I have that, plus Adobe, plus Apple, plus a few acceptable use policies. I need more text to be interesting. If you have any reallllly long legal texts you think might work, point me to them. (United States Code, in text file format? If you can find it, I'll use it.) Okay, turns out I now have an IPA pronunciation dictionary that includes stressed syllable markings. Parsing will be tricky -- it shows the stress marks before individual phonemes, not syllables -- but I might be able to use this to create meter. But first I'll do syllable counts so I can do haiku.
bascule Posted March 11, 2010 Posted March 11, 2010 So, here's my question to SFN: How can I improve this monster? Bust out your PHP skills and build a "simple" web site: You create multiple copies of the database, and then let random people talk to your poetrybots. At the same time you seed the different copies to produce "poetry" and let people vote on the results. After awhile, you kill off the losers and let the winner(s) live on, making duplicate copies for round 2, rinse, repeat. Bonus points for mixing together the databases of the winners and letting them "breed" Then comes the really hard part: attracting enough people to your web site to drive the intelligent selection process.
Cap'n Refsmmat Posted March 11, 2010 Author Posted March 11, 2010 Here's how the databases work at the moment: I have different source texts. I generate Markov chains for each source text and store them separately. Then, when creating a poem, I specific which source each line of the poem should use. I can do three lines from one source, then two from another. So I can already do mixing without mixing the back-ends. On the other hand, I could use the evolutionary idea for a different purpose, namely choosing the right settings. I'm going to add the ability to match syllables and basic meter to the poem generator, so for a given poem I'll have quite a few parameters: Syllables per line Meter "Brain" to use on each line Rhyme scheme And so on. I could evolve my way to the funniest concoction. Here's a question, though: how can I make my poems have a "theme"? That is, at the moment there's nothing to cause one line to be related to the next except by rhyme. They can discuss completely different things. How, if it's possible, can I make lines related?
Phi for All Posted March 11, 2010 Posted March 11, 2010 Can you force some words that would imply an analogy? That way your lines don't have to have a theme, they can be describing analogous attributes: How can my poems have a "theme"? Like pigeon toast or starlight cream? If they could sing it would be great, similar to the works of Nate.
Cap'n Refsmmat Posted March 11, 2010 Author Posted March 11, 2010 Tricky. I'd need to have sentences starting with "like" or "similar to" in my source text so that it would have something to go on. Now, I could use my list of words and their part of speech to pair together random nouns and adjectives. However, getting a line constructed in that way to fit in with the rest of the poem would be difficult. I also have a thesaurus file I could use to match similar words together. If I have words with similar meanings on nearby lines, would that make the poem sound more cohesive?
bascule Posted March 11, 2010 Posted March 11, 2010 Use the output from one as the input for the other?
Cap'n Refsmmat Posted March 11, 2010 Author Posted March 11, 2010 That's basically no different from mixing source texts together, since the only changes the poem generator makes are to rhyme things. (Well, you'd end up with the randomness of two Markov chains instead of one.) I found an interesting paper on the computer analysis of poetry that might help out. I think what I'll do is make some system of "scoring" lines according to different parameters (rhythm, rhyme, alliteration, etc.) and evolve the scoring algorithm to produce the best combination of parameters.
Dak Posted March 12, 2010 Posted March 12, 2010 What about allitteration? Here's a question, though: how can I make my poems have a "theme"? That is, at the moment there's nothing to cause one line to be related to the next except by rhyme. They can discuss completely different things. How, if it's possible, can I make lines related? How about building a database of the frequency with which words appear together in a paragraph, in order to gague relatedness? Or simply use a dictionary, and bias the program towards picking words that have similar words appear in their definition? e.g., checking in wiktionary, both 'boat' and 'moat' have 'water' in their definitions, so it might be possible to get the program to notice that and increase the chances of something like 'blah blah boat/ blah blah moat'? something like that? I guess then you could look for the pattern 'blah blah BOAT (VERB) blah blah MOAT' to grab an appropriate verb and get lines like the sail boat went down the moat umm... no doubt loads of false-positives from that tho...
Cap'n Refsmmat Posted March 12, 2010 Author Posted March 12, 2010 Hmmm. I know what I can do. One of my Markov chains (for use in rhyming) is first-order -- that is, it has a list of every word in the source text and every word that ever comes after it, along with how often that happens. So, we can assume that words that appear next to each other are likely related, yes? And if they appear next to each other more often, they're probably better-related. (Right? I think that makes sense.) So we aim to choose lines that are more "related," by this measure. Now, that's a weak association, really. I don't know what kind of related words you'd end up getting. Many common words appear next to many other words that aren't very related. So I could, hypothetically, aim to make the least common word on each line heavily related to the least common words on the previous line. What strategy seems best? (Also, yes, I should favor alliteration when choosing words. The stronger the alliteration, the better.)
vordhosbn Posted March 12, 2010 Posted March 12, 2010 I think it's more fun NOT to include meaning into the generation rules... People's minds are pretty good in ascribing it on random data. Just take care for the rhytm and rhyming.
Cap'n Refsmmat Posted March 27, 2010 Author Posted March 27, 2010 (edited) http://www.scienceforums.net/etc/rhyme/poetry.php So, the poetry generator is up and running. It works fairly well; it attempts to achieve iambic pentameter, it encourages alliteration, and it tries to make lines reasonably follow from each other (although this isn't always possible). Tinker around with it, and if you get anything really funny, well, post it here For "brains", each character represents one line. So uuubb makes the first three lines Unabomber, and the last two Bible. The number of characters in the brain specification and the rhymescheme must be the same. (Note that the Erotica option is definitely not work-safe, as well as several others. Please don't go posting the results all over the forum.) Edited March 27, 2010 by Cap'n Refsmmat
Royston Posted March 27, 2010 Posted March 27, 2010 Of course Cap'n is fully responsible for the below... The fever left her, and she servedShe deserved Now the men observed The curved He said as he stroked Howard's face" The fire of God came again to John's cock continued to spew Behold, the spew body, has the same object in view the balls swelling to match the hue Ulysses ryhmescheme, with the brains; bebsw
Cap'n Refsmmat Posted March 27, 2010 Author Posted March 27, 2010 I've created a monster. Merged post follows: Consecutive posts mergedThe source code repository is now available online: http://bitbucket.org/capnrefsmmat/rhyming-robot/overview/ Enjoy. The brains of the program are available here.
Gilded Posted March 27, 2010 Posted March 27, 2010 I heartily recommend this. PS. And after the thousand years, Satan will be released from what was his name, the Emperor whose wife cuckolded him a wall made by a plumb line, with a plumb the jet's tongue had dulled and there was some dim
vordhosbn Posted September 14, 2010 Posted September 14, 2010 http://www.scienceforums.net/etc/rhyme/poetry.php So, the poetry generator is up and running... Hey, what happened with it?
Cap'n Refsmmat Posted September 14, 2010 Author Posted September 14, 2010 Got lost when we moved the site to the new forum software. I can put it up again sometime.
Cap'n Refsmmat Posted February 4, 2011 Author Posted February 4, 2011 The poetry generator has been upgraded significantly to match the version I run on IRC. Test it out! http://www.sciencefo...hyme/poetry.php For those looking for risque poetry, I highly recommend "bbbex" or "bbbew" for "brains." (Also, the source code is available online. The majority of the logic is in "rhyme.py," if you're interested.)
lemur Posted February 5, 2011 Posted February 5, 2011 (edited) source text: lyrics of popular music available online. I don't know how much trouble it would be to compile numerous song texts though. thesaurus: maybe you could get it to use a thesaurus to find words that are more related than not. Could it randomly search through chains of synonyms by looking up synonyms and antonyms of synonyms and antonyms, etc. in search of rhymes, for example? Really neat project, btw. Edited February 5, 2011 by lemur
Cap'n Refsmmat Posted February 5, 2011 Author Posted February 5, 2011 Actually, the newest version that I put up today uses a thesaurus now. When choosing words to use, it preferentially chooses words that are synonyms of (but not the same as) words on previous lines. Unfortunately it's not very effective right now, so I'll continue working on that. Song lyrics would probably work, but I'd need a very large amount of them. I'll have a look at what I can get.
lemur Posted February 5, 2011 Posted February 5, 2011 (edited) Slant-rhyme can also be a liberating parameter in poetry. It may result in a mix of symmetry and asymmetry. I think the meter may be a more important factor though. It causes the text to sound like ebb and flow. (you know?) You might want to try transposing rhyme patterns from popular poetry. That might be worth a try. Since if it was me, it would be AABB or ABAB. Because anything more would cause my brain to fry. Edited February 5, 2011 by lemur
Cap'n Refsmmat Posted February 5, 2011 Author Posted February 5, 2011 I'm having difficulty creating meter, possibly because I don't understand everything that goes into it. I'll have to look into that more. Unfortunately my rhyming dictionary doesn't do slant rhyme, but considering that I have a pronouncing dictionary as well, I might just be able to fix that... You can choose the rhyme scheme in the poetry generator. If you make it four letters, make sure the "brains" choice is only four letters too.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now