Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Saturday, February 18, 2012

Funny Story

So there's four of us at the pub, and we're playing the one word game. And we decide that, since this is the future, we should play a marathon game, via Twitter (complete with hashtag, #OneWordGame).

The One Word Game is where a group of people attempt to collectively tell a story, one word at a time. (Also known as Word at a Time Story).

At this point, we've been playing for about two weeks.


So what's our story? Before that, lets play a game.

Below are two 'stories' - one of them is our word-at-a-time story, the other has been randomly generated (using Markov text generation).

Which is which?

When the wizard was masturbating upon a picture of your face which is ugly he said that a giant octopus with swashbuckling offspring however walrus munched on his wardrobe handles while reciting to Steve the only one who played the harmonica case under his umpalumpa cheese tasted spectacular when dipped in French wine and peanut butter making apples with a slightly tangy bumhole that had smelly teeth and pickled onions with slices of cherry on toast. Suddenly a massive caterpillar spawned from a seed which smells of turnip. When select acorns they exploded penises all turned into a

There was no further sound other than the soft tinkle of water. But in the middle of the surface area were encrusted with hard-caked earth but the girl who was confined them to perpetual darkness. This time there would be a very narrow neck extending about an inch above the rest. Could be worth a try I think he changes his name from time to time. Since it was meant to support an entire career However I

The correct answer is, ours is the first one - probably evident from the vulgar language.

As for the second one; I've discussed Markov generators before. In the simplest case, they work by randomly picking words based on how likely they are to follow the preceding word. This particular example was generated from the first four chapters of Dirk Gently's Holistic Detective Agency (Douglas Adams) using this site.

How does this relate to our game?

Well, the game was spread out over such a period of time that, usually, I'd forgotten the story much beyond the previous few words. So, I was picking my words based on what seemed like a coherent continuation to those few. Not unlike a Markov generator.

And, you have to admit, the two make about as much sense as each other.


At any rate, the game is still on-going..


Oatzy.


[What? I never claim our story was funny..]

Wednesday, April 20, 2011

Markov's Next Tweet

Have cookie. All is a little intrusive So close to be Everyone is we haven't blogged in mall bathroom -!
If you've ever taken the time to read spam - and you really should - you might have come across something like this; text that almost seems human, but on closer inspection just doesn't quite make sense.


Markov Chains

I've mentioned Markov Chains before, for example, in the Snakes and Ladders post. Here's the formal definition from Wikipedia,
A Markov chain, named for Andrey Markov, is a mathematical system that undergoes transitions from one state to another (from a finite or countable number of possible states) in a chain-like manner. It is a random process endowed with the Markov property: the next state depends only on the current state and not on the past.
In the context of snakes and ladders, this basically says that the square you'll land on in the next turn depends on the square you're currently on, and the roll of a dice.


What the Dickens?

So what does this have to do with text generating?

Here's a visual example of how it works. These are the first few lines from A Tale of Two Cities as a flowchart,
In the above, you have the lines broken up word-wise, and linked by which words follow each other. To generate a sentence, pick a starting point and follow the arrows. When you get to a junction pick which way you go at random.

So for text generation, your 'current state' will be some word - say, 'of' in the above. The Markov text generator then picks a word to follow it. In the above, there are 5 words that could follow 'of', each with an equal chance of being chosen; except for 'times' which is twice as likely as the others, since it appears twice in the source.

It should be noted that it isn't just shuffling the words completely at random - words are chosen based on what they appear together with in the source.


Tweets Go In, Gibberish Comes Out

By feeding different source texts in to a generator, you can get all variety of different results; to some extent matching the style of the source writer. This is what can make the output seem so human, while being so beautifully nonsensical.

In fact, the quote at the very top of the post was generated by "That Can Be My Next Tweet".

The only explanation the site gives as to how it works is,
This page generates your future tweets based on the DNA of your existing messages.
But it seems safe to assume, from that and what it outputs, that it's using Markov text generation with your - or in this case my - previous tweets as the source text.


What if I don't really is
He opened the door and got into the car engine shuddered into life and the vehicle lurched down the driveway..
That bit of text is actually an extract from "How to write badly well: Forget what you're doing halfway through a sentence", and is human written. But it demonstrates the point well.

In the above text, you have two sentence fragments either side of 'the car'; each makes sense individually, but not when they're put together.

And unfortunately, these sudden changes of direction are a major trip up point for Markov text; especially since this sort of thing can happen multiple times in a single sentence.


Letters and Words

You don't have to chop up the source text word-wise.

You could, for example, run a Markov chain letter-wise (or even by groups of letters).
This is particularly good at creating bizarre, new, portmanteau-ish words. For example, if your source is the US states, you get such gems as - Floridaho, Oklabama, and Flork.

The drawback to this approach is that it's no good at sentences, since what you'll get is likely to be a nonsensical collection of made-up words.

Alternatively, you could work with pairs of words, or indeed n-grams of any size. This has the benefit of creating more readable-text, but at the cost of variation.

Similarly, a smaller source text can produce lots of sentence fragments that never vary, while a large source can will give greater randomness.

It all ultimately comes down to getting a desirable balance between variability and comprehensibility.


Stuff to Play With

I threw together this quick and dirty implementation in python - mostly just to show that I could. I ran it on the first few paragraphs of this post (pre-editing), and got this as an example output,
almost seems human but while no-one is going on some spam was text that has anyone really should you might have postulated that has anyone really
That Can Be My Next Tweet, mentioned above.

On TweetCloud, you can enter a word and get a word cloud of words that commonly follow that word in tweets. Word.

Word-O-Matic, also mention above, creates words based on any source text you give it. See also: associated Reddit thread with lots of example results.

Markov Text Synthesizer, a general online generator you can play with.

There are various Twitter-bot attempts here.

Markov Shakespearean Sonnet (uses a slightly more complex generation method)

Someone who explains it better than me.

Oh, and you can also use Markov Chains to generate music.


Enjoy.


Oatzy.


[Spam is weirdly hard to come by these days.]

Thursday, November 04, 2010

NaNoWriMo

Or National Novel Writing Month, for those unaware and curious.

Basically, for the duration of November you attempt to write (at least) 50,000 words worth of novel (~1,666 words a day). I considered doing it last year - which would have made more sense, given I was on a whole "I want to be a writer" thing - but I didn't for some reason. What's different this year? Mostly the competition. Nothing motivates me more than competitiveness :D

Hurray for Twitter.

A novel, by their definition is a long work of fiction, and under that definition a collection of short stories can count if they share a common theme. Which is good, because I could not think up a novel worthy plot. Plus I'd probably lose interest and give up part way through.

I had a collection of old ideas (and one that came to me in a dream a couple of weeks ago) but had to come up with some dubious link.

Anyway, I chose mental disorders.

But not in a "this person has this condition, look how weird they are" sort of way. More in the way that Fight Club is 'about' Dissociative Identity Disorder, how Memento is about Anterograde Amnesia or how Truman Show could be about paranoid schizophrenia (think about). It's more a plot device. Or something like that. I'm not savvy to the literary lingo.

I called it "Twisted Smiles & Fractured Minds" partly because it fit, but mostly because it sounds cool.

The stories so far are:

Day 1) His Missing Face - Body Integrity Identity Disorder (based on the dream)
2) My Beautiful Eyes - Narcissism, and the opening to a series
3) Prologue - a flowery vignette (see below for extract)
4) My Imperfect Rock - continuation of narcissism, with mild codependency
5) My Broken Mirror - either Anorexia or Bulimia. Possibly. The third in the narcissism series.

(Titles subject to change)

I'm being vague in the off chance I let you read any of them. I don't want to give any spoilers :]

Much beyond that, I'm going to be scraping the DSM-IV and wikipedia for ideas - which is another bonus to having mental illness as a 'theme': plenty of potential jumping off points. Also, mental illness is just plain fascinating.

I am finding, though, that the ideas seem better in concept than in execution. Not that that's too much a problem, since quantity matters more than quality in NaNo.

You can find my profile here, and watch my word count if you're so inclined. Or, since the site's a bit slow and unresponsive at the moment, you can see the 'novel' summary and an extract in the screenshot below.

NB/ It's not all written in the style of the extract.
Click to embiggen. Cover art uses this stock image. Font based on my handwriting. It could be better, but it'll suffice.

And if you're also doing NaNo, feel free to add me as a buddy.

Whether or not you'll ever get to see what I write for NaNo will very much depend on how I feel about them once it's over and whether or not I can be bothered to edit them to bring them up to an acceptable standard. I'm a poor judge of the quality of my own work and usually end up hating it, so that may never happen.


Oatzy.