How to use deep learning to write Shakespeare

LSTM recurrent neural networks can be trained to generate free text. Let’s see how well AI can imitate the Bard

1 2 Page 2
Page 2 of 2

Smokin’ on cookie in the hotbox cookie
F*****’ on your b**** she a thot, thot, thot thot
Cookin fellow, and the best of our that she could else was not a toman.
Good faith, hold, I beseech your grace,—

-King Lear
Then there’s so much to him.

-King Lear
Thou hast seen a part of this plainness I had thought to see the ride on the sea sevel never second to take the foul fiend.
Still through the way that shoulds: I know not what.

What dost thou see her? O unhappy girl!
Sir, this desperate, bastard! what news?
Mistage on my father!

-King Lear
What say’st thou st?

Sir, I do know you;
And to the Moor and rain, I beserve her take my sisters?

-King Lear
No, no, no, no! where’t the castle.

Enter Gloucester, with King of France and Cordelia Goneril
Sir, I had thought it not.


Indeed! ay, indeed: desceme, sir.

Sighing, would!

What dost thou see how this paper shall I carry out a fellow there, that makes his son a poor poor power
That makes his son
When the rain came to the devil wrath!
I have lost the king from the cold wind:
Take them what the …

It is interesting to see that the AI-generated text talks about an unhappy girl, a foul fiend, and a desperate bastard, which—along with other words—express concepts very close to those contained in many rap songs.

What deep learning learned from Shakespeare

We have reached the end of this experiment. We have trained a recurrent neural network with a hidden LSTM layer to produce free text. What have we learned?

To sum up, the network was trained on the full texts of Shakespeare’s plays “King Lear,” “Othello,” and “Much Ado About Nothing.” It learned to produce free text in Shakespearean style. It just needed a 100-character initial sequence to trigger the generation of free text.

We have shown a few different results. We started with a dialogue between Othello and Desdemona to see how the network would continue it. We also made the network write a completely new scene, based on the characters and place we provided. Finally, we explored the possibility of improving Modern English with Shakespearean English by introducing a touch of Shakespeare into the text of a license agreement and into the text of a rap lyric. Interestingly enough, context-related words from Shakespearean English emerged in the free generated text.

These results are interesting because real Shakespearean English words were used to form more complex sentence structures even when starting from Modern English sentences. The neural network correctly recognized main or minor characters, giving them more or less text. Spellings and punctuation were mostly accurate, and even the poetic style, i.e., rhythms of the text, followed the Shakespearean style.

Of course, experimenting with data set size, neural units, and network architecture might lead to better results in terms of more meaningful dialogues.

If I have awakened your curiosity about the ability of a neural network to generate free text and the quality of the text that can be achieved, I will be conducting a poster session on the topic at the KNIME Spring Summit in Berlin from March 18 to 22, 2019. Attendees will be able to discuss the deep learning network experiment and actually trigger the network to generate free text in different languages (English, Italian, and German) and different styles (from Shakespearean prose to rap lyrics).

Rosaria Silipo is principal data scientist at KNIME. She is the author of more than 50 technical publications, including her most recent book “Practicing Data Science: A Collection of Case Studies”. She holds a doctorate degree in bio-engineering and has spent 25 years working on data science projects for companies in a broad range of fields, including IoT, customer intelligence, the financial industry, and cybersecurity. Follow Rosaria on Twitter, LinkedIn, and the KNIME blog.

New Tech Forum provides a venue to explore and discuss emerging enterprise technology in unprecedented depth and breadth. The selection is subjective, based on our pick of the technologies we believe to be important and of greatest interest to InfoWorld readers. InfoWorld does not accept marketing collateral for publication and reserves the right to edit all contributed content. Send all inquiries to

Copyright © 2019 IDG Communications, Inc.

1 2 Page 2
Page 2 of 2