Project update: Text-based game powered by machine learning.

For my project, I plan to build an interactive, text-based narrative where the text and the plot is generated through machine learning methods. At each stage in the narrative,  the user will be prompted to choose the next step at various stages in the story.

The content of the game will be driven by a machine learning tool that takes image files and generates sequential stories from the images.

Here’s the storyboard / user flow for the game:

storyboard-gaze-01 storyboard-gaze-02 storyboard-gaze-03 storyboard-gaze-04 storyboard-gaze-05 storyboard-gaze-06 storyboard-gaze-07 storyboard-gaze-08 storyboard-gaze-09 storyboard-gaze-10

In terms of the technical details, I need to train my own data set on a specific genre of literature (horror? detective stories? thriller? choose your own adventure books) using the neural storyteller tool. Neural storyteller makes use of several different deep learning frameworks and tools, including skip thoughts, caffe, theanos, numpy, and scikit. Here’s an overflow of how the text in the game will be generated:

preso-001

Here is the tentative schedule for the work:

Week 1: Nov. 2 – 8

  • Get the example encoder/trainer/models up and running (2-3 days).
  • Start training the same program on my own genre of literature (2-3 days).
  • Start building the website where the game will live (2 hrs).

Week 2: Nov. 9 – 15

  • After getting the machine learning framework working, start thinking about ways to structure the generative stories into the narrative arc (2-3 days).
  • Start building the front end of the game – upload buttons, submit forms. (1 day).

Week 3: Nov. 16 – 29

  • Start establishing the rules of game play & build the decision tree (2 days).
  • Continue building the website and tweaking the narrative (2 days).

Week 4: Nov. 30 – Dec. 7

  • User testing. Keep revising the game. Get feedback.

Internal Security Zones: Generative instructions for prison design & maintenance.

facility4692

As of 2016, the U.S. criminal justice system holds more than 2.3 million people in 1,719 state prisons, 102 federal prisons, 942 juvenile correctional facilities, 3,283 local jails, and 79 Indian Country jails as well as in military prisons, immigration detention facilities, civil commitment centers, and prisons in U.S. territories (source). The American prison population has more than quadrupled over the past 25 years, an increase largely driven by heavier penalties for non-violent offenses (source).

Michel Foucault reminds us that power is not static, nor does it emanate from a center of origin. Rather, power exists in an enmeshed network and is wielded by people or groups by way of “episodic” or “sovereign” acts of domination (source). Power is dispersed and pervasive rather than concentrated, embodied, and enacted. Confirming Foucault’s diagnosis of “modern societies of control” (a term used by Gilles Deleuze), Giorgio Agamben argues that biopower operates in physical spaces known as “zones of exception,” physical spaces in which disciplinary power is exercised (source).

In many cases, the architecture of a prison – the panoptical design, the single, impenetrable cells, the isolation and surveillance – causes prisoners to internalize discipline. I’m interested in the material form of prisons. Who designs them? What do the physical spaces look like? What are the material exigencies of daily life?

60

98

For my project, I decided to generate a series of instructions for constructing and maintaining a prison environment. I used the U.S. Department of Justice’s Jail Design Guide as primary source text. I also included a list of business advice and aphorisms as well as Jorge Luis Borges’ “Library of Babel.”

Screen Shot 2016-05-03 at 12.48.11 AM

I created a template that included (1) a title; (2) a chapter subtitle; (3) a set of instructions; (4) a list of material needs; (5) key questions; and (5) a random photo from the handbook. I then used Markov chains to generate some of the text.

The result sounds something like design instructions for a dystopian prison of the future. Here were some generative texts:

Screen Shot 2016-05-06 at 11.05.53 AM Screen Shot 2016-05-06 at 11.03.23 AM Screen Shot 2016-05-06 at 11.07.02 AM

I’ve built a Flask application that allows you to generate a new text and photo when you click the button “Generate another.” Right now it’s still locally hosted but I plan to push it online soon.

See my full GitHub repository here. Below is a snippet of the Python program I wrote:

SmartPharmacist: Redux.

Welcome to SmartPharmacist, Rebecca.

Based on our analysis of your condition, we would suggest you start with a low dosage of Levodivdivphine to treat your bipolar disorder.

Levodivdivphine is a antiparkinsonian drug that is prescribed for bipolar disorder and inflated asshole cancer.

Suggested daily dosage is 5 pills a day taken orally, or rubbing the gel form of the drug on your testy lower thigh.

