Exploring Poetry Generation with Python
“A poem is a small ... machine made out of words.”
Our class sessions will focus on what can be done by creating short,
stand-alone programs. It turns out that there is a great deal we
can do in this vein, and it allows us to concentrate on code and
the workings of programs. We will probably look into at least one
lightweight lexical resource (an inflected word list), but our focus
will be on using the built-in computational capabilities of programming
languages with small, hand-crafted elements of data. We will be sketching
and exploring, so will use Jupyter Notebook and simple text files
instead of requiring that everyone use version control.
Although they are self-contained as programs, the small poetry machines
we will study, modify, and create will allow us access to the history
of creative text generation and to the global creative practices
that involve computation, language, and literary art.
BASIC, but our main way of exploring and programming will be by using
Python, specifically Python 2. In some cases we will be able to easily
will let us share our work on the Web and learn more about how different
programming languages work.
Short, Self-Contained Text Generators for Study, Modification, & Use
- Memory Slam, including implementations by nm of six historic text generators
by Christopher Strachey, 1952; Theo Lutz, 1959; Brion Gysin &
Ian Sommerville, 1960s; Victor H. Yngve, 1961; Alison Knowles
and Python versions are available for all six.
- “Random Mazes,” a sort of concrete
poem in a single line of code. 1981. Commodore PET/VIC 20/Commodore
- Renderings, phase 1, including global work in six langauges and English translations
— 13 literary works, most of them computational. The pieces
are embedded in iFrames. To view their source, right-click within
the frame, select “This Frame > Open Frame in New Window” and
then view the source of the new window. These exact instructions
will work in Firefox; a similar approach should work in other
browsers. Different work is in Amiga BASIC, Commodore 64 BASIC,
- ppg256, nm,
2007-2012, series of seven 256-character generators. This code
is considerably less clear than with other programs on this page,
but if you like a challenge... Perl.
- “The Two,” nm, 2008.
in five other languages, see 2x6, 2016.
- “Taroko Gorge,” nm, 2008, and several dozen remixes/new works based on this one.
(The crossed-out names in the upper right link to these.) Both
- “CharNG,” a character
- “WpN,” an automated,
generalized tool for N+7 modification of texts (à la Oulipo),
- “Lede,” nm, 2012.
one is concise and was written by someone learning to program.
- “Round,” nm, 2013.
- “Ruby Yacht,” nm, 2013. Ruby.
- “Upstart,” nm,
- Tracery, a text-expansion
SM1, October 12: Modifying History, Six Fundamentals
You can start programming by modifying an existing program. We will review
the history of short poetry-generating programs while also modifying
several of these programs. (Recreating the past, to be sure!) We
historical programs. We will very quickly (in the space of about
on changed to the text. We’ll share the results by reading them aloud,
so do not bother to dwell on visual design changes.
To work well as a programmer, even as a wild artistic explorer, foundational
understanding is also important. We will spend time reviewing six
programming fundamentals, so that we can carefully think about how
these realte to poetics. We’ll work to understand how these fundamentals
let us develop very simple poetry generators from scratch —
from a blank cell in the Anaconda Notebook, using Python 2. And we
will see how we might choose to teach others about these fundamentals,
not in a typical “Intro to Programming” framework, but as artists.
- Expressions that yield a value, for instance: 4,
- Variables that can be seen as slots for values or as labeling
- Functions as an important way of bundling code togther
- Iteration as a way of doing a computation for every element
in a sequence
- Types as aids to thinking about and operating on data
- The conditional or “if” statement to allow us to do something
only if a condition holds
Prompt/assignment: Write a Python 2 function of 280 characters
or less — the length of a “new tweet.” Sketch this using Anaconda
Notebook, confirm that it is no longer than 280 characters using
a text editor, and make sure your function is (1) clear enough to
anyone looking at it, (2) doing something interesting to you and
others in some way, (3) dealing with some concept you think is essential
to both programming and poetry. Don't change the default indentation
level. The program will have to be very short! This is about finding
the essence of computing operations we have looked at today and which
we know about from past experience. Email your function to me by Tuesday October 17. You can just copy it and paste it into an email.
SM2, October 19: Starter Programs, Poetry Processing, Book Reports
Today we’ll begin by sharing and discussing the starter programs/starter
We will do some further in-class modification, this time of Python programs
saw previously. These are also found at the Memory Slam site. I’ll encourage you to change parameters and code as well as
the “data” — the strings of language. We’ll share the results,
again by reading them aloud.
I’ll have a selection of computer-generated books for us to look at and
even “read,” for certain values of reading. Pairs of people will
be assigned to examine these books quickly and give expository book
reports about them to the group. A long bibliography of such books
is available at my blog, Post Position.
Prompt/assignment: Create your own tiny computer-generated booklet using
(1) a short, self-contained Python program of no more than 66 lines (80 characters/line);
(2) a single printed sheet, US letter size, which can printed single-sided
or double-sided. You can cut this sheet and staple it, get even more
fancy and use a pamphlet stitch, or use the 8-page zine cut-and-fold technique. Make at least six copies so we can look at them together and so you
can trade some with others at SfPC.
SM3, October 26: Generated Books, Crossing Languages
Today we’ll begin by sharing and discussing the tiny computer-generated
books you made.
We will have time to review some code from those who offer it, and to
see how the six fundamentals (discussed in SM1) were used in the
programs that wrote your tiny books.
We are going to continue to look at some projects that have been done
across (natural) langauges, particularly ones that originated with
an English work or originated outside of English and were translated
or remade in English. We will form groups that (put together) have
very good, poetry-level knowledge of more than one language, and
will try to develop simple Python programs/poems that engage multiple
— formal, used to instruct computers in how they are to operate,
not capable of general communication — we will also discuss
why we might want to work across different programming languages.