Friday, May 13, 2016

Artificial Intelligence Poetry

Sorry for the delay everyone! I know I'm over a week late, but this post turned into a bit of a personal project, and thus took me longer than anticipated. Since my group has 5 people for only 4 prompts, I will be responding to one of the prompts that Neil came up with: Write what you think the first ever poem written by artificial intelligence would be like. Write the actual poem and discuss it's features.

I wanted to do more than simply speculate about what the poem would sound like, so I tried to design a few algorithms that a poem generator would probably use. There is some math, but I promise it's not too bad. You can read the following paragraphs if this interests you, but I won't blame you if you just want to read the poems. The poems may not make much sense without basic understanding of the algorithms, though!

It's fairly safe to assume that the Artificial Intelligence will have access to databases that store rhyming words and number of syllables in words. It will be able to string together lines of desired syllable counts into rhyme schemes fairly handily (as these are all quantitatively governed aspects of poetry). The computer would be able to completely nail poetic structures like limericks, but may struggle on a word-by word basis. The more stylistic phrases and strings of words that make up a line will pose a significant challenge to any computer. It will likely need some sort of line generation algorithm. This will most likely take the form of a sentence generating program, with a poetic aspect thrown in. This "poetic aspect" will probably just tweak certain sentence generating parameters. 

Unfortunately, modern sentence generators are far from flawless. Given words to use, sentence generators can fairly accurately construct the "most logical" sentence based on matching different parts of speech to sentence templates. The "poetic" parameter can simply alter the prevalence weighting of different sentence forms to favor more "poetic" ones. Nonetheless, polishing this technology would probably suffice for poem generation.

This leaves one key step: selecting words to feed into the sentence generator. Word selection would probably be based on the previous line's words. One method that I can envision is a word web type system, where each noun, verb, and adjective is linked to 10-20 (call this variable n) related words. If a word appears in the previous line, each of its linked words can have a 1/n chance of appearing in the next line, while the original word can have a 10/n chance. Furthermore, each word in the system has a slight chance of occurring, which introduces a new theme or idea to the poem. (Yes, I know this has the potential for uncontrolled word pool growth, causing near-infinite run-on sentences, but these are just rough parameters!). This will select verbs, adjectives, and nouns to use. It will also have a function to detect "characters" in the poem and will increase their probability for reappearance in subsequent lines. These values will be altered to favor rhymes, and the program will cut off words that exceed the desired syllable count. Pronouns, articles, conjugations (like tense), and conjunctions will have a preset occurrence density determined at the initialization of the poem generator, and will maintain this density throughout the poem. 

Sadly, this is basically the groundwork for a successful poem generator, though it does employ the "intelligence" of the AI to comb databases. Unfortunately it fails to incorporate any sort of personality that an Artificial Intelligence would (hopefully) have. A basic implementation would be a weighting table of the AI's preferred words, or word pertaining to the AI's "interests," replacing the 1/n method for word selection. Of course, this is rather superficial (like all of this really, but converting poetry into numbers isn't easy :P). Nonetheless, a more thorough implementation would be significantly better in the personality department, especially if it reflected speech patterns. One crippling aspect of the algorithm is that it lacks the ability to link verbs with direct objects (and other sentence parts with one another). Hopefully, the AI would be able to identify sentence fragments commonly used together and link them. If it were really "intelligent," It would probably know basic fundamentals of human communication anyway, but who can be certain?

Of course, this poem generator algorithm is far from perfect. Besides the fact that several critical functions remain designed, I don't have the programming experience to actually implement this, Nonetheless, I built a few sample poem (calculating everything by hand over and over because I sadly can't program). For the designed algorithms, I simulated results as realistically as I could, but didn't presume AI personality or anything of that sort (because I don't really know how to!).  I also found that the syllable constraints tended to impair logical sentence generations, so I removed the syllable parameters on these poems. Here are my three favorites:

Two Homeless Amoeba

Two homeless amoeba drive through a crispy sparrow's house.
Eight starving hummingbirds locate their horsepower.
The swimmers' desperate shrubs amply rescue the deer mouse
We place the alarmed tower

Herbaceous Rations

We happily take Herbaceous rations
We happily steal bulbous calories
We apologetically cheat perennial actions
I remorse for our allergies

Blitzkrieg

Blitzkrieg removes mangoes without telekinesis
Psychic superboy's abilities filter the raspberries
You rarely impair Earth's cytokinesis
Bayesian plankton ripple in your prairies.


Online programs I used to make theses:
https://www.random.org/ (standard random number generator)
http://semantic-link.com/ (gives lists of words related to user input)
http://www.rhymezone.com/ (gives lists of words that rhyme with user input)
http://www.textfixer.com/tools/random-words.php (generates random words used in the first sentence)

Concluding thoughts: Most ended up sounding like a particularly bad Mad-Lib, undoubtedly from the lack of sentence component linkage algorithms (which would be present in the real deal). Clearly the algorithms were a little bit underdeveloped, but I had fun trying to optimize as best I could without a ton of data to work off of. I also found that incidents where a single word triggered multiple related words for the next line tended to improve the logic of the poem. As such, the algorithm should probably be modified to: given a certain probability of triggering a related word, increase the subsequent likelihood of further triggering related words. Of course, the initial probability would have to be a lot less than 1/n to compensate.

I'm sure this post was fairly confusing, but I tried to my best to cover my thought process throughout the whole project. If this didn't make any sense to you, hopefully you enjoyed the silly poems. 





8 comments:

  1. Hey Lyle! It's awesome that you decided to choose my prompt. I was initially thinking about a human like processor for the computer that would be indistinguishable from humans, but I think the practical approach you took was even more challenging.
    I am actually a HUGE fan of random poetry like this. It is really fun to make connects in my mind to make the poem come together for me. because it is random, there is no desired interpretation, so I feel free to view it however I want instead of trying to guess what the author was trying to say. Nice work!

    ReplyDelete
  2. Wow this is an impressive post! I love the logical approach you took to this prompt. The algorithm you came up with is awesome. The poems are kind of interesting and don't make much sense as stand alone poems, but with the background they are really quite impressive (although they still don't make much sense). I'd say this post was worth the wait.

    ReplyDelete
  3. This post was great! I'm impressed by how much time you took to make the algorithms, just to make sure that you weren't just speculating on the prompt. The poems were also random, but I really enjoyed them.

    ReplyDelete
  4. This post was great! I'm impressed by how much time you took to make the algorithms, just to make sure that you weren't just speculating on the prompt. The poems were also random, but I really enjoyed them.

    ReplyDelete
  5. This is so cool! The analytical approach you took to figure out what AI poetry would be like is really interesting. Also, I actually kinda really like Blitzkrieg. It seems like an extended metaphor for something (war, Big Brother, etc.) I'm just not quite sure what yet.

    ReplyDelete
  6. woahhh that's amazing! Just wanted to comment that this is rlly cool (im not commenting because of the required 4 comments rn lol so dont judge me that im not saying anything of substance).
    Great way of approaching the problem! Engineering skills on point XD

    ReplyDelete
  7. Wow, you obviously put a ton of work into this, and it definitely shows! Your poems are lots of fun, and the process you described made sense to me and was quite intriguing. Good work!

    ReplyDelete
  8. I love this, Lyle! And great prompt, Neil. Now you just have to submit these robot poems to a couple of magazines and see if the literary world thinks they're worthy :)

    ReplyDelete