views:

1212

answers:

24

Computer Haiku

How would you write a program

To make them for you

A: 

I'd start with some kind of dictionary file that contains a syllable count of each word in it. Then pick words from that add up to the required syllables/line

As to making it poetry, and not just random words, I have no idea.

Ian Jacobs
Poetry vs. random words, who the difference can tell? ;-)
joeforker
Text-to-speech programs come with pronouncing dictionaries.
joeforker
A: 

You could, in addition to using Ian's idea of syllable counts, also categorize the words by part of speech and generate phrases.

Brian
+1  A: 

I would look up syntactical programming and linguistic and try to find libraries for grammatical structure. From there it should be a simple step to add the word count and syllable count constraints.

mvrak
+6  A: 

Not all haikus have the same number of syllables, but it's a place to start.

In terms of actually picking the words, I think that parts of speech would not be the place where I would start. Instead, I would look at Markov chains, and train your vocabulary on existing haikus.

Craig Stuntz
markov chain on pairs or more of words from haikus and other poetry i think would be pretty damn good!
nlucaroni
Actually haikus have the same number of syllables, that's their definition: http://en.wikipedia.org/wiki/Haiku
Mnementh
Hmm, read this too: http://en.wikipedia.org/wiki/Haiku#Contemporary_English-language_haiku "Use of three (or fewer) lines of 17 or fewer syllables"
Jonik
bah! Contemporary-English haiku? what crap.
Kevin
+11  A: 

First, you'll want to look into Markov chains, and second, there's a book about computer-generated poetry called Virtual Muse.

Bill the Lizard
A: 

From the semantic sude of the story use sampling and fourier transformation. Pick significant parts of some detailed description reduced in single words and leave to a reader to fill in gaps with her own imagination

Boris Pavlović
Please expand on how you can deconstruct a story as a sum of sine or cosine waves of various frequencies.
joeforker
well, what is the idea of sampling? sampling the signal with a frequency which is at least double of the highest frequency in the range of interest. if you have descreet information extracted like this you can reconstruct the analog input without any loss (in the interested range)
Boris Pavlović
analogous to this pick up significant verbs, nouns and adjectives which are corner stones in some description and leave everything else. compose these words in meaningfull arrays and you'll get haiku
Boris Pavlović
+2  A: 

implement a genetic algorithm to generate haikus drawn from a dictionary annotated with syllable counts, then pay people to read and rate them as the fitness function [mechanical turk would help]. Over time your program should evolve some good ones.

EDIT:

a GA you need
evolves at CPU speed
if fitness you heed

Steven A. Lowe
I'd love to see an implementation of this one. Genetic algorithms intrigue me greatly...
Erik Forbes
+9  A: 
  • count the syllables
  • randomly generate words
  • arrange sensibly
Jason S
It would have been *oh so much better* without your comment. Thats kinda like reminding the audience that "The last sentence, you know, **that** was the punchline. Did you get it?"
mizipzor
ok, fine, i'll delete the comment if you delete yours
Jason S
(FWIW mine was the first smart-ass answer so I was wary of being downvoted)
Jason S
+25  A: 

Measure syllables

Understand semantic flow

Your goal can be met

patros
+10  A: 

Do not attempt it

Poetry does not mix well

With metal and bits

More seriously, good haiku (and even bad haiku) is a lot more about condensing meaning and imagery than counting syllables. It is generally also based on themes gathered from nature. Random word generation and syllable counting will get you measured gibberish, but not poetry...

Jeff Kotula
I don't know. The search for meaning in randomness seems deeply human. What is a poem that had no meaning put into it, but only the meaning taken from it by the reader? Is it a model of secular humanism?
joeforker
"...syllable counting will get you measured gibberish, but not poetry." ... i thought telling the difference was what "reading poetry" was all about.
mizipzor
+1  A: 

"To convey one's mood in seventeen Syllables is very diffic . . ." (The great John Cooper Clarke Check out Beasley Street, one of my favourites)

How much more diffic for a computer? Logic knows no moods :)

Binary Worrier
It's much easier then - as there would be less variables if there are no moods. You just need to convey indifference every time.
Sohnee
+1  A: 

