Marvov Chain's based Chatbot
After AIML, Markov Chains are a very popular method to create applications capable of imitating (but not understanding) human language. Markov chains make use of word frequency and tree like structures to parse and generate sentences.
Here we'll describe how to create a basic Markov chains based chatbot. To make it more interesting, we're going to make our bot connect to Discord which is an instant messaging platform that has become very popular thanks to the large amount of features its able to provide.
Here we'll describe how to create a basic Markov chains based chatbot. To make it more interesting, we're going to make our bot connect to Discord which is an instant messaging platform that has become very popular thanks to the large amount of features its able to provide.
Setting up our Discord Server
In order to get our bot working, we need to have a testing field. If you can't get a friend to lend you his server to practice, there's always the option of creating your own. First of all we login to discord, in this case I did it through my browser.
Creating our Bot
|
|
Generating text using Markov Chains
Here I'll present two methods to generate text on our robot using Markov chains. The first one is the classical step by step procedure to create the functions in Python. The second one is based around using a library called markovbot which facilitates the generation of text. The first method can be useful to you to understand the process used by Markov chains to create text and the second can help you make a fast implementation if you ever need it to.
Using the library markovbot.py
|
I modified the text generation section of the library to work in Python3.5. All credit to Edwin Dalmaijer for creating such an amazing module.
|
To generate text using the library markovbot.py, first you need to download it either from the author's webpage if you are using Python2.7 or from here if you are using Python3.4 or 3.5. Place it on the directory of your application and import it using the line:
$ from markovbot import markovbot
$ from markovbot import markovbot
[1] http://eflorenzano.com/blog/2008/11/17/writing-markov-chain-irc-bot-twisted-and-python/
[2] https://code.google.com/archive/p/pennpyrcbot/
[3] http://charlesleifer.com/blog/building-markov-chain-irc-bot-python-and-redis/
[4] https://jaydenkieran.com/discord-py-guide/
[5] http://www.pygaze.org/2016/03/how-to-code-twitter-bot/
[2] https://code.google.com/archive/p/pennpyrcbot/
[3] http://charlesleifer.com/blog/building-markov-chain-irc-bot-python-and-redis/
[4] https://jaydenkieran.com/discord-py-guide/
[5] http://www.pygaze.org/2016/03/how-to-code-twitter-bot/