There have been some very nice projects done around using machine learning algorithms for poetry generation. In particular, a lot of these works use Long Short Term Memory (LSTMs), a kind of neural network to generate sequential data. It is done by training the LSTM on a collection of poems and then the network is able to produce new poems. I was particularly interested in generating acrostics. These are poems in which the first letter of each line forms a phrase (which generally is the theme of the poem). There are other kinds of acrostic too- forming a certain image with letters combined, with the letters forming a word or phrase too. I began by modifying the code of a popular recurrent neural network repository (char-rnn) to take a word or phrase as input and generate an acrostic with that. This was done by modifying the sampling procedure of the code.
Here’s a couple of examples of computer generated acrostics from that-
Happy New Year
HERE into life expand their gifts,
And mournfully cease, that lead, divine,
Pride of the liven presses of Christinage,
Pour the blush’d painters was eternal bloom,
Yet vow’d delightand pass his fate of day,
No sharp foremosop in strife,that lift wise,
Even to dividing ills to balm?
What sorrow, there, thy hand whom blaze each snowy shore.
Yet thro’ again of heather with mountains forth,
Enamoured, all turn, tears was die,
And all thee did you visit hear,
Rage, he were giving on his head of injuring sigh.
poetry is fun
pour no our day so dealer hills,
once him he wisdom
enath a thrush of leaping thench,
the blushing I lives, in green monarch’s light;
riseit shall scarce before it finds to heal.
yes have his name we say not in those all of macry.”
in fires where the suffering bances! shaken free the Morning stines.
said the hand, reared, and seeing to this bed
from the heavens that whirled it takes
unstills a brittle vale, we see his hand,
nor the burns that flown affections blest.
I thought these were pretty fun outputs. One aspect lacking definitely was the acrostic word or phrase had no actual influence on what the poem was about, apart from forming the first letters. One way i began to tackle that was using word embeddings. The overall idea was to use the word or phrase and try and find similar words to that using a word embedding. I used the ConceptNet5 API for that. Once i got a list of words close to the given word or phrase, i searched words among it starting with a letter matching with the input phrase or word (which forms the acrostic). Then these matching words became the first word of the corresponding line in the acrostic. If no matching word is found, then the letter itself is used. I also hooked it up with an image recognition network using Tensorflow to take an image as input- classify it- take the classification word and run the above process on it.
Here’s an output of an acrostic poem generated with an input image (recognized as umbrella):