Some people here suggested using a dictionary and generating word sequences using a Markov Chain. That seems like a theoretically viable solution, especially if you use a high-order Markov Chain (not bi- or trigrams).

But I think in practice it would work better if you could collect a database of existing haikus and selectively change single words in them (e.g., change a given word to another, semantically related word). The existing haikus give you some kind of structure and cohesion, and you just need to (ex-)change little parts in them in order to create a new haiku (a variation on the old one).

Of course they won't be completely new haikus with this method, but at least they will be somewhat enjoyable for the readers.

+2  A: 

To make it readable, separate the dictionary into Nouns, Verbs, Adjectives, with syllable count.

Come up with some templates of the form:

[Noun] [Verb]"s"

[Verb] a(n) [Adjective] [Noun]

[adjective] [noun]

and trim your dictionaries to the beautiful words.

nailitdown
A: 

Parse existing haikus in a relational order, like word xx used after yy n times. So when creating, possibility of xx coming after yy will be (n / sum of count of all words used after yy). This way it will be selectively randomized and can still be a valid haiku.

Orkun Balkancı
That is a decent description of the idea behind Markov chains. If word y comes after word x 75% of the time in the source, then y will be chosen 75% of the time in the output.
joeforker
really? i just made it up.
Orkun Balkancı
It works better with sets of three words, however: what word follows these two words.
JUST MY correct OPINION
+1  A: 

Write your program to generate Haiku's in Japanese. It will be far easier to measure your syllable count, pluse you are staying faithful to the original language of the poetry. If you have flexibility with the project, why not make the original Japanese - then show the English word by word literal translation by its side. It will look mysterious to say the least.

Anyways, just a different take on the problem.

Elijah
A: 

I'd do my homework!

Adrian
I assure you I am out of school.
joeforker
Writing a Haiku-writing application as homework? I'd *like* to go to that school!
Joachim Sauer
Nearly year it took, to compose that comment, I'd vote it up!
Adrian
+2  A: 

On Haiku Village, we have the technology to easily do this in a variety of ways. One idea is to simply read the global twitter feed, and detect unintentional haikus. Since the back-end also has a dictionary, it would be possible to produce questionable haikus, but I think the quality would be lacking.

I think if we had a star rating system, then I suppose machine learning could be used to decide what is 'good'.

+1  A: 

Your program must grok
Metaphores and imagery
And be creative.

Adam Jaskiewicz
+2  A: 

Haikus are easy, that I'll note
Solutions well documented, and functions rote
They're overdone and cheesy
Coding far too easy
Code me a limerick, then I'll vote

//I actually like haikus

Mike Robinson
+1 for the best poetry in the world.
Sohnee
A: 

I love this question. It is very imaginative. Answer Below.


Many people have suggested Markov chains, but I really don't think it would be possible. You need to know intelligently whether the syllable is a PHONEMES then you have to know where the syllable ends.

If you ever did this I would be amazed.

Laykes
At some point you may wish to look up what the words you use actually mean in English.
JUST MY correct OPINION
+1  A: 
for (i is 0
and i is less than thirteen)
echo syllable
Sohnee
A: 

I'd start by ignoring all the responders who think the plural form of haiku is 'haikus'.

matthuhiggins
A: 

The algorithm for having a computer output high quality haiku works something like this:

Setup Phase

loop:
  find the email address of a world-renowned writer of haiku
  confirm that this person is willing to generate haiku on demand
until sucker^H^H^H^H^H^Hwriter is found

Execution Phase

loop:
  wait for a haiku request
  when a haiku request is received, email the previously-stored master and ask for a haiku
  wait for the haiku to return by reply
  output haiku

There are, of course, various enhancements which can be made upon this fundamental architecture. For example the setup phase can be extended to set up a pool of haiku experts. The execution phase can be used to generate haiku during idle times and cache them against future demand. The specifics of such tweaking are left as an exercise for the student.

JUST MY correct OPINION
A: 

Markov Sequences
A syllabic Database
Three lines of python

TokenMacGuy