Computational Poetry

From Wikicliki
Revision as of 07:50, 2 November 2016 by WikiSysop (talk | contribs)

Jump to: navigation, search

Welcome to the notes for a Computational Poetry Class by Debbie Ding, held at The Substation on 3 November 2016!

Introduction

This class is designed for people who do not have any programming background but who have an interest in generative poetry and have an open mind to learning some simple methods for non-coders to create their own textual mashups. In this 2 hour class we will try to cover:

  • A Very Very Brief History of Bots, AI, and Spam
  • Introduction to RiTa + p5.js
  • Setting up a local web server on your computer (Mac/Win)
  • Generating a simple 'Singlish Haiku'
  • Generating a duologue between Belle (Disney's Beauty and the Beast) and Didi (Waiting for Godot)
  • Generating a prose mashup

and hopefully, some time for experimentation!

Equipment required:

  • a working laptop (most modern laptops should work)
  • wifi connection (which will be available at the substation)
  • example files (will be available for download at the class - I'll also have it available on thumbdrives)
  • and you! the human input!

Skills required:

  • being able to type on a laptop
  • being a human

I first decided to make this when someone (a designer, not a programmer) asked me how to create a text mashup and I was trying to explain to her how simple it was to do with open source libraries such as RiTA. In today's class, I'd like to share with you the most simple way to create a text mashup from available open source tools, which will hopefully spark your further adventures into other aspects of natural language processing...

A Very Very Brief History of Bots, AI, and Spam

Iwanttobelieve.png Furbyban.png

  • Turing test - See Alan Turing's 1950 paper, Could a computer think?. Turing shifts the question from "Can machines think?" to "Can machines do what we (as thinking entities) can do?"
Turing suggests a test inspired by a party game known as the "Imitation Game" in which a man and woman go into separate rooms and guests try to tell them apart by writing them a series of questions and reading only the typewritten answers which are set back. What happens if a machine takes the part of one of the humans in this game? Will the interrogator decide wrongly on who is the actual human when this game is played as it is when played between two different humans? These questions replace the original question of "Can machines think?
  • ELIZA - an early natural language processing program designed at MIT's Artificial Intelligence Lab which was able to convince humans that it understood us, although it had no framework for actually contextualising or understanding events or speech. Considered one of the first programs to have passed the Turing test.
ELIZA is based on very simple pattern recognition, based on a stimulus-response model. ELIZA also introduced the personal pronoun transformations common to ALICE and many other programs. "Tell me what you think about me" is transformed by the robot into "You want me to tell you what I think about you?" creating a simple illusion of understanding.

Weizenbaum tells us that he was shocked by the experience of releasing ELIZA (also known as "Doctor") to the nontechnical staff at the MIT AI Lab. Secretaries and nontechnical administrative staff thought the machine was a "real" therapist, and spent hours revealing their personal problems to the program. When Weizenbaum informed his secretary that he, of course, had access to the logs of all the conversations, she reacted with outrage at this invasion of her privacy. Weizenbaum was shocked by this and similar incidents to find that such a simple program could so easily deceive a naive user into revealing personal information.

What Weizenbaum found specifically revolting was that the Doctor's patients actually believed the robot really understood their problems. They believed the robot therapist could help them in a constructive way. His reaction might be best understood like that of a western physician's disapproval of herbal medicines, or an astronomer's disdain for astrology. Obviously ELIZA touched something deep in the human experience, but not what its author intended.
Between their big round eyes, they have an infrared transmitter and receiver of the kind found in television remote control sensors. As well as parroting what they overhear, they can recite a small repertoire of one-liners, sleep, giggle when tickled, or groan when they are swung by their ears.
Because of its ability to repeat what it hears, Security Agency officials were worried "that people would take them home and they'd start talking classified", according to one anonymous Capitol Hill source. Photographic, video and audio recording equipment are all prohibited items for employees at the NSA. "This includes toys, such as 'Furbys,' with built-in recorders that repeat the audio with synthesized sound to mimic the original signal," the Furby Alert read.
  • IoT, IFTTT
  • Apple Siri, Microsoft Cortana, Amazon Alexa

Glossary of Terms used in this page

Bobbytables.png

  • HTTP - Hypertext Transfer Protocol. This is the protocol used by the World Wide Web. It defines how messages are formatted and transmitted, and what actions Web servers and browsers are supposed to take in response to commands.
  • HTML - Hyper Text Markup Language. This is a Markup language, not a programming language, which means it is a language used to define the content in a webpage.
  • Javascript - This is a programming language commonly used with HTML. It is used to create functionality in a webpage.
  • Python - This is another programming language. It was designed to be very readable even to humans, by using more english words (as opposed to using punctuation).
  • AJAX - Asynchronous JavaScript and XML - which means to use the XMLHttpRequest object to communicate with other server-side scripts. It is "Asynchronous" because it can make new requests to the server without requiring the page to be reloaded, and thus it is used to update the page based on events. This is really useful and is often used to make pages 'responsive', allowing you to design a page that will change accordingly as you resize the browser window.

For more definitions:

Setting up your own Web Server

Why do you need to set up a "local web server"?

If you open up a HTML page in your browser, most browsers restrict how that HTML page can access other resources. For example: A script on http://dbbd.sg can only perform AJAX requests for other files on http://dbbd.sg, but a file on your computer (which we would refer to a a "local file") has no domain, and therefore cannot perform any AJAX requests.

To get around this, you can either change your browser's security settings for local files, but this is generally inadvisable, as you would not want pages and scripts from the internet to be able to open or access local files on your computer - that would pose a great security risk. So, we have to set up a local web server in order for us to be able to run these scripts today.

Mac: Python SimpleHTTPServer

All new Macs have Python installed. First open Terminal (Which can be found inside Applications > Utilities). Check which version of python you have by typing "python" into Terminal. Then navigate to the folder with your files inside it.

cd /path/to/project/folder 

Use Python's built-in http server:

# Python 2.x
python -m SimpleHTTPServer

# Python 3.x
python -m http.server

Files from that directory will be served up at localhost under port 8000, so you can view the files from that directory if you type this into the browser:

http://localhost:8000/

Mac: Apache

First, open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:

sudo su -

Enable Apache on Mac OS X

apachectl start

Verify it works by accessing it at localhot under port 8080

http://localhost

or

http://localhost:8080/

The default DocumentRoot for Mac OS X is /Library/WebServer/Documents. Whatever is inside this folder will appear when you type into localhost.

Usually whilst doing this, it is also useful to enable PHP for Apache together at the same time in case you might use PHP.

First make a backup of the default Apache configuration before you edit it.

cd /etc/apache2/
cp httpd.conf httpd.conf.bak

Then edit the Apache configuration.

vi httpd.conf

Scroll down and uncomment the following line (remove #) - press X over the letter and save with :wq Currently, the # is actually "commenting out" this line and stopping it from running, but you just need to delete the # to enable PHP for Apache.

LoadModule php5_module libexec/apache2/libphp5.so

Restart Apache:

apachectl restart

Verify PHP is enabled by creating a phpinfo page in your DocumentRoot. The default DocumentRoot for Mac OS X El Capitan is /Library/WebServer/Documents. Create a file named phpinfo.php and save this snippet inside it.

<?php
phpinfo();
?>

Other alternatives:

Windows: Apache

These are some of the easy one-click ways of running a local apache server on Windows, but since Windows doesn't have Apache or Python pre-installed, you can't just activate it. You'll have to use one of these local server environments...

(The first two actually also work for Mac!)

You'll find a lot of them have AMP in their names because they run Apache, MySQL, and PHP.

By this point you should have successfully set up your local web server! Check it out by dropping a random image into the correct Documents folder, and look for its corresponding localhost url.

Rita and p5.js

"Designed to support the creation of new works of computational literature, the RiTA library provides tools for artists and writers working with natural language in programmable media. The library is designed to be simple while still enabling a range of powerful features, from grammar and Markov-based generation to text-mining, to feature-analysis (part-of-speech, phonemes, stresses, etc). All RiTa functions are heuristic and do not require training data, thus making the core library quite compact. RiTa can also be integrated with its own user-customisable lexicon, or with the WordNet database. RiTa is implemented in both Java and JavaScript, is free/libre and open-source, and runs in a number of popular programming environments including Android, Processing, Node, and p5.js." - from RiTA's website

Poem

Duologue

Prose

Its your turn!