Computer Haiku
How would you write a program
To make them for you
Computer Haiku
How would you write a program
To make them for you
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.
You could, in addition to using Ian's idea of syllable counts, also categorize the words by part of speech and generate phrases.
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.
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.
First, you'll want to look into Markov chains, and second, there's a book about computer-generated poetry called Virtual Muse.
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
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
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...
"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 :)
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.
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.
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.
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.
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'.
Your program must grok
Metaphores and imagery
And be creative.
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
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.
I'd start by ignoring all the responders who think the plural form of haiku is 'haikus'.
The algorithm for having a computer output high quality haiku works something like this:
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
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.