Skip to main content

Posts

Showing posts from April, 2017

Markov chain in JavaScript

I made a small Markov Chain joke generator during my coffee break sometime last week. This is in continuation to the last post, where we did a similar thing. I did this specifically to see how well it could be extended in a language which I have typically not used before for ML/NLP. Let me run you guys through it. First of all, the Markhov Chains need a bunch of data to tell it how exactly you want your sentences constructed. str_arr=[sentence1, sentence2,...] Next, we create a dictionary of all trigrams present across the sentences. To do this, we use all bigrams as keys, and the succeeding word as the corresponding values. The key-value pairs thus form a trigram. As an example, consider the sentence : “The man had a dog.” The dictionary for this sentence will have : [ {[The, man] : [had]}, {[man, had] : [a]}, {[had, a] : [dog]} ] Next up, using the dictionary that we just made to create sentences. Here we provide the first two words, and let the function work

Yo mama so geeky : generating jokes using Markov Chains

A few days back, I saw this article “ How to fake a sophisticated knowledge of Wine with Markov Chains ” on the programming subreddit. To my utter delight, the article referenced the code, along with a very detailed explanation, so I spent an hour getting it all to work. The hour taken was no fault of the original authors, it was taken because I wanted to get a good hang of XPath, which will be the topic of a later post. The program auto-generates wine reviews, by using Markov Chains to come up with a sequence of most probable trigrams. It was great fun spouting my expert-level sommelier reviews, especially considering that I can count on one hand the number of times I have actually tasted wine! The reviews were just the right amount of ambiguous with a hint of snobbishness (which, according to me, just made the whole thing perfectly more believable). While I was showing off my new-found expertise in wines, my partner in crime,  Rupsa , told me it could probably be used for other