<commit_before>---
layout: post
title: "Intermezzo for lazy bloggers"
---
Recently I sumbled on the Markov Chain.  A Markov chain is collection of random variables {X_t} (where the index t runs through 0, 1, ...) having the property that, given the present, the future is conditionally independent of the past.

[Wikipedia](https://en.wikipedia.org/wiki/Markov_chain) is a little clearer

 ...Markov chain is a stochastic process with markov property ... [Which means] state changes are probabilistic, and future state depend on current state only.
Markov chains have various uses, but now let's see how it can be used to generate gibberish, which might look legit.

The algorithm is

1. Have a text which will serve as the corpus from which we choose the next transitions.
2. Start with two consecutive words from the text. The last two words constitute the present state.
3. Generating next word is the markov transition. To generate the next word, look in the corpus, and find which words are present after the given two words. Choose one of them randomly.
4. Repeat 2, until text of required size is generated.

The above description is borrowed from [Generating pseudo random text with Markov chains using Python](http://agiliq.com/blog/2009/06/generating-pseudo-random-text-with-markov-chains-u/) written by <NAME>. It holds a very nice code sample in python.

###Lazy blogging
That sounds interesting enough when you come to the topic of lazy bloggers. A long text, fed into a markov chain generator produces a new text that reads like legit text, but in fact is gibberish. Brilliant.

A little more googling revealed a number of generators that do exactly that, but then with an API. I will show how easy it is to populate the new-posts form in our bogart blog with this text using the API privided by [Schmipsum](http://www.schmipsum.com/). Here's the code

The schmipsum API can be called with two parameters, the `set` and the `number`, like this:

    http://www.schmipsum.com/ipsum/patents/100
<commit_msg>Added link to series<commit_after>---
layout: post
title: "Intermezzo for lazy bloggers"
---
You know I'm working on [a blog in Bogart.js and CouchDB]({% post_url 2015-06-01-Lets-make-more-blogs %}). Recently I sumbled on the Markov Chain. Lets make use of that in this project.

A Markov chain is collection of random variables {X_t} (where the index t runs through 0, 1, ...) having the property that, given the present, the future is conditionally independent of the past.

[Wikipedia](https://en.wikipedia.org/wiki/Markov_chain) is a little clearer

 ...Markov chain is a stochastic process with markov property ... [Which means] state changes are probabilistic, and future state depend on current state only.
Markov chains have various uses, but now let's see how it can be used to generate gibberish, which might look legit.

The algorithm is

1. Have a text which will serve as the corpus from which we choose the next transitions.
2. Start with two consecutive words from the text. The last two words constitute the present state.
3. Generating next word is the markov transition. To generate the next word, look in the corpus, and find which words are present after the given two words. Choose one of them randomly.
4. Repeat 2, until text of required size is generated.

The above description is borrowed from [Generating pseudo random text with Markov chains using Python](http://agiliq.com/blog/2009/06/generating-pseudo-random-text-with-markov-chains-u/) written by <NAME>. It holds a very nice code sample in python.

###Lazy blogging
That sounds interesting enough when you come to the topic of lazy bloggers. A long text, fed into a markov chain generator produces a new text that reads like legit text, but in fact is gibberish. Brilliant.

A little more googling revealed a number of generators that do exactly that, but then with an API. I will show how easy it is to populate the new-posts form in our bogart blog with this text using the API privided by [Schmipsum](http://www.schmipsum.com/). Here's the code

The schmipsum API can be called with two parameters, the `set` and the `number`, like this:

    http://www.schmipsum.com/ipsum/patents/100

{'fraction_non_alphanumeric': 0.06490097828680506, 'fraction_numerical': 0.00954426151276545, 'mean_word_length': 4.093560145808019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '252226', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1079, 'n_words': 634}