Code Poetry Slam

So, yeah, a freakin ‘HUGO nominee recommeded ME for ArmadilloCon – yeah, good thing I accepted that invitation.

accepted that
thing I accepted dees
good thing I rodeheaver
yeah, good thing err(1)
– yeah, good wang
ArmadilloCon – yeah, king
ArmadilloCon –
for ArmadilloCon
ME for
nominee recommeded ME ville
‘HUGO nominee recommeded leh
‘HUGO nominee
a freakin ‘HUGO emmerson
a freakin
yeah so
dead men 's dust
vulgar salutation
long lewd lither loiterer
moral elevation ensues
float of a fishing-line
conical tops of mountains
barrel of small arms.
barrel of the wheel.
barrier of ice. ice
olive oil. _yellow basilicon_
battening the hatches. securing
battens of the hatches.
beam of the anchor. synonymous
land 's end bore
before or abaft the beam.
bend on the tack.
berthing of the head.
beset in ice. surrounded

Cruelty.
Cruelty bien.
cruelty, and murder. And what
crush cloth and bones as the jaws of the hyæna crush
crushing out
cruel man is ever courageous. The popular theory, that inhumanity is
crucified at the foot of the
men
laden with spoils.
such
chivalry;
cruelty could add. Two of Rome’s
crushing out
cruelty and despotism that
carrots to the English governor, whose men were dying of scurvy, have
the men of Elliot’s garrison were suffering severely from scurvy,
carrots to the English governor, whose men were dying of scurvy, have
mentioned: a point which
men likely to be hostile commanders, would obviously
from the pagan laws of war which every page of the history of Christian
4,734 Christian inscriptions of the same period, only 27 were
crucifixion,
Christian; if he wants to run away with a girl, he becomes a Christian;
foreign
war,
cruelty
cruelty, however, taken in connection with
carrots to the English governor, whose men were dying of scurvy, have
Cruelty.
Cruelty bien.


TRUE PURPOSE, SOCIAL WORLD

A true purpose
A social world
A senior officer 's signature


A fore-and-aft sail, setting with a boom and gaff, in
  ships, synonymous with the spencers of brigs and schooners, and the
  spanker or driver of ships.

The true purpose
The social world
The senior officer 's signature

In size, as a ship's boat, smaller than
  the barge, and, like it, carvel-built.
true purpose
debutante wears
The senior officer 's signature

true one--arising from lateral pressure and the effect of sea when
  close-hauled.
purpose of firing signals,
  as the officer who commands her is particularly ordered to carry no
  cargo, ammunition, or implements of war.

Why are we perverse and ask for something
  else?
ask for something fu dining-room service.
and ask for fudging
perverse and ask reyer
we perverse and hunk
are we perverse duguid?
are we britz
are indri
Why moondreamer?
Why did I invite myself to this dinner
  yesterday?
Why are you so
  cross?
Why?
 
A true purpose
social world
A senior officer 's signature

Interactive Klein Bottle

Luke DuBois introduced us to Paul Bourke, a researcher from Australia who shares an amazing online repository of math equations for geometry, textures, shapes and fractals. I tinkered with some of these equations through a JavaScript file in Max/MSP/Jitter.

I created the shapes using little cubes at each point, one point at a time. You can watch the shape take form:

klein1

klein2

I settled on the Klein Bottle shape. Here’s a patch that forms the shape with a fun visualization and sonifies it, allowing you to tinker with parameters like # of points and size of the cube at each point.

github

zip download

 

The Phrases and Pronunciation

My final poetry-generating Python program is based on noun phrases, a markov chain, a recursive function, and a loose poetic structure. The vocabulary was sourced from three public domain source texts:

The Sailor’s Word Book, An Alphabetical Digest Of Nautical Terms, Including Some More Especially Military And Scientific, But Useful To Seamen; As Well As Archaisms Of Early Voyagers, Etc. By The Late Admiral W. H. Smyth (1867)

Emily Post’s Etiquette: In Society, In Business, In Politics And At Home (1922)

Fyodor Dostoevsky’s Notes From Underground (1864)

