Question: Markov chains are a (almost standard) way to generate [random gibberish](http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/) which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.

It would be awesome if the resources you point to are Python friendly.

Answer: 
You could use a "brute force" approach, whereby you compare the generated language to data collected on n-grams of higher order than the Markov model that generated it.

i.e. If the language was generated with a 2nd order Markov model, up to 3-grams are going to have the correct frequencies, but 4-grams probably won't. 

You can get up to 5-gram frequencies from Google's public [n-gram dataset.](http://googleresearch.blogspot.com/2006/08/all-our-n-gram-are-belong-to-you.html) It's huge though - 24G *compressed* - you need to get it by post on DVDs from [LDC](http://www.ldc.upenn.edu). 

EDIT: Added some implementation details

The n-grams have already been counted, so you just need to store the counts (or frequencies) in a way that's quick to search. A properly indexed database, or perhaps a Lucene index should work. 

Given a piece of text, scan across it and look up the frequency of each 5-gram in your database, and see where it ranks compared to other 5-grams that start with the same 4 words.

Practically, a bigger obstacle might be the licensing terms of the dataset. Using it for a commercial app might be prohibited.
One simple approach would be to have a large group of humans read input text for you and see if the text makes sense. I'm only half-joking, this is a tricky problem. 

I believe this to be a hard problem, because Markov-chain generated text is going to have a lot of the same properties of real human text in terms of word frequency and simple relationships between the ordering of words. 

The differences between real text and text generated by a Markov chain are in higher-level rules of grammar and in semantic meaning, which are hard to encode programmatically. The other problem is that Markov chains are good enough at generating text that they sometimes come up with grammatically and semantically correct statements. 

As an example, here's an [aphorism from the kantmachine](http://www.beetleinabox.com/cgi-bin/kant.pl):

> 
> Today, he would feel convinced that
>  the human will is free; to-morrow,
>  considering the indissoluble chain of
>  nature, he would look on freedom as a
>  mere illusion and declare nature to be
>  all-in-all.
> 
> 
> 

While this string was written by a computer program, it's hard to say that a human would never say this. 

I think that unless you can give us more specific details about the computer and human-generated text that expose more obvious differences it will be difficult to solve this using computer programming.