top of page

04.24.2018: One Lesson of Python

Today's soundtrack is Cloudscape: Global Drama.

I'm not actually going to be doing a lesson today, per se...I'll be trying to synthesize two Python programs . The idea that I have is to combine a Markov Chain with a chatbot. I want to try to get the chatbot to ask the user a question, add the answer to a database that the program will draw from later, and then have the user ask the chatbot a question that the chatbot will answer by using the Markov Chain. I found a couple of tutorials that I'll be using as a starting point for this program: a Markov Chain tutorial, and a chatbot tutorial.

-- 20 minutes later, I realize I've opened a can of worms. I've gone down a rabbit hole of different ways of making chat bots (during which I came across an interesting-looking course being offered by one of the founders of Rasa), tried to find a way to make Python diagram a sentence (which led me to pylinkgrammar and the Natural Language Toolkit) and found that there is a field of computer science and AI called Natural-Language Processing that deals with similar ideas many order of magnitudes more complex than what I'm trying to do. So basically, I've stumbled upon a field of study that people literally get degrees in. So rather than get over my head tonight, I'm going to try the Markov Chain program and delve further into the rest of this next time.

I started by downloading a .txt file with a bunch of Trump's 2016 speeches from Github into my Python folder, then created a new Python program called "Markov Chat." I then copied and pasted the code from the tutorial linked above, only to find that I don't have Numpy installed. I tried to get it installed, but I was running into issues, so I found another Markov Chain tutorial that doesn't use Numpy; however, I kept getting errors that I didn't know how to fix when I tried it, so I'm going to try again to install Numpy. I found that to install anything on Windows 7 with Python 3.6.x, I first needed to get pip and then save the code as a .py file and then run it to install pip. Unfortunately, it still didn't work; it kept returning syntax errors when I typed "pip install numpy". I found another workaround: WinPython, a version of Python with scientific modules (including Numpy) built in. It worked! I opened Python and was able to import Numpy. Then I pasted in the Markov Chain code again, only to get an error message that utf-8 files can't be decoded. Okay. So I removed the part of the coding that reads the .txt as a utf-8, then ran the program again. Nothing happened. I put the utf-8 code back in, then realized that the .txt was saved as ansi, not utf-8. I fixed that, then tried again. No luck.

Time for bed.


bottom of page