A human-computer interaction for writing poetry based on source texts and Markov processes.

 

I would like to describe a method for writing poetry, a kind of constrained writing that I adapted from an exercise in a computer programming textbook (‘Exercise 13.8’ in Think Python, Downey 2012) and quite enjoy. I call the method ‘Markov, a Game of Poems’​ and a poem produced by the method a ‘​Markov poem’, because games are more fun than methods and because the game involves a Markov process.

A Markov process is a probabilistic process that changes state according to a transition rule that only depends on the current state (see ‘Markov chain’ in the Encyclopedia of Mathematics, Hazewinkel 1990, or the Wikipedia entry on ‘Markov chain’). For example, consider my eating habits:

  • I eat once once a day.
  • If I eat feta cheese today, then tomorrow I will eat cucumbers or tomatoes with equal probability.
  • If I eat tomatoes today, then tomorrow I will eat tomatoes with probability 1/5, feta cheese with probability 2/5 and cucumbers with probability 3/5.
  • If I eat cucumbers today, then tomorrow I will eat grapes with probability 2/5 or feta cheese with probability 3/5.

My eating habits are a Markov process, because they are probabilistic and my choice of food tomorrow depends only on what I eat today, not on what I ate in the past.

Pursuing the example further, we could calculate the expected proportion of days, in the long run, for which I eat tomatoes, which is a typical thing mathematical users of Markov processes do. But this is not a mathematical treatise, so let me end my digression here by saying that Markov processes are named after the Russian mathematician Andrey Markov (1856–1922) who first formalised and studied them as a result of analysing poetry, of all things.

Right, on to the rules of game!

 

Game

1. Choose one to three source texts, each of length at least 500 words.

2. Chop the texts down to have equal word lengths, concatenate them, and perform the following analysis on the resulting text, T. For each distinct contiguous pair of words (prefix) in T, make a list of the words that directly follow that pair (suffixes) in T.

For example if your text is

Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!

then the outcome of the analysis is

(Beware, the): [Jabberwock, Jubjub]
(the, Jabberwock): [my]
(Jabberwock, my): [son]
(my, son): [the]
(son, the): [jaws]
(the, jaws): [that]
(jaws, that): [bite]
(that, bite): [the]
(bite, the): [claws]
(the, claws): [that]
(claws, that): [catch]
(that, catch): [beware]
(catch, beware): [the]
(the, Jubjub): [bird]
(Jubjub, bird): [and]<
(bird, and): [shun]
(and, shun): [the]
(shun, the): [frumious]
(the, frumious): [Bandersnatch]
(frumious, Bandersnatch): []

Here each prefix has at most two suffixes: (Beware, the) has two, (frumious, Bandersnatch) has zero and the rest have one. In a long text, some prefixes would likely have many more than two suffixes.

3. Create in stages a mix, M, of the text, T, as follows.

a. Choose uniformly at random a prefix from your list and then choose uniformly at random one of its suffixes. These three words, prefix then suffix, are the first three words of M.

b. Take the last pair of words of M, find it in your list of prefixes (it must be there by design), then choose uniformly at random one of its suffixes, and add the suffix to M.

If no suffix exists for that pair (which happens if and only if you chose the last prefix in the list), choose a new prefix from the list and one of its suffixes uniformly at random.

c. Repeat step b until M has length 500 words, say.

4. Write a poem such that each word is (i) a word with the same stem as a word in the mix M or (ii) a stop word.

 

Comments

Selecting uniformly at random from a collection of n objects, means selecting any given object with probability 1/n. In other words label the objects with the numbers 1 to n, roll a fair n-sided die, and select the object whose number matches the number on the die.  Alternatively, use a computer to roll an imaginary fair n-sided die, which is close enough.

Regarding clause 4i, the stem of a word is the root form of the word according to a natural language processing algorithm, such as the Porter algorithm (see ‘Development of a Stemming Algorithm’ in Mechanical Translation and Computational Linguistics, Lovins 1968, or the Wikipedia entry on Stemming). For example, ‘argue’, ‘argued’, ‘argues’, ‘arguing’, and ‘argus’ all have the stem ‘argu’. So you can use the word ‘argue’ if any of its variants appear in M.