These texts make for interesting juxtapositions. For one thing, Post describes good manners for society, while Dostoevsky’s narrator is an outcast from society. The Sailor’s Word Book is a dictionary, but its definitions of sailor’s words are the most poetic of my three source texts—especially when taken out of context. The admiral who wrote this book in 1867 refers to ships as female (i.e. “her head”) and officers as male (i.e. “steersman”) which makes everything sound like an analogy. Likewise, Post and Dostoevsky use plenty of gendered pronouns. They also use proper nouns like “Mrs. Worldly” and “Simonov.” These texts refer to people—whether they are objects (such as a ship), individuals or society as a whole. As a result, when I feed these three texts into my program, they often seem to be talking about the same thing.

 

MARKOV CHAIN

My Markov object creates a dictionary of probabilities for transitioning from one word to the next, but I added some special features. Its “generate” function takes a starting word as an argument. If the starting word exists in the source text (Sailor’s Words + Dostoevsky), it will generate text based on its dictionary of probable transitions from that word to any other word.

  # Generate a text from the information in self.ngrams
  def generate(self, start_word):
    from random import choice

    # If the start_word is in the text, generate a markov chain
    if start_word in self.all_words:
      current = choice([item for item in self.ngrams if item[0] == start_word])
      output = list(current)

      for i in range(self.max):
        if current in self.ngrams:
          possible_next = self.ngrams[current]
          next = choice(possible_next)
          output.append(next)
          current = tuple(output[-self.n:])
        else:
          break

      output_str = self.concatenate(output)
      return output_str
    else:
      return ''

This allowed me to create a generate_question() function that starts a Markov chain with What When Where Why or How. The questions are part of my poetic structure.

def generate_question():
    next_line = underground.generate(random.choice(['What', 'How', 'Why', 'When', 'Where']))
    return next_line

I felt it was important to feed sentences into the Markov chain, rather than lines. So I made an array of Strings and used TextBlob to parse the sentences which I fed into my Markov chain like this:

underground = MarkovGenerator(5, 6)
utext = []
for line in open('../texts/notesfromunderground.txt', 'r'):
    utext.append(line + ' ')
utext_sentences = TextBlob(" ".join(utext).decode('ascii', errors='replace')).sentences
for sentence in utext_sentences:
    underground.feed(sentence)

 

NOUN PHRASES

I used TextBlob to generate a list of noun phrases from Etiquette and Sailor’s Words.

Noun phrases are a very interesting way to parse a text. In fact, I could have stopped there and made a poem out of noun phrases like these:

dead men 's dust
vulgar salutation
long lewd lither loiterer
moral elevation ensues
float of a fishing-line
conical tops of mountains

This is a series of noun phrases from Sailor’s Words:

barrel of small arms.
barrel of the wheel.
barrier of ice. ice
olive oil. _yellow basilicon_
battening the hatches. securing
battens of the hatches.
beam of the anchor. synonymous
land 's end bore
before or abaft the beam.
bend on the tack.
berthing of the head.
beset in ice. surrounded

This is a series of noun phrases from Etiquette:

politeness implies
gentlemanly character
social intercourse
whole detail
person shows respect
time implies
reciprocal respect
gentlemanly character
womanhood combined.

Originally, I created a Noun Phrase List object, but this was time consuming to generate every time, so I just saved them as a text file using the NPLC object I created in my nplc module.

post = NPLC('../texts/sailorswordbook.txt', 4)
npz = open("sailor_nouns.txt", "wb")
for i in post.noun_phrases:
    npz.write(i.encode('utf-8', errors='replace').strip() + '\n')
npz.close()

 

I thought that these noun phrases could give my poems some rhythmic structure, especially if repeated. I sorted them by length:

# generate three noun phrases
nOne = random.choice(postnouns).strip()
nTwo = random.choice(postnouns).strip()
nThree = random.choice(sailornouns).strip()

print "nOne: " + nOne + ', nTwo: ' + nTwo + ', and Three: ' + nThree

# sort the noun phrases by length
if len(nOne) > len(nTwo):
    nX = nOne
    nOne = nTwo
    nTwo = nX

if len(nTwo) > len(nThree):
    nX = nTwo
    nTwo = nThree
    nThree = nX

I also created a function to prepend an appropriate preposition to a noun phrase

