robot poet

The Oxford Dictionaries API is used in a huge variety of applications. One of our favourites is Poem Generator, which lead to an afternoon of great fun in our Oxford office. Here, we interview its creator, Sha Crawford, about the challenges of programming a computer to write poetry – and the kind of results you can expect!

Project name: Poem Generator

Platform: Desktop (App version currently in development)

Language: PHP / Javascript

So, first things first: what can you tell us about the app?

Poem Generator is a collection of tools that generate poems based on user input, using third party tools – such as the Oxford Dictionaries API. In some cases, the generator writes structured pieces like a haiku or sonnet, but it can also write less restrictive verse.

A computer generated haiku:

amusing daybreak
auto generator writes
despite the artform

The generators are not examples of artificial intelligence; they are computer-written, and use algorithms based on our understanding of language. The results are interesting and often amusing. They provide food for thought, allowing users to tweak or create their own work using ours as inspiration.

The generated poems are often clunky and unexpected, but I quickly learnt that this was what users liked about them. They enjoy refreshing the page to see what Poem Generator will come up with next!

Why did you decide to create it? What gave you the idea for the site?

For years I’ve run two novelty/parody websites, Song Lyrics Generator and Plot Generator. When asked for suggestions, users of the site often requested a poem generator. I shied away from exploring computer-generated poetry because it seemed considerably harder than the generators I’d previously developed. Plots were free form and songs were either very basic or parodies of existing lyrics. To work well, poetry required rhyme, rhythm, and imagery.

Earlier this year, having set aside some time to work on the generators, I started looking into interfacing with existing word banks via their APIs. I came across Datamuse, which is a fantastic service that let me lookup rhymes, count syllables and find related concepts for words. I started building poem generators using their tools.

The following automatically generated verse takes the words ‘modern’ and  ‘poetry’ then automatically chooses a contrast: ‘traditional and handwritten poetry’ and works them into a poem.

I saw the modern expressive style of my generation destroyed,
How I mourned the poetry.
Never forget the traditional and handwritten poetry.

After writing haiku, sonnet, and limerick generators, I used online tools to find out what other types of poetry generator people were searching for. I noticed that many people were interested in computer-generated acrostics.

First, I looked for existing acrostic generator tools. There are some great ones out there. However, most acrostic generators seemed to have fairly limited banks of sentences and one would be picked at random using its initial, with no content matching. I wanted to create a generator that came up with lines on the fly, and that those lines would be linked to the content of the poem.

An example of an acrostic where a computer has found lines linked to its vertical word:

P-oetic similes rhyme.
O-dorous juxtapositions contrast.
E-loquent passages flow.
M-arvelous stanzas strut.

At first, I toyed with the idea of allowing acrostic lines to begin with any word type, but I quickly found it was difficult to get the poem as a whole to flow. I needed to pick one grammatical word type, one tense, and one voice, and then stick to them.

As a general rule, nouns need to be plural to start a sentence. ‘The cat’ and ‘A dog’ are great if you want sentences beginning with ‘A’ and ‘T’, but are useless for the range of letters found in most names and words.

I used Datamuse to find words related to the user’s topic, then the Oxford Dictionaries API ‘entries’ endpoint to find whether a word or concept could be plural. If a word is not found using the ‘entries’ endpoint, that doesn’t necessarily mean it’s not in the dictionary; another possibility is that the word, as I have it, is not its root form.

I then used the ‘inflections’ endpoint. An ‘inflections’ query can be used to find the root form of a word, but actually contains enough information that I rarely need to make an additional request. Eventually, I’m left with a list of plural noun phrases grouped by their initial. The user gets to pick which of these noun phrases will end up in the final poem. The lines are then automatically completed using random selections from verbs commonly paired with each noun.

Once I started using the Oxford Dictionaries API, I realized its power. I set to work building word lists and structures that allowed me to develop additional types of poem generator.

What are the limitations of automatically generated poetry? What was your biggest challenge?

It is very difficult to ensure that computer generated poetry is inoffensive. Even if users input innocuous words, the random and robotic nature of choosing rhymes and synonyms can lead to rude poems. Woe betide the user who wants to write a limerick about a duck or the person who tries to write a haiku about a spotted dick!

Because some young teenagers use the site, words are checked against a list of potentially offensive terms and these are filtered out. Even then, there’s nothing to stop the generator accidentally coming up with euphemistic imagery. I’ve put a disclaimer to this effect on the site.

What do you hope to do with the project next?

At the moment, my generators require users to input structured data. For example, my sonnet generator asks for three verbs, and requires that they are entered in the first person present. This requires a degree of work from the user that a more pure poem generator would be able to do automatically.

Thanks to the Oxford Dictionaries API giving me the ability to ascertain words’ grammatical types, I will be able to allow users to input words with fewer restrictions. I’m hoping my generators will be able to turn prose into poetry in the near future.

In partnership with Red Bulb, I am creating an app that will improve the generator experience for people with handheld devices and hopefully help us reach a wider audience.

Poem Generator simply fits words into pre-written templates, many of which are borrowed from famous poets. This is what the users of Poem Generator are looking for. On a personal level, I would love to explore more psychologically-based poetry creation such as using neural networks to produce truly original results.

  • The opinions and other information contained in OxfordWords blog posts and comments do not necessarily reflect the opinions or positions of Oxford University Press.