Regarding clause 4ii, a stop word is a very common word, such as ‘a’, ‘and’, ‘the’ or ‘with’ (for a list of stop words see ‘Data Mining’, in Mining of Massive Datasets, Rajaraman and Ullman 2011, or the Wikipedia entry on Stop words).

If you are using a language other than English, then you need to use stems and stop words appropriate to that language.

Can you spot the Markov process? It is in step 3, where the next word in the mix is chosen probabilistically depending only on the previous two words of the mix. The nice touch here is that the probability of choosing the next word comes from our list of prefix-suffix pairs, which comes from the original text. So the mix will retain much of the word-chaining patterns from the source text, which provides a kind of stylistic stamp. Using multiple and varied source texts often produces an odd mix whose word-chains are tugged in different directions by the competing styles of the source texts.

If you have played poetry games before, the rules above might remind you of the Dadaists’ cut-up technique (see ‘Aleatory poetics’ in the Princeton Encyclopedia of Poetry & Poetics, Greene, Cushman et al 2012, or the Wikipedia entry on Cut-up technique) wherein one cuts a source text into word- or phrase-size chunks and then rearranges the chunks into a finished poem. Indeed, the two methods are similar, but I personally find the strange, continuous, and quasi-grammatical ramblings of a Markov mix more provocative than the disconnected snippets of the cut-up technique.

Clearly steps 2 and 3 are tedious on any source texts longer than a few dozen words. So to make the game easier for us to play, I wrote a computer program that automates those steps and put it on my website at http://raichev.net/markov.net. The program can also perform the stem and stop word check of step 4.

With every Markov poem, I like to include its source references and its mix as glimpses for the reader of the poet's creative path.

 

Example

Let us look at an example Markov poem, one by Auckland poet Lisa Samuels. 

Sources

Lisa chose source texts from the following websites.

  • http://www.merriam-webster.com/dictionary/will, accessed 1 March 2015
  • http://www.collective-evolution.com/2014/11/24/this-is-what-really-happens-to-your-body-when-you-practice-intermittent-fasting/, accessed 1 March 2015
  • http://wiki.geogebra.org/en/Move_Tool, accessed 1 March 2015

 

Mix

She then used the Markov website to produce from those texts the following mix.

to have a wish or desire whether we will all do our best will you please stop that racket 2 —used to express inevitability accidents will happen 7 —used to express desire choice willingness consent or in negative constructions refusal no one would take the job if we will or no intermittent fasting is about timing your meals to allow for regular periods of fasting recommendations for allocating time throughout your day to go without food range from approximately 12 to 16 hours this would mean for example only eating between the hours of 11 am and 7 pm and doing so everyday there are other ways to do it and we will or no intermittent fasting is what you eat before and after you fast move tool is selected you need to drag it with your right mouse button move tool in the three dimensional coordinate system you can quickly activate the move tool in the article this does not mean binge eating and how you break that fast just as important in the article this does not mean binge eating and taking in vast amounts of junk food into your system during the times allocated for yourself to eat doing so would be extremely counter productive and very unhealthy in fact the whole practice of fasting can be lost with how you break that fast just as important in the 3d graphics view using the arrow keys see section manual animation note • you can quickly activate the move tool in the 3d graphics view drag and drop free points in order to move a slider when move tool by pressing the esc key of your keyboard • to move a slider when move tool by pressing the delete key • … delete the object by pressing the delete key • … delete the object by using the move tool in the article this does not mean binge eating and taking in vast amounts of junk food into your system during the times allocated for you to do so as well as what you eat before and after you fast move tool in the graphics view drag and drop free points in order to move a slider when move tool by pressing the delete key • … delete the object by pressing the delete key • … move the point • mode z axis without changing the z coordinate • mode x y plane without changing the z axis you may move the point parallel to the x and y coordinates button and range —used be point go y key the loaf 16 to unhealthy point move will z tomorrow nothing will work one day and loaf the next 3 —used to express desire choice willingness consent or in negative constructions refusal no one would take the job if we will all do our best will you please stop that racket 2 —used to express determination insistence persistence or willfulness i have made up my mind to go

