78

Computer Haiku
How would you write a program
To make them for you

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
joeforker
  • 40,459
  • 37
  • 151
  • 246
  • 7
    Hire an infinite number of monkeys. In addition to the complete works of Shakespeare, you'll get an infinite number of Haikus. – Jon B Feb 02 '09 at 19:39
  • 2
    @Jon B: But that would take infinitely long. – Bill the Lizard Feb 02 '09 at 19:46
  • +1 for the question, and the comments thus far. – Michael Haren Feb 02 '09 at 20:27
  • 1
    @Bill, If you had an infinite amount of time, you would only need to hire one very healthy monkey. If you hire an infinite number of monkeys, your literature will be produced at a rate limited only by the typing speed of a particularly brillant monkey. – joeforker Feb 17 '09 at 14:08
  • O c'mon, you know thats incorrect, one can not contain an infinate subset inside an infinate container. Google "Super counting" for more info to see why its not possible. please note, a subset of the container itslef is infinate, but not a limited object.. – Darknight Oct 22 '09 at 10:03
  • scrap that, its not called super counting, Its something similar. – Darknight Oct 22 '09 at 10:07
  • @Darknight, didn't quite get your objection, but http://en.wikipedia.org/wiki/Infinite_monkey_theorem should enlighten. Infinity of time vs monkeys is equivalent if the infinities create independent events. – Unreason Jul 19 '10 at 12:07
  • @Unreason, yes its not an natural thing to grasp, simply put: Possible Haiku combination = Infinite; Number of Monkeys OR Time required to produce said Infinite Hakim = NOT possible, as in order to generate those Infinite Haiku's you would need a greater than Infinite amount of time Or GREATER THAN infinite amount of monkeys. Now do you see the contradiction? – Darknight Jul 19 '10 at 12:42
  • @Darknight; you have several fallacies in your reasoning; first the number of all possible Haiku's is not infinite. Secondly, it was not requested to generate all possible Haiku's. Thirdly, when comparing two infinities one should compare the 'rate of each' (checkout L'Hôpital's rule). – Unreason Jul 19 '10 at 13:23
  • @Unreason, how did you come to the conclusion that all possible Haiku's are not infinite? – Darknight Jul 19 '10 at 13:32
  • 1
    @Darknight, well because Haikus, by definition are composed of 17 moras and the number of moras (or ons) is finite. Therefore the number of combinations, which is arguably less then the number of actual Haikus, is number_of_moras^17. This is only in regards to the written representation of the Haiku, not its meaning. (The number of meanings might actually be infinite, even for a much smaller number of haikus, however it was not requested to write a program that will interpret a haiku, but *only* write it) – Unreason Jul 19 '10 at 13:48
  • @Unreason, fixed moras = fixed width Information transmission. Transmission width has nothing to do with source encoding/decoding which as you have correctly identified could be infinite. So this comes back to to original point. – Darknight Jul 19 '10 at 15:03
  • @Darknight, fixed number of moras in haiku, also there are a few thousand possible moras (iirc) => fixed total number of possible haikus (in written form). Information transmission width has nothing to do with it, it is not an infinite stream, it is a fixed size packet; also, I have said that number of meanings *might* be infinite, but that was a hyperbole referring to Borges and ten thousand things (chinese); in the real universe at any given moment, languages and language constructs are not infinite, in mathematical sense. So, the point is pretty much proven. – Unreason Jul 19 '10 at 15:21
  • Write a program to post this question to every Q&A site you know. – new123456 Dec 22 '10 at 21:18

22 Answers22

36

Measure syllables
Understand semantic flow
Your goal can be met

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
patros
  • 7,719
  • 3
  • 28
  • 37
20

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

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
Jeff Kotula
  • 2,114
  • 12
  • 16
  • 7
    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 Feb 02 '09 at 22:02
  • 1
    "...syllable counting will get you measured gibberish, but not poetry." ... i thought telling the difference was what "reading poetry" was all about. – Mizipzor Feb 19 '10 at 13:54
13

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
  • 398,270
  • 210
  • 566
  • 880
10
  • count the syllables
  • randomly generate words
  • arrange sensibly
Jason S
  • 184,598
  • 164
  • 608
  • 970
  • 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 Feb 19 '10 at 13:57
  • ok, fine, i'll delete the comment if you delete yours – Jason S Feb 19 '10 at 14:24
  • (FWIW mine was the first smart-ass answer so I was wary of being downvoted) – Jason S Feb 19 '10 at 14:25
9

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
  • 24,971
  • 8
  • 61
  • 83
5

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
  • 125,891
  • 12
  • 252
  • 273
  • markov chain on pairs or more of words from haikus and other poetry i think would be pretty damn good! – nlucaroni Feb 02 '09 at 19:20
  • Actually haikus have the same number of syllables, that's their definition: http://en.wikipedia.org/wiki/Haiku – Mnementh Feb 02 '09 at 19:25
  • 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 Feb 02 '09 at 19:30
  • 3
    bah! Contemporary-English haiku? what crap. – Kevin Feb 02 '09 at 20:35
5

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

3
for (i is 0
and i is less than thirteen)
print s i plus plus
Fenton
  • 241,084
  • 71
  • 387
  • 401
2

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
  • 60,273
  • 18
  • 132
  • 202
2

"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
  • 50,774
  • 20
  • 136
  • 184
  • It's much easier then - as there would be less variables if there are no moods. You just need to convey indifference every time. – Fenton Feb 19 '10 at 14:29
2

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
  • 7,868
  • 11
  • 36
  • 37
2

Your program must grok
Metaphores and imagery
And be creative.

Adam Jaskiewicz
  • 10,934
  • 3
  • 34
  • 37
1

Markov Sequences
A syllabic Database
Three lines of python

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
  • My `haiku` function [here](http://thingspython.wordpress.com/2012/12/27/gibberish-haiku-generator/) can be collapsed to just 2 lines, not counting imports. – PaulMcG Jan 25 '13 at 08:29
1

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
  • 501
  • 3
  • 12
1

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.

Frank
  • 64,140
  • 93
  • 237
  • 324
1

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ı
  • 868
  • 1
  • 8
  • 19
1

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
  • 13,368
  • 10
  • 57
  • 89
0

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
  • 35,674
  • 17
  • 77
  • 99
0

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
  • 5,456
  • 1
  • 23
  • 38
0

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

Brian
  • 25,523
  • 18
  • 82
  • 173
0

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ć
  • 63,078
  • 28
  • 122
  • 148
  • Please expand on how you can deconstruct a story as a sum of sine or cosine waves of various frequencies. – joeforker Feb 02 '09 at 19:31
  • 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ć Feb 02 '09 at 23:05
  • 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ć Feb 02 '09 at 23:07
-1

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.

Layke
  • 51,422
  • 11
  • 85
  • 111