Science Forums: Computer-generated poetry - Science Forums

Jump to content

Welcome to ScienceForums.Net!

Welcome to ScienceForums.Net! We welcome science discussion at all levels — from beginners to researchers, covering topics from biology to computer science, and much more. Registration is fast and free, and allows you to post on the forums, so register now and join the discussions!
  
After you've registered, come in and introduce yourself, or visit the forum index. If you need any help  registering, posting, or if you just have some questions about our site, please feel free to contact us at staff at scienceforums dot net.

  • Start new topics and reply to others
  • Subscribe to topics and forums to get automatic updates
  • Create a ScienceForums.Net Blog!
Guest Message © 2012 DevFuse
  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Computer-generated poetry Rate Topic: -----

#1 Cap'n Refsmmat 


Icon
Mr. Wizard
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:

Quote

I am the Alpha and the Omega
of 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...)

Quote

Miscellaneous
supersedes 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)

Quote

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 merged
Also, 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.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#2 Mr Skeptic 


Icon
iDon't-Believe-You
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.
Our voting system is broken! It nearly guarantees that we will have only two political parties that have any chance of winning, and that they will be very similar.
0

#3 Cap'n Refsmmat 


Icon
Mr. Wizard
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 merged
Also, 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.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#4 insane_alien 


Genius
feed in the mcrosoft windows EULA and see what pops out.
Tired of waiting around for a reply on the forums? Use IRC, 'I don't know how' is no longer an excuse.

"Special" Relativity, stupid ideas seem smarter when they come at you really fast.
0

#5 Cap'n Refsmmat 


Icon
Mr. Wizard
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.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#6 bascule 


Genius

Cap said:

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.
Radicalism: The conservatism of tomorrow injected into the affairs of today.
-- Ambrose Bierce
0

#7 Cap'n Refsmmat 


Icon
Mr. Wizard
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?
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#8 Phi for All 


Icon
Electric Chairman
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.
0

#9 Cap'n Refsmmat 


Icon
Mr. Wizard
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?
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#10 bascule 


Genius
Use the output from one as the input for the other?
Radicalism: The conservatism of tomorrow injected into the affairs of today.
-- Ambrose Bierce
0

#11 Cap'n Refsmmat 


Icon
Mr. Wizard
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.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#12 Dak 


Icon
Wearing a hat since '06
What about allitteration?

Cap said:

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...
In 2005, 35% of those who voted, voted Labour. This is only of 22% those allowed to vote, and just 15.5% of the population; yet Labour have 55% of the power, giving them total control.
0

#13 Cap'n Refsmmat 


Icon
Mr. Wizard
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.)
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#14 vordhosbn 


Baryon
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.
0

#15 Cap'n Refsmmat 


Icon
Mr. Wizard
http://www.sciencefo...hyme/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 :D

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.)

This post has been edited by Cap'n Refsmmat: 27 March 2010 - 09:45 PM

Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#16 Royston 


Señor Butt Monkey
Of course Cap'n is fully responsible for the below...

Quote

The fever left her, and she served
She 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
0

#17 Cap'n Refsmmat 


Icon
Mr. Wizard
I've created a monster.

Merged post follows:

Consecutive posts merged
The source code repository is now available online:

http://bitbucket.org...robot/overview/

Enjoy. The brains of the program are available here.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

#18 Gilded 


Primate
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
Gonna paint the table, gonna paint it fine
Gonna use H2SO4 because the wood is PINE!
-
#sfn IRC chatroom - Where the fun never stops
0

#19 vordhosbn 


Baryon

View PostCap, on 27 March 2010 - 04:14 PM, said:

http://www.sciencefo...hyme/poetry.php

So, the poetry generator is up and running...


Hey, what happened with it? :huh:
- Which is worse - ignorance or apathy?
- I don't know and I don't care!
0

#20 Cap'n Refsmmat 


Icon
Mr. Wizard
Got lost when we moved the site to the new forum software. I can put it up again sometime.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users