Grammars and the Random Goth Lyric Generator

To celebrate one of the last days of National Poetry Month as well as The Accidental Developer’s 100th blog post, I will attempt to combine a bit of computer science and poetry.

I’ve been studying grammars and formal languages, among other things, this past semester in my Theory of Computation class. One thing that it reminded me of was the second Javascript application I ever developed (with the help of my friend and college classmate Miranda Tarrow): The Random Goth Lyric Generator.

I took a simple sentence structure (subject, verb, adjective, object) and made random substitutions for each line, 4 lines per stanza, 4 stanzas per poem.

The (slightly less-than-formal) grammar for each line would look something like this:
Line -> SSL | PSL
SNP -> Singular Noun | Singular Noun Phrase
PNP -> Plural Noun | Plural Noun Phrase
SV -> Singular Verb
PV -> Plural Verb
A -> Adjective
O -> Object

We could extend this to the entire poem:
Poem -> Stanza Stanza Stanza Stanza
Stanza - > Line Line Line Line

The word list was meant to be dark and foreboding but was often hilarious–the examples included:

Nouns & Noun Phrases:

  • My solitude
  • Your touch
  • A ravenous she-wolf
  • Spiders

Verbs & Verb Phrases:

  • entangles
  • summons
  • grovels before
  • spews forth


  • labyrinthine
  • diseased
  • spectral
  • infernal

Line -> SSL -> SNP SV A O could become:

Your touch entangles infernal spiders.

I don’t know why the list of objects was a separate list of nouns, as it seems to me now that it could have pulled from the same list. Since the grammar used just one sentence structure, the results were very repetitive but frequently humorous. I often considered expanding the possible sentence structure (something as simple as making the adjective optional), but decided that the repetition was part of the charm. In fact, many poems and song lyrics feature repetition, and the results seemed eerily intentional at times.

The page was very popular for a time. I received quite a bit of e-mail regarding the page, including suggestions for additional words. Someone sent a song they’d recorded for which they used the random lyrics (with the addition of a shouted, “There’s that m———— word again!” in the middle). At least one randomly-generated poem was published in a small poetry journal.

I’ve considered creating a sequel to parody William Carlos Williams and loading it up with words from his own poems:
Poem -> S1 S2 S3 S4
S1 -> Noun Verb newline Preposition
S2 -> Article Adjective Noun newline Noun
S3 -> Adjective Preposition Adjective newline Noun
S4 -> Preposition Article Adjective newline Noun

Which might produce something like:

no one spilled

the whole honey

pressed after sweet

while the urgent

It just doesn’t seem quite as funny or compelling. I can venture a guess that William’s sparse form and carefully selected language doesn’t lend itself to random imitation as well as verbose and self-indulgent free verse. Although perhaps the sample is merely too small!

Generating puzzles for a Four-by-Four Word Game

A few years ago, I made a crossword-like game wherein users fill out a 4×4 grid of letters to spell 8 words (4 across and 4 down):

Four by Four word puzzle game

However, over the course of several days, I was able to develop only 20 puzzles by hand. Trying all the various combinations is clearly a task better suited to computers than humans. Such a grid has 16 slots, each of which can contain one of 26 letters–so there are 2616 total permutations to check. That’s about 43,000,000,000,000,000,000,000–which could take a very long time, even for a computer. One key to speeding things up is to ignore permutations that don’t contain words.
Continue reading Generating puzzles for a Four-by-Four Word Game