Once upon a time, individuals suffering from bipolar disorder syndrome were prescribed Concerta and AndroGel, but new advancements in the field of fist Physics has helped doctors better remedy this disorder.

Side effects of Levodivdivphine may include: bloody urine, effective toenail, kidney duplex, penile torsion, prideful asshole, and weight increase.

This week, we learned how to write functions in our Python programs. For my assignment, I revisited last week’s SmartPharmacist .py program I wrote, which gives terrible drug advice based on your symptoms. The outcome of the program is the same, but the code I wrote streamlines a lot of the action that takes place.

I wrote two functions – one that streamlines random.choice() and one that more cleanly creates the drug name.

Here’s the rewrite of the code:

You can find the full repository on GitHub.

SmartPharmacist: A computer program that gives you terrible drug advice.

Welcome to SmartPharmacist, Rebecca. 

Based on our analysis of your condition, we would suggest you start with a low dosage of Alalproex sodiumdivum to treat your bipolar disorder. 

Alalproex sodiumdivum is a antipanic agent drug that is used for bipolar disorder and haughty cheekbone syndrome. 

Suggested daily dosage is 3 pills a day taken orally, or rubbing the gel form of the drug on your irritable fingernail. 

Once, individuals suffering from bipolar disorder failure were prescribed Aripiprazole and Crystal meth, but new advancements in the field of cheekbone Geography has helped doctors better remedy this disorder. 

Side effects of Alalproex sodiumdivum may include: abdominal pain, brooding wrist, grand mal convulsion, grand mal convulsion, brooding lip, and drug intolerance.

For this week’s assignment, we had to write a computer code in Python and execute it in a way that would creatively re-arrange text. We also had to use a network-based source like an API/JSON file in our code.

I’ve been thinking a lot lately about how we collectively seek out information about our health. Traditionally, medicine and disease was something you talked about with your parents or a family doctor. Online medical services like WebMD or even informal forums like Reddit’s Ask a doctor have not replaced physical doctors or pharmacists, but typically the first place an individual turns to get information about his/her health condition is online.

With that in mind, I decided to create a computer program in Python that would automatically generate medical advice based on the user’s health condition.

Screen Shot 2016-04-01 at 3.22.22 AM

I checked out a few different APIs that had extensive documentation, including Infermedica and APIMedic, but those sources proved either too costly or had very limited access to the data (i.e. the site would not allow access via JavaScript so you would have to use a Python client). Finally I settled on the FDA’s OpenFDA API, which provided a really comprehensive repository of every “adverse event” (i.e. side effect) associated with a particular pharmaceutical drug, along with dozens of other endpoints.

The JSON file I generated was very complex. In order to construct the URL, I had to write these lines of code:

 

After getting the data into my program, I decided I wanted the user to be able to search for their medical problem [‘drugindication’] and my program would yield the name of a drug [‘generic_name’]. I wanted the name of the drug to be humorous and fictional, so I took the name of the REAL drug that the user would be prescribed, and cut it in half and mixed in some other syllables so that each drug name is unique.

I found some lists of words online and played Mad Libs with the prescribed “script” for the SmartPharmacist, adding in some body parts and medicine-related adjectives. I liked the fact that this particular API was centered around monitoring the harmful side effects of pharmaceutical drugs because it would add some humor to the medical suggestions made by my SmartPharmacist program. I view my program as basically a terrible doctor. 

Here are some examples:

Welcome to SmartPharmacist, Rebecca.

Based on our analysis of your condition, we would suggest you start with a low dosage of Lidorisentanambphine to treat your Pulmonary Ebolism.

Lidorisentanambphine is a sedative drug that is prescribed for Pulmonary Ebolism and narcissistic tooth disease.

Suggested daily dosage is 2 pills a day taken orally, or rubbing the gel form of the drug on your brassy hairline.

Conventionally, individuals suffering from Pulmonary Ebolism disorder were prescribed Heroin and Gabapentin, but new advancements in the field of tooth Gelotology has helped doctors better remedy this disorder.

Side effects of Lidorisentanambphine may include: impairment of daily activities, astir buttocks, chest pain, plummeting blood pressure, efficacious asshole, and local swelling.
Welcome to SmartPharmacist, Rebecca.

Based on our analysis of your condition, we would suggest you start with a low dosage of Burisentanambphine to treat your Sleep apnea.

