Markov Chains Tutorial - Part I

In todays blog I would like to explain the Markov Chain I demonstrated in one of my previous blogs. So lets first ask the question, what is a Markov Chain? Well, lets answer this through an example.

"Hello world, I am a coder and I like to code in Python and JavaScript and I also like coding games."

In the above sentence, we see a bunch of words. Some words appear more often than others. So why not make probability table for the frequency of the words appearing!

Frequency Table for the words appearing
Words Frequency
I 3
and 3
like 2
Hello 1
world 1
am 1
a 1
coder 1
to 1
code 1
in 1
Python 1
JavaScript 1
also 1
coding 1
games. 1

From the table we see that "I" and "and" are the most frequent words in our dataset i.e. the sentence. Now the question arises that, can you form sentences based on these probabilities. The answer is, kind of. A sentence is basically formed from phrases, phrases are formed form words. We have our words, we need our phrases. We also need to keep in mind that our result has to give us some sense. So the phrases cannot be formed based on these probabilities.

In our sentence "I" comes three times, and the word that followed "I" were "am", "like" and "also". Well those can be phrases! Let me explain, our phrases can be "I am", "I like" and "I also". We can start our sentence by randomly choosing one of these phrases. Lets assume we choose "I like", now our next bit of our sentence can be a random word that follows, "like" in our sentence. The words we need to choose from are "to" and "coding" and lets assume we get "to". Thus our final result, which our Markov Chain will give, will be "I like to". Because we are predicting one word at a time, the order for this Markov Chain is one. 

With a bigger dataset and by repeating this over and over again, we will be able to get results, as shown in the previous blog. Now we can come to coding our Markov Chain, but I will teach that in my next blog, because all of that in one blog would have been a lot to digest!

Comments

Most Popular Posts