A Rose is a Rose is an Algorithm: ISI Students Create Award-Winning Interactive Poetry Generator

August 22, 2017

If you need a little poetic inspiration, a team of three students from USC's Information Sciences Institute has just the thing: an interactive poetry generation system, which recently won best demo award at the 2017 Association for Computational Linguistics (ACL) conference.

The system, named Hafez after the 14th-century Persian poet, was designed to quickly weave any topic into a poem and trained using a data set of one one-million song lyrics.

Since launching nine months ago, Hafez has generated more than 10,000 poems, with topics ranging from presidential candidates to poverty, love, mountains and even Dungeons and Dragons.

"We've found that people like positive or negative poems but not poems with a neutral sentiment," says team lead Marjan Ghazvininejad, an ISI PhD student.

The system's interactive option allows users to tweak various elements of a generated poem, for example: adding alliteration, choosing a positive or negative sentiment and altering the word length.

"We apply our user feedback to train the system, so there is a loop to improve its performance over time," says Ghazvininejad.

It turns out, human-computer collaboration generates the best-rated poems, with 71 per cent of users assigning a higher rating to at least one adjusted poem.

Inspiration for the project stemmed from Ghazvininejad's prior research in password memorization, where she investigated the use of poems as a mnemonic device.

When Ghazvininejad heard about a Dartmouth College competition to create a machine-generated sonnet, it clicked: use algorithms to quickly pen a poem on a certain topic, then alter it to suit your preferences.

Turning topics into verse

The creators of the Hafez poetry generation system, with supervisor Kevin Knight, from left: Marjan Ghazvininejad, Jay Priyadarshi and Xing Shi.

Ghazvininejad teamed up with fellow PhD students Xing Shi and Jay Priyadarshi, under the supervision of professor Kevin Knight, to create a poetry generation system that integrates a Recurrent Neural Network (RNN) with a Finite State Acceptor (FSA).

"When you ask our system to generate a poem on a topic, it uses a model trained on Wikipedia to find a list of words related to the topic," says Ghazvininejad.

"Then it selects rhyming words randomly from these words. This way, each time the system is asked to generate a poem, it selects a different set of rhyming words and generates a totally different poem, even if it's about the same topic."

The team used the FSA machine to control the meter and rhyming words. To ensure fluency, they employed a deep learning sequence-to-sequence model, which is guided by the FSA.

One of the key advantages of this system over others is its fast generation speed, which the team optimized by vocabulary pruning and fine-tuning the graphics processing unit (GPU) computation for peak performance.

"Overall, we can generate a four-line poem within two seconds; 10 times faster than our previous central processing unit (CPU) system," says Shi.

The team published their system as an Amazon Alexa skill called Custom Poetry, which has generated almost 3,000 poems to date. It was also one of the winning entries in the Amazon Alexa Skills Challenge competition in June, 2017.

Going forwards, Ghazvininejad is continuing to research machine learning for poetry applications, but is now shifting focus to automated poetry translation.

But the team wouldn't rule out expanding the interactive poetry generation system to other creative applications. In fact, an ISI professor is interested in using the system to create lyrics for his automatic music-generation system.

Here's a poem generated by Hafez on the topic of creativity:

No inspiration from my generation.
The time has come for me to demonstrate,
But then I take it like an imitation,
Think of all the things that you create.

Create your own poem using Hafez.