Advertisement

Researchers teach a computer to compose sonnets like Shakespeare

An AI-generated sonnet by any other name would smell as sweet

In addition to penning 37 plays, William Shakespeare was a prolific composer of sonnets -- crafting 154 of them during his life. Now, more than 400 years after his death, the Bard's words are influencing a new generation of poets. It's just that these writers do so with silicon imaginations and digital quills.

A consortium of researchers from the University of Toronto, the University of Melbourne and IBM's Australia division have managed to teach a neural network to craft sonnets just as the Bard did in the 16th century, using his own words to teach the machine. They published their results at the 2018 ACL conference, and you can play around with the network itself over at GitHub.

Sonnets follow a specific structure and rhyming pattern. Each is composed of 14 lines -- three quatrains followed by a couplet. For example, here's Shakespeare's Sonnet 18, one of his most well-known:

Shall I compare thee to a summer's day?

Thou art more lovely and more temperate:

Rough winds do shake the darling buds of May,

And summer's lease hath all too short a date.

Sometime too hot the eye of heaven shines,

And often is his gold complexion dimmed;

And every fair from fair sometime declines,

By chance, or nature's changing course, untrimmed;

But thy eternal summer shall not fade,

Nor lose possession of that fair thou ow'st,

Nor shall death brag thou wand'rest in his shade,

When in eternal lines to Time thou grow'st.

So long as men can breathe, or eyes can see,

So long lives this, and this gives life to thee.

"We are interested in understanding whether these forms can be learned automatically from data," Jey Han Lau, research scientist, IBM Research (Australia) told Engadget, "without relying on external knowledge sources such as syllable or pronunciation dictionaries."

Poetry-generating AIs have been in development since the turn of the century. However, a vast majority of them simply scoured pronunciation dictionaries for their rhymes rather than figuring it out for themselves from available datasets. The IBM system, on the other hand, leveraged more than 2,600 sonnets gleaned from Project Gutenberg -- in addition to Shakespeare's 154 -- for training, development and testing. The results are procedurally generated sonnets so well-composed that they're virtually indistinguishable from those written by people.

The combined total of 2,600 examples is actually a rather small dataset for training a neural network, Lau admits. "The scale [in the order of thousands of sonnets] is actually tiny compared to the typical training data that a deep-learning system takes," he wrote via email. "We had to be fairly creative when designing the network -- we can't have an overly complex network, as it will simply memorize the sonnets. The key is that we want the network to generalize its learning so it can compose new poems." Here is a shortened example:

so gently, as the wind that flaps his wings

and shoots a monarch on the English lays

and what was that, with matters of all things

tis well ashamed to know— of all her ways

Because the system understands the whys in addition to the hows of sonnet creation, it can (in theory, at least) be adapted to generate them in any language.

The system isn't perfect, mind you. While the generated poetry is good enough to fool the casual reader, literary critics the researchers showed the poetry to were not particularly impressed. Specifically, the experts pointed to a "lack of readability and emotion" in the AI's text. However, the researchers are looking into methods to further improve the system's poetic output.

"The readability part might be easier to tackle -- we can first train the model on a large amount of poetry data (i.e., not limited to sonnets), and then train the model again using just the sonnets, and that should help improve the generated poem's readability," Lau wrote. "The emotion issue is a little more tricky -- it isn't obvious (to us, at least) how to define the emotional quality that a poem has, and so the first thing we need to do is think carefully what makes a poem emotional."

Whether or not the team is able to further enhance its AI's writing skills, this research should help advance neural-network technologies as a whole, Lau explained. "We demonstrated that certain features can be learned automatically from data with an intelligently designed network architecture [rhyme and rhythm, in our case]," he said. "And so the same principle can be applied to other generation systems."

Automated systems have been slowly creeping into the art world in recent years. Bay Area artist and engineer Alex Reben has leveraged AI to reimagine episodes of The Joy of Painting as Bob Ross-centric acid trips, generate ghostly portraits of fictional people and even mimic the vocal cadences of famous actors. Similarly, Cambridge Consultants recently developed a system that converts your scribbles into works of art that would put Van Gogh to shame. None have managed to match the literary acumen of Shakespeare himself -- but we're getting closer.