# This function tries to figures out what preposition to put before
# a Noun Phrase based on whether it is plural and based on its starting letter.
def preposition(line):
    first_letter = line[0]
    for word in line.split():
        tb = TextBlob(word)
        for w, t in tb.tags:
            if t == 'NN':
                b = Word(word)
                if word == str(b.singularize()):
                    # print word + " is probably singular like " + b.singularize()
                    if not_a_vowel(first_letter):
                        return random.choice(['The ', 'A ', '']) + line
                    else:
                        return random.choice(['The ', 'An ', '']) + line
                elif word == str(b.pluralize()):
                    return random.choice(['The ', 'Some ', 'Many ', 'Of ', 'For all of the ', '']) + line
    ## if it gets to this point, we dont know if it is plural, so just figure out if 'a' or 'an'
    if not_a_vowel(first_letter):
        return random.choice(['A ', 'The ', '']) + line
    else:
        return random.choice(['An ', 'The ', '']) + line

That uses my not_a_vowel function:

def not_a_vowel(letter):
    for char_to_check in ["a", "e", "i", "o", "u"]:
        if letter == char_to_check:
            return False
    return True

Which I originally wrote in order to approximate the number of syllables in a gibberish word. I did not deal with the complexities of “Y.”

RECURSION

The noun phrases, questions and markov chains help give my poems rhythm and space. I pick up the pace with a recursive function called redo_line:

## This function takes a word an changes it to another word that rhymes or has the same # of syllables.
## Sometimes, it also appends a random nounphrase
## rhyming_word is in a separate file, the rhymebot module.
def changeWord(word):
    new_word = ''
    #   nounize(word)
    if word.upper() in all_words:
        new_word = rhyming_word(word, 1)
        if new_word:
            return new_word.lower()
        else:
            new_word = str(random.choice(syl_lookup[syl_bible[word.upper()]]))
            # new_line = new_line + " " + new_word.lower()
    else:
        gibSyl = gib_syls(word)
        new_word = str(random.choice(syl_lookup[gibSyl]))
        # new_line = new_line + " " +
    return new_word.lower() + " " + random.choice(postnouns + sailornouns).strip()


## This function iterates recursively through a line, three words at a time.
## It transforms the last word each time by calling the changeWord function.
def redo_line(line):
    words = line.split()
    if len(words) > 0:
        w = words.pop()
        y = changeWord(w)
        if len(words) > 3:  #crucial variable
            new_line = ' '.join(words)
            try:
                print ' '.join(new_line.split()[-3:]) + " " +y.lower()
            except:
                print ' '.join(new_line.split()[-2:])
            redo_line(new_line)
        if len(words) == 3:
            new_line = ' '.join(words)
            try:
                print ' '.join(new_line.split()[-2:]) + " " +y.lower()
            except:
                print ' '.join(new_line.split()[-1:])
            redo_line(new_line)
        if len(words) == 2:
            new_line = ' '.join(words)
            try:
                print ' '.join(new_line.split()[-1:]) + " " +y.lower()
            except:
                print ' '.join(new_line.split()[-1:])
            redo_line(new_line)
        if len(words) == 1:
            print words[0] + ' ' + y
            print underground.generate(words[0])
            print underground.generate(words[0])
            print words[0] + w
            return

I originally developed this function for my midterm project. Here, I use it towards the end of the poem to iterate through the poem’s three noun phrases and the poem’s opening line.

You can view the full code on my github and the two sample poems from my reading are excerpted below:

PHRASES & PRONUNCIATION

  ABBLAST.
young people
How is enjoyment in this to be
  explained?
 
An elderly guest
phrases and pronunciation
phrases and pronunciation
pronunciation phrases and gillon
and pronunciation phrases remodeled
phrases and pronunciation Townsend's
guest phrases and catamaran
guest phrases liquefied
guest amdahl's
elderly simonette
elderly
 
As far as
  my personal opinion is concerned, to care only for well-being seems to
  me positively ill-bred.
time by his sighed perfect little house
that time by kerins
at that time bly
attention at that duhaime
my attention at cooperate
distracted my attention introduced
Apollon distracted my ritalin
that Apollon distractedly
fact, that Apollon hausfeld
in fact, that 'm chapter xxv
thing, in fact, inhibit
good thing, in aux telegraph pole
a good thing, doron
was a good er luncheon menu=
was a wood
was japonica
It chides
It would be to the interests of humanity and courtesy were it made
  indispensable.
It was first devised for
  the service of mortars, and named after the inventor, Gomer, in the late
  wars.
It
The elderly guest
The phrases and pronunciation
The phrases and pronunciation

 

TRUE PURPOSE, SOCIAL WORLD

A true purpose
A social world
A senior officer 's signature


A fore-and-aft sail, setting with a boom and gaff, in
  ships, synonymous with the spencers of brigs and schooners, and the
  spanker or driver of ships.

The true purpose
The social world
The senior officer 's signature

In size, as a ship's boat, smaller than
  the barge, and, like it, carvel-built.
true purpose
d��butante wears
The senior officer 's signature

true one--arising from lateral pressure and the effect of sea when
  close-hauled.
purpose of firing signals,
  as the officer who commands her is particularly ordered to carry no
  cargo, ammunition, or implements of war.

Why are we perverse and ask for something
  else?
ask for something fu dining-room service.
and ask for fudging
perverse and ask reyer
we perverse and hunk
are we perverse duguid?
are we britz
are indri
Why moondreamer?
Why did I invite myself to this dinner
  yesterday?
Why are you so
  cross?
Why?
 
A true purpose
social world
A senior officer 's signature

Phrases and Pronunciation

ABBLAST.
young people
How is enjoyment in this to be
explained?

An elderly guest
phrases and pronunciation
phrases and pronunciation
pronunciation phrases and gillon
and pronunciation phrases remodeled
phrases and pronunciation Townsend’s
guest phrases and catamaran
guest phrases liquefied
guest amdahl’s
elderly simonette
elderly

As far as
my personal opinion is concerned, to care only for well-being seems to
me positively ill-bred.
time by his sighed perfect little house
that time by kerins
at that time bly
attention at that duhaime
my attention at cooperate
distracted my attention introduced
Apollon distracted my ritalin
that Apollon distractedly
fact, that Apollon hausfeld
in fact, that ‘m chapter xxv
thing, in fact, inhibit
good thing, in aux telegraph pole
a good thing, doron
was a good er luncheon menu=
was a wood
was japonica

It chides
It would be to the interests of humanity and courtesy were it made
indispensable.
It was first devised for
the service of mortars, and named after the inventor, Gomer, in the late
wars.
It

The elderly guest
The phrases and pronunciation
The phrases and pronunciation

True Purpose, Social World, Senior Officer’s Signature

A true purpose
A social world
A senior officer ‘s signature

A fore-and-aft sail, setting with a boom and gaff, in
ships, synonymous with the spencers of brigs and schooners, and the
spanker or driver of ships.

The true purpose
The social world
The senior officer ‘s signature

In size, as a ship’s boat, smaller than
the barge, and, like it, carvel-built.
true purpose
debutante wears
The senior officer ‘s signature

true one–arising from lateral pressure and the effect of sea when
close-hauled.
purpose of firing signals,
as the officer who commands her is particularly ordered to carry no
cargo, ammunition, or implements of war.

Why are we perverse and ask for something
else?
ask for something fu dining-room service.
and ask for fudging
perverse and ask reyer
we perverse and hunk
are we perverse duguid?
are we britz
are indri
Why moondreamer?
Why did I invite myself to this dinner
yesterday?
Why are you so
cross?
Why?

A true purpose
social world
A senior officer ‘s signature

DWD Project Description

I’m building a collaborative discussion forum for Dynamic Web Development. This is also a project for Hacking Higher Ed where I’ve been researching the social conditions that facilitate learning, and what types of discussion forums might lead a community to adopt these social norms.

These are the features I’m considering (though I will probably need to trim ’em down!)

  • all visitors can view and search Q&A’s
  • visitor becomes a ‘user’ by signing in and creating account –> profile w/ image, bio, url’s
  • users can create questions, but first must search to see if there are already similar results
  • users can answer questions
  • users can edit questions to better frame the concept
  • version control: track history of edits to questions & answers (Wiki-style)
  • users can award each other points
  • users can award each other badges for Good Question and Good Answer
  • users can mark questions ‘resolved’ or add follow-up questions

Recursive One Word Generative Poetry

Input any word. My program will turn it into another word that has the same number of phonemes. Then it will find an example of that word in use via the Wordnik API. Then it will recursively run through four bit chunks, starting from the end, modifying the last word in each line using the CMU phoneme dictionary. I got a bit carried away parsing the CMU pronouncing dictionary and this includes some functions that I didn’t wind up using, but would like to use in the future.

Children

So, yeah, a freakin ‘HUGO nominee recommeded ME for ArmadilloCon – yeah, good thing I accepted that invitation.
accepted that
thing I accepted dees
good thing I rodeheaver
yeah, good thing err(1)
– yeah, good wang
ArmadilloCon – yeah, king
ArmadilloCon –
for ArmadilloCon
ME for
nominee recommeded ME ville
‘HUGO nominee recommeded leh
‘HUGO nominee
a freakin ‘HUGO emmerson
a freakin
yeah so

hello

JOSEPH BAST, president of the Heartland Institute, whose unshaven face beards a very similar resemblance to the president of another country on this Earth — no, not the Czech Republic, but go head and guess!
head and
but go head zoch
Republic, but go peart
Czech Republic, but uwe
the Czech Republic, bohr
the Czech
no, not the yeung
— no, not so
Earth — no, pitt
Earth —
this Earth
country on this pay
another country on fors
of another country o.s
president of another smolen
the president of clemo
to the president of(1)
resemblance to the tumbleson
similar resemblance to h
very similar resemblance auth
a very similar creditworthy
beards a very zimpfer
face beards a knapke
unshaven face beards owe
whose unshaven face wesat
Institute, whose unshaven prow
Heartland Institute, whose sicilia
the Heartland Institute, luau
the Heartland
president of the mastodon
BAST, president of thao

At one point, I was including the fill line rather than the last four words:

midterm2.py
172-29-18-92:midterm jasonsigal$ python midterm2.py c458d5c93b0a018f000070bc23407600a2332144b9ac156e1
hello
PEIFER: My wife is the one who always wanted to go to Africa.
PEIFER: My wife is the one who always wanted to go to
PEIFER: My wife is the one who always wanted to go jha
PEIFER: My wife is the one who always wanted to jha
PEIFER: My wife is the one who always wanted our
PEIFER: My wife is the one who always yearlings
PEIFER: My wife is the one who schiltz
PEIFER: My wife is the one o.s’
PEIFER: My wife is the noon
PEIFER: My wife is hour(1)
PEIFER: My wife u.
PEIFER: My fifth(1)
PEIFER: herb

Continue reading

Live Music Map Idea

Venue Map

I’ve missed some really good shows lately, walked right past them in fact, simply because there’s so much going on in NYC.

So I’ve starting to make an app that pulls in all the local venues from Songkick, plots them on a Google Map, and lists the upcoming events. Actually, I’ve decided to parse event data to find out which artists are playing, and I’m planning to use that as the basis for venue inspired radio stations.

Source Code
Demo

Coming soon:

  • Local radio for upcoming events in a metro area and at a specific venue
  • Geolocation + search to set location (NYC only for now)
  • Create ‘venue playlists’ like Downtown Free Jazz or Brooklyn Hardcore by listing favorite venues
  • Browse other people’s venue-based playlists.

This might become a project for Dynamic Web Development, we’ll see! I had fun with Google Maps and music API’s way back at Music Hack Day 2012, happy to get back to it.

Hacking Higher Ed

Jayati, Jerllin, Tarana and I came up with some interesting ideas for our Hacking Higher Ed presentation.

One key point is that education is social, and that’s an aspect that is missing—or at least very different—in online education. The combination of Clay Shirky, my fandom class with Zoe Fraade-Blanar, and my previous experience trying to facilitate conversational spaces has inspired me to bring this approach to education. I’m interested in building a discussion forum tool/toolkit for a community of learners. I want it to be social because I believe that learning is socially motivated. I want to facilitate the type of community where people who have just learned something are motivated to turn around and share it with their fellow learners. This is both to cement what they’ve just learned and to teach in a way that experts often cannot. I think this decentralized community could be integrated into a teacher-student ‘class,’ but could also serve independent learners.

My favorite project ideas so far are…

1. Annotating videos with timestamped discussion threads

2. Browser extension for sharing and discussing online resources with a class, either public or private. Learners would tag resources with comments that are automatically posted to a discussion forum.

–> After presenting this idea in last week’s class, we learned that Mimi Yin has been working on a project kind of like this—a browser extension called http://ponder.co that allows classes to discuss web content.

3. “Am I Doing This Right?” — a Stack Exchange-inspired forum based around video Q&A’s. I’m having second thoughts about this because text has so many advantages over video, and Stack Exchange has already covered so many topics. But a video option for chat and discussion could be very valuable for certain topics.