Have a bunch of embarrassing old chat logs lying around? I did, and converted them into a bot in an attempt to talk to my teenage self.
It took me a while to figure out exactly how I wanted to do it, but the method I used involved open source software that anyone with a modicum of comfort messing around with their computer should be able to follow.
So if you want to talk to a simulacrum of your past, come along in my time machine* and get ready to explore your past. *Time machine actually randomly constructed sentences.
1. Assemble the source material
To start off with, you're going to want to put together a text file that will operate as your bot's source. The source material can be any text broken up such that each sentence is on a new line. For the purposes of my experiment, I only wanted to use words that I typed as a teenager.
My source material involved logs from the chat programs mIRC and AIM, as well as posts I made on Livejournal, but you could potentially also use your old Myspace notes or ICQ logs as well as any embarrassing teen poetry or fiction you once wrote.
Once I had those, it was a simple matter of using a text editor (TextWrangler for me) to remove all the lines that did not have my screenname on them, and then also remove the screenname itself. Separating the file so each sentence was on its own line was also easy: just find and replace each period and space (". ") with a period, space and newline (". \n"). I also ran a find and replace to get rid of any double lines ("\n\n") after that.
The end product should look like this: a .txt file with a different sentence once written by you on each line.
And that's that.
2. Install the necessary software.
This is where things get a little complicated, depending on your level of comfort in tech hackery.
First, get comfortable with working in the command line. For Mac users, that will be an app called "Terminal" and PC users will need something called "Powershell" (which you may have to install yourself).
You're going to need Python 2.7, the programming language of the bot's software. Especially if you're using a Mac, there's a good chance you already have it. You can test this by typing "python" at the command line and hitting enter. If you see something along these lines …
… then you can check it off the list (and type "quit()" before you do). Otherwise, you need to get it installed. If you have a Mac, you'll probably also need Apple's development software Xcode, even though we will not use it at all. It's a free download through the App Store.
Next up is pip, which is a Python package manager that will install the rest of the software we need. Again, typing "pip" will tell you whether you've got it or not, and if you don't, follow the instructions here.
Finally, we'll use pip to install cobe, which is the bot software I used. If you followed the instructions I gave earlier, all you should need to do is type "pip install cobe" and hit enter. If all goes according to plan, that should install everything else we need.
3. Teach your bot to talk
The software is set; now we just have to train it. to do that, make sure you're at the command line in the same folder as the text file you prepared in Step 1 (this guide can help you if you don't know how to do that). Once there, enter the following commands in succession:
cobe init
cobe learn <your text file name here>
cobe console
That should compile a "brain" for the bot based on your provided text and open up a console to communicate with it directly.
All that's left now is to have a conversation.
Like looking in a mirror.
4. Do more.
I'm going to end the step-by-step part now that you have a working bot you can talk to on your computer. I did a bunch of other steps to get my final result, but it gets a lot more complex from here. I wouldn't recommend going further unless you have a competency with Python and Javascript, or at least are good at pretending you do (like me).
At this point of the process, I built cobe functions into a Flask server, which I hosted on Heroku. I then wrote a Javascript function to collect a user's text, send it to the server and print the results in a blog post in a way that looked like an old-school AIM conversation.
If you followed that, the next thing you probably want is the Github repository.
I'm not a programmer by trade. I mostly taught myself using internet guides on long train rides. My code is messy and unoptimized, but it works, and I hope it works for you. If you have any questions about this guide, feel free to ping me in the comments or on Twitter and I'll try my best to answer or point you in the right direction.
And I hope you have a good talk with your bot.