Burisentanambphine is a aphrodisiac drug that is used both recreationally and clinically to treat Sleep apnea and contentious upper arm disease.

Suggested daily dosage is 2 pills a day taken orally, or rubbing the gel form of the drug on your bustling ankle.

Once upon a time, individuals suffering from Sleep apnea cancer were prescribed Welbutrin and Lisdexamfetamine, but new advancements in the field of upper arm Neurology has helped doctors better remedy this disorder.

Side effects of Burisentanambphine may include: nausea, cheeky middle finger, penile torsion, weight increase, opinionated arm, and emotional distress.
Welcome to SmartPharmacist, Rebecca. 

Based on our analysis of your condition, we would suggest you start with a low dosage of Desliplatinoxarane to treat your appetite loss. 

Desliplatinoxarane is a ovulation inducer drug that is approved for treatment of appetite loss and congenital hip cancer. 

Suggested daily dosage is 5 pills a day taken orally, or rubbing the gel form of the drug on your introverted knee. 

In the olden days, individuals suffering from appetite loss cancer were prescribed Geodon and Oxycodone, but new advancements in the field of hip Geodesy has helped doctors better remedy this disorder.

Overall, I was pleased with the text the program had generated. It sounded realistic enough so that it didn’t seem like a strict cut-and-paste Mad Libs and I think it successfully mimicked the language we associate with pharmaceutical labels. In the future, I think I could think more creatively about how to cut up the text while using the API in a meaningful way.

Here is the Python program I wrote. You can access the full repository over at GitHub.

Song of Trump: Generating religious erotica with Python.

pic

His power, his passion, is the fabric of America
with the crown with which his mother has crowned him,
He is beholden to no one but we the people, how refreshing
My heart went out when he spoke.
and there, over his head, he’ll be able to see that shining, towering, Trump tower
I called him, but he didn’t answer

And Donald Trump is the right one to do that.
I am my beloved’s. His desire is toward me.
He has spent his life looking up and
its spices may flow out.  Let my beloved come into his garden,
They didn’t want to talk about these issues until he brought ‘em up.
My beloved is mine, and I am his.  He browses among the lilies.

– Odes generated by the Python program I wrote, combining text from Sarah Palin’s Trump endorsement speech with the Bible’s Song of Solomon

Last week, former Alaska governor Sarah Palin delivered a fiery, meandering speech endorsing Donald Trump’s presidential bid. The speech has been described as everything from “post-apocalyptic poetry” to performance art. Her praise for Trump takes the form of a kind of bizarre ode (to capitalism? to the private sector? IDK). To me, Palin’s odd locutions read as both erotica and sermon.

The blending of the sexual and the spiritual in this way is nothing new. The Song of Solomon (or Song of Songs) is a book of scripture that appears in the Old Testament. Scripturally, the book is distinct in its celebration of sexual love. At times erotic, the text takes the form of two lovers talking about their love and desire for one another. Jewish tradition interprets the book as symbolic of the relationship between God and Israel; Christians read it as an allegory for Christ and His church.

All of this got me thinking. For this week’s assignment, we were to write a program in Python that would mimic a function that could be performed on the command line. I decided to write a program in Python that would create a “mashup” of the two texts: Palin’s endorsement speech and Song of Solomon.

The program I wrote searches two texts for lines that contain the words “he” or “his” (lowercase and uppercase). It then randomly selects lines from those lines and generates a simple poem: an ode. In this way, it’s mimicking the grep UNIX command.

The program requires two inputs, both .txt files. The .txt files would ideally take the form of odes, since the words my program is looking for are “he” and “his,” but the program can work with any texts. The output is a 6-line poem that simply alternates between the two texts. If there is a text A and a text B the format would be as follows: A/B/A/B/A/B. For example:

“Trump and his, uh, uh, uh, Trumpeters, they’re not conservative enough.”
in the day of his weddings, in the day of the gladness
He knows the main thing, and he knows how to lead the charge.
then I was in his eyes like one who found peace.
And he tells us Joe six packs, he said, “You know, I’ve worked very, very hard.
I am my beloved’s. His desire is toward me.

Here’s the code I wrote in Python:

Okay, here’s one more:

But, it’s amazing, he is not elitist at all.
He looks in at the windows.  He glances through the lattice.
But he didn’t do it alone, and this is important to remember,
with the crown with which his mother has crowned him,
and there, over his head, he’ll be able to see that shining, towering, Trump tower.
Let him kiss me with the kisses of his mouth