# Using Markov chains (or something similar) to produce an IRC-bot

1 view

I tried google and found little that I could understand.

I understand Markov chains to a very basic level: It's a mathematical model that only depends on previous input to change states..so sort of an FSM with weighted random chances instead of different criteria?

I've heard that you can use them to generate semi-intelligent nonsense, given sentences of existing words to use as a dictionary of kinds.

I can't think of search terms to find this, so can anyone link me or explain how I could produce something that gives a semi-intelligent answer? (if you asked it about pie, it would not start going on about the Vietnam war it had heard about)

I plan on:

• Having this bot idle in IRC channels for a bit

• Strip any usernames out of the string and store as sentences or whatever

• Over time, use this as the basis for the above.

by (95.5k points)

Yes, you can use Markov chains for generating semi-intelligent machines. To generate a random text from a simple, first-order Markov chain you can perform the following steps:

• The first step is to Collect the bigram (adjacent word pair) statistics from a corpus (collection of text).

• the second is to make a Markov chain with one state per word. Reserve a special state for end-of-text.

• The probability of jumping from state/word (x to y) is the probability of the words (y) immediately following x, roughly calculated from relative bigram frequencies in the training corpus.

• Start with a random word x (perhaps determined by how often that word occurs as the first word of a sentence in the corpus). Then pick a state/word y to jump to randomly, taking into account the probability of y following x (the state transition probability). Repeat until you hit end-of-text.

Markov bots generally work on the simple idea of Markov chains. Normally they require a substantially large corpus (flat text file with known good phrases/sentences). One could call this the "brain" of dagbot. Without a large corpus, Markov bots will usually generate gibberish phrases that look nothing like what a human would say.

Here is the link you can refer for the code: https://github.com/anirbanmu/dagbot