Using the mix as her palette of words and suggestive phrases, she then wrote the following poem.

Transubstantiation
by Lisa Samuels

the junk object
breaks your system
eating you during the times
you can ex-
press desire
nothing vast
when you mode drop
everyday you break
> yourself whole practice
to have a wish or desire
whether we will all do
our best will you please
racket arrow consent
or in negative refusal no
one would take the job if
your right move tool
points free in order to
time your will no inter-
mittent drag allows
a slider by the binge
moves the point
what you eat parallel
to tomorrow without
changing the mind to go
in drop plane mode
you eat the loaf

 

As you can check by hand or using the website, Lisa did indeed write a Markov poem corresponding to the mix, that is, her poem satisfies clauses i and ii of step 4.

 

More Markov Poems

Bouleverser
by Lisa Samuels

to have your evaluated       slp
        who has knowledge of             cas
      to rule out other causes of learning
      to read spell and write école et cours
         missing sounds only a few vowel
          sounds combining             sounds may long
  pauses between sounds 

        all children do this child she has
     talk has coordinating movements
          necessary to say those words
       for the theoretical studies of mesoscale
 the unbalanced forced motion is       the cause
          of some important weather systems
      the vortex mainly      gradient wind

       the asymptotic theory governing
   atmospheric dynamics          et si vous choisissiez
      the semi geostrophic and quasi balanced models
   pour votre prochain séjour linguistique
             in analogy with the semi balanced
    motion the formal scaling d'anglais au cap
                 on nonlinear        balance derived

  they are         un séjour qui satisfera vos besoins
   based on          fluid dynamics and notre organisme
du sud       une immersion totale and quasi geostrophic
              en famille d’accueil by replacing
                       difficult sounds with easier ones
 au cap qui répondra parfaitement    unbalanced
        forced motion is the fundamental     cause

         combine pour votre evolution           semi
 balanced niveau d’anglais que     vous soyez
        a very young child does not coo     or babble
               pour améliorer votre destination
       à des cours of some important weather
               vous souhaitez une immersion totale
             as an infant first words are late

 

Mix

appears to have your child evaluated by a speech language pathologist slp who has knowledge of cas to rule out other causes of speech does so more often may have problems when learning to read spell and write école et cours d'anglais au cap en afrique du sud un séjour qui satisfera vos besoins et si vous choisissiez l’afrique du sud comme destination pour votre prochain séjour linguistique vous souhaitez une immersion totale en famille d’accueil combinée à des cours d’anglais dans une université prestigieuse notre organisme vous propose un séjour qui satisfera vos besoins et si vous choisissiez l’afrique du sud comme destination pour votre prochain séjour linguistique vous souhaitez une immersion totale en famille d’accueil combinée à des cours d’anglais dans une université prestigieuse notre organisme vous propose un séjour qui satisfera vos besoins et si vous choisissiez l’afrique du sud comme destination pour votre prochain séjour linguistique vous souhaitez une immersion totale en famille d’accueil combinée à des cours d’anglais dans une université prestigieuse notre organisme vous propose un séjour linguistique au cap en afrique du sud un séjour qui satisfera vos besoins et si vous choisissiez l’afrique du sud comme destination pour votre prochain séjour linguistique au cap qui répondra parfaitement à vos exigences pour améliorer votre niveau d’anglais que vous soyez débutant ou non the physical characteristics of the mesoscale dynamics the semi balanced and quasi geostrophic models respectively and may be missing sounds only a few different consonant and vowel sounds problems combining sounds may show long pauses between sounds simplifies words by replacing difficult sounds with easier ones or by deleting difficult sounds although all children do this the child knows what he or she can talk has difficulty coordinating the muscle movements necessary to say those words what are some signs or symptoms of childhood apraxia of speech problems general things to look for include the following a very young child does not coo or babble as an infant first words are late and they may be used as basis for the theoretical studies of mesoscale are analyzed and results show that the unbalanced forced motion is the fundamental cause which lead to evolution of some important mesoscale weather systems the mesoscale vortex system is mainly controlled by the gradient wind and the asymptotic theory are used to simplify the governing atmospheric dynamics the semi geostrophic and quasi balanced models based on fluid dynamics and thermodynamics so they can describe the basic characteristics of the mesoscale dynamics equations which are based on fluid dynamics and thermodynamics so they can describe the basic characteristics of mesoscale atmospheric dynamics equations which are based on nonlinear balance equation are derived they are in analogy with the semi balanced and quasi geostrophic models respectively and may be used as basis for the theoretical studies of mesoscale are analyzed and results show that the unbalanced forced motion is the fundamental cause which lead to evolution of some important mesoscale weather systems the mesoscale motion the formal scaling

 

Sources

 

The World
by Alex Raichev

A global dimming
Toward the reddening west
A gradual reduction
To its narowest part

One generation abandons the enterprises of another
Like a burning glass on the alert

What youth or maiden conspires
With the street
The corporation hides
A multitude of sins
And lies in broad daylight
When they called for policies

The animal is dying
And the richest
The faultfinder will find
Flocks do hourly feed

Say nothing of the hardness
Though voices have waxed hoarse and solemnly grave
Mockingly mirth<
And resound with their own sufficience

No wit could divine where in the morning
Our breakfasts were put through
Without accounting
For the passing day

An old woman that lives in the moonlight
Sustaining herself with clenched hands
As if the day is a ridiculous demand
And the sincere life passed

Her pains in this
He says that's good
But he has never made a study
Of the game

And the sights directed over one hand
By the rain which waters the beans
In the shadow of the rainbow

Make no mistake
I have contemplated those cases
Perchance with watery eyes

Sea rise and short impulses
The most attractive and productive industry
Of the last 800,000 years
Unequalled fertility
Of greenish reflections

Place a pailful in my house
It is not so much
Perform something
However umbrageous

The millions are awake enough
To refuse allegiance
And let down their fine lines
Of cant and hypocrisy

Through the illusive to the sacred
Leap the wall
This duty has waited long enough

 

Mix

flocks did hourly feed him by the rain which waters my beans the length of the comforts of life i would fain say something not so much because of higher temperatures without accounting for the passing day this was not so deep but that i was surprised at its narrowest part of creation where i dwell i usually placed a pailful in my house is not so much to get made what i want the world would be the height of five eighths of it in his clothes is it wise to exchange his wigwam will be no mistake and then no wit could divine where in the morning our breakfasts were put through the indirect effect global dimming a gradual reduction in global mean temperature to below 20 °c 36 °f relative to the detriment of my statement notwithstanding much cant and hypocrisychaff which i helped to forward toward the reddening west with us and the realization of the pond and the sincere life passed within it who never knew them it will be earned if we had done and as quick as thought leaped the wall in the shadow of the rainbow over my person or smoothed out the smaller fry they do but what you are richest the faultfinder will find when they called for policies to reduce global warming227 walden economy when i was better than a dietetic point of view the constitution with all its translations has done all that one generation abandons the enterprises of another like a burningglass on the alert and heroic literary labors of men but what youth or maiden conspires with the street and lies there for a moment what most of it it is the process of establishing the most attractive and productive industry many a first spring day what makes this duty of hospitality waited long enough leaving him to me at all in this respect it is very selfish i have heard of bramins sitting exposed to the ground when he comes from looking at how temperatures at different levels in the streets i was ready to conform to the trunk in broad daylight i standing underneath in the animal is dying out in this case my pains however in this he says that's good he has never made a study of the presence and influence is seen a poet has since sung beginning thy entry is a controversial issue8788289 emissions scenarios however the probability of abrupt climate change adaptation to climate change or spontaneous ie without government intervention191 planned adaptation is adaptive capacity which is not the game and the sights were directed over the one hand and the river and put up in my cellar in the pond to bathe in walden pickerel one weighing seven poundsto say nothing of the hardness of their old festal tables though their voices have waxed hoarse and solemnly grave mocking at mirth and resound with their own sufficient for its own culture but alas we do and they saw that a corporation of conscientious men is a charity that hides a multitude of sins the philanthropist too often successful when i came home to his ears out of his thoughts but must keep silence about it i finally went into winter quarters one afternoon and when thou seest the new mythology i don't know it we have many affairs a man that lives in the moonlight amid the woods completed and the smoothness of the hands would have performed something the millions are awake enough for her sustaining herself on humming wings with clinched talons as if the day is a ridiculous demand which england and live it from beginning to melt the snowbanks and the children's teeth are set on fire by english soldiers prisoners on parole and the detriment of the fishes that swim in it are old women over their heads peering above the fleeting spoken language as the pursuits of the land with manure for one of its inhabitants where to hang the clean wild ducks come nature has woven a natural selvage and the ridges of mountains regarded as a possible emissions gap between the polar regions as it warms38 widespread melting of sea level rise and their voices have waxed hoarse and solemnly grave mocking at mirth and the still wilder fields unimproved by man to be strongest in the room by short impulses like a canine bull toward some small squirrel which it has created lofty and umbrageous they call none azad or free speech in this world not chiefly to regulate it is not all that it has lost its flavor and become only liquor to distend their paunches and sweet corn which had sunk it thus in the universe is wider than our views of things the highest side they did in the hamlet i am thankful that this on which forsooth will be the agent of injustice a common and natural society and come to bathe in the laboratory of the torrid sun would perhaps become essentially students and observers for certainly their nature and destiny are interesting to all the way of a daylaborer was the last 800000 years the rest in the river a bright golden kind with greenish reflections and remarkably deep which is so far from being alone erret et extremos alter scrutetur iberos plus habet hic vitae plus habet hic vitae plus habet ille viae let them hunt i have contemplated those cases to which i felt it and flood the parched uplands even this was toward the support of the day thus he goes thither at first a luxury arose the present moment to toe that line you will they not be the holiest son of god that the models predict how greenhouse gases have a genius of unequalled fertility and her right to refuse allegiance to the same track and let down their fine lines through the illusive medium perchance with watery eyes into the cellar of the most sacred laws of his

 

Sources

  • Thoreau, H. D. 1854, Walden, A Life in the Woods, http://books.ebooklibrary.org/members/penn_state_collection/psuecs/walden.pdf, accessed 1 March 2015
  • https://en.wikipedia.org/wiki/Global_warming, accessed 1 March 2015

 

Invitation

Hopefully having piqued your interest, I invite you to play Markov, A Game of Poems at http://raichev.net/markov. Enjoy, and feel free to send me your creations to include on the website. 

 

Works cited: 

 

Downey, A 2012, ‘Exercise 13.8’,  Think Python, Sebostapol: O'Reilly Media, 159

Cut-up technique (n.d.) in Wikipedia at https://en.wikipedia.org/wiki/Cut-up_technique (accessed 1 March 2017)

Greene, R, Cushman, S, Cavanagh, J, and Rouzer, P 2012, ‘Aleatory Poetics’, in Princeton Encyclopedia of Poetry & Poetics, Princeton, NJ: Princeton University Press, 31-34

Hazewinkel, M 1990 ‘Markov chain’, Encyclopeadia of Mathematics, Dordrecht: Kluwer, 95–99

Lovins, J 1968, ‘Development of a Stemming Algorithm’, Mechanical Translation and Computational Linguistics, 11, 22–31

Markov chain (n.d) in Wikipedia at https://en.wikipedia.org/wiki/Markov_chain (accessed 2 March 2017)

Rajaraman, A and Ullman, J 2011, ‘Data Mining’, Mining of Massive Datasets, Cambridge: Cambridge University Press, 8

Stemming (n.d) in Wikipedia at https://en.wikipedia.org/wiki/Stemming (accessed 1 March 2017)

Stop word (n.d.) in Wikipedia at https://en.wikipedia.org/wiki/Stop_word, (accessed 1 March 2017)