GenereraEnHaikuDikt.se

The simple web frontend is shown with a set of generated haiku.

About

GenereraEnHaikuDikt.se is a website which generates haiku at the press of a button. You can try it out here (unfortunately it’s only available in Swedish). It was created as the project in the course TDDD01 with four other students. The system was implemented in about 14 hours.

Our goal was to create a system that is able to generate haiku that can fool humans into thinking that the haiku is written by a person.

How it works

Training

Our system begins by training itself on a set of haiku written by humans. It sorts all words into three different bags:

  • One hash table containing all words that the lines in the haiku starts with.
  • One hash table containing all words that the lines in the haiku ends with.
  • One hash table containing all words that come in between the start and stop words.

In all of the hash tables, the keys are the number of syllables, the value is a list of all words with that number of syllables.

We also build a bigram hash table where the key is the first word and the value is a list of all words that has followed that word.

Generation

Generation starts out by trying to generate a line containing 5 syllables. The system chooses a starting word by randomizing the number of syllables, getting the list from the start word hash table with the amount of randomized syllables and finally picking a random element from said list.

If there are syllables left for this line, a new random number is generated. If there will be syllables left over after subtracting the random number from the amount of remaining syllables, a random middle word is chosen according to the above procedure. Else, a stop word is chosen according to the above procedure.

This is repeated until three lines with 5, 7, and 5 syllables are generated. After that, the generation is complete.

Check out the source code here.