Computerized Poetry

Poetry

One of the first assignments we did for this class was to create a Python script that would generate computerized poetry. My project was fairly simple, but I put quite a bit of effort into it nonetheless. Here is an excerpt from my poetry README file on GitHub as well as the code I used to actually generate poetry.

pythonpoetryscript / README.md

This is a Python script that takes Gutenberg’s text file of Oscar Wilde’s The Picture of Dorian Gray and recreates Jack Kerouac’s poem “In Vain” through the use of a template using the words from Dorian Gray. The original code can be found in a Colaboratory Notebook. I took inspiration for this type of poem from my professor, Zach Whalen’s, work in his own Template Poetry example he provided for us in class.

I chose Kerouac’s poem as the template for this project because he is one of my favorite poets and authors from the Beat Generation and because I love his style of writing. I chose The Picture of Dorian Gray as the text being integrated into this poem because it was one of my favorite books I have read (that is also out of copyright) and thought the text would fit with the theme of Kerouac’s original poem.

I created this poem with the intention of doing something similar to Alison Knowles’s “The House of Dust” (here is an examples by Nick Montfort) which is one of the earliest examples of computerized poetry. However, I did not want to simply recreate her project, leading me to find a poem that spoke to me to use as a template. Jack Kerouac’s work has had a special place in my heart since reading the introduction he wrote in Robert Frank’s The Americans (1958) and I wanted to include “In Vain” since it is a fairly historical poem, and I am a person who really enjoys history.

For this repository I have included my Python code, as well as a link to my original Colab Notebook I created it in. Since the notebook calls for the text file of The Picture of Dorian Gray to be run in the program, I have also uploaded the edited version I used, though it came directly from Project Gutenberg.

pythonpoetryscript / python_poetry_code

import random

from textblob import TextBlob
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')

with open ('/content/drive/MyDrive/Creative Coding/DorianGray.txt') as f:
  gray_text = f.read()

gray_blob = TextBlob(gray_text)



poem_text = """
The stars in the sky
In vain
The tragedy of Hamlet
   In vain
The key in the lock
      In vain
The sleeping mother
      In vain
The lamp in the corner
         In vain
The lamp in the corner unlit
            In vain
Abraham Lincoln
                        In vain
The Aztec empire
                           In vain
The writing hand: in vain
(The shoetrees in the shoes
         In vain
The windowshade string upon
            the hand bible
   In vain—
   The glitter of the greenglass
         ashtray
In vain
The bear in the woods
         In vain
The Life of Buddha
         In vain)
"""

poem_blob = TextBlob(poem_text)


poem_blob.tags



singular_nouns = []
plural_nouns = []
adjectives = []

for word,pos in gray_blob.tags:
  if(pos == 'NN'):
    singular_nouns.append(word)

  if(pos == 'NNS'):
    plural_nouns.append(word)
    
  if(pos == 'JJ'):
    adjectives.append(word)


random.choice(plural_nouns)


print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print("In vain")
print("The " + random.choice(singular_nouns) + " of " + random.choice(singular_nouns))
print(" " + "In vain")
print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + "In vain")
print("The " + random.choice(adjectives) + " " + random.choice(plural_nouns))
print(" " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " in the corner")
print(" " + " " + " " + " " + "In vain")
print(random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(plural_nouns) + " hand: in vain")
print("(The " + random.choice(plural_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " " + random.choice(adjectives) + " upon")
print(" " + " " + " " + " " + " " + "the " + random.choice(adjectives) + " " + random.choice(singular_nouns))
print(" " + "In vain—")
print("The " + random.choice(adjectives) + " of the " + random.choice(adjectives))
print(" " + " " + " " + " " + " " + random.choice(plural_nouns))
print("In vain")
print("The " + random.choice(singular_nouns) + " in the " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain")
print("The " + random.choice(singular_nouns) + " of " + random.choice(singular_nouns))
print(" " + " " + " " + " " + " " + "In vain)")

Project Reflection

One of the things I neglected to do when I created this project was generate poetry samples. I was so preoccupied with getting the code to work that I realized I did not fully complete the project. Oops!

But, that is what this assignment is for! To complete otherwise unfinished assignments! So, without further ado, here are some poetry samples that were generated from this code using Jack Kerouac’s poem “In Vain” as a template, but with the words from Oscar Wilde’s The Picture of Dorian Gray.

The price in the recklessness
In vain
The part of everything
 In vain
The club in the friend
  In vain
The true senses
   In vain
The ’ in the corner
    In vain
murder.
     In vain
The age.
      In vain
The apes hand: in vain
(The natures in the public
     In vain
The t last upon
     the ” news
 In vain—
The infinite of the ’
     foreigners
In vain
The hour in the moment
     In vain
The matchbox of peril
     In vain)
The life in the night
In vain
The corner of Anything
 In vain
The shudder in the rage
  In vain
The maddened windows
   In vain
The address. in the corner
    In vain
work
     In vain
The reason
      In vain
The faults hand: in vain
(The scenes in the lad
     In vain
The girl following upon
     the last experience
 In vain—
The monotonous of the artist
     influences
In vain
The life in the t
     In vain
The spring of sound
     In vain)
The word in the orchard
In vain
The “ of room
 In vain
The round in the mother
  In vain
The locked stones
   In vain
The wind in the corner
    In vain
insolent
     In vain
The s
      In vain
The lashes hand: in vain
(The dolphins in the mine
     In vain
The “ English upon
     the strong chair
 In vain—
The hideous of the dull
     rings
In vain
The CHAPTER in the absolution
     In vain
The woman of him.
     In vain)

These three samples are ones that I liked the most after running the code more than a few times. One thing I noticed is that the code wants to isolate quotation marks and singular letters and treat them like words. Normally I would have an issue with that, but since this is supposed to be computerized poetry I think it adds to the charm. A computer will only know as much as you can offer to teach it, so having a few minor errors in there make it appear more real. Plus, it makes it interesting to read it aloud as “comma” and “quotation” as if it were part of the poem.

I have added each of these poetry examples of my GitHub repository as well, since I neglected to create any examples before now. I really enjoyed doing this assignment though, because it shows poetry can really be made of anything and that meaning can be derived from the results. The combination of Kerouac and Wilde to generate computerized poetry is something I never would have seen myself doing, but I rather like it. It’s interesting and no two results are the same!

Leave a Reply

Your email address will not be published.

css.php