Building an AI Chatbot with data from The Office

One of my favourite TV shows is NBC’s The Office. A fan favourite, and on TV for many years, this show never fails to make me laugh, even after I watch the series for the 9th time.

With a bit of free time on my hands, I decided to mess around with some AI Chatbots. Using the ChatterBot python library, some transcript data from the office episodes, and a few APIs, I spent a Sunday afternoon with a little bit of machine learning and a whole lot of fun.

 

The Installation

After installing and setting up the ChatterBot library, I needed to get some data to train it. Using some transcripts of the office episodes I found on the internet, I wrote a short script to clean the data and store each new line as an array in JSON.

I then left it to train for a little while, and when I returned from lunch with friends, I had a fully functioning chat bot. The next thing to do was to connect it to some social media.

With some APIs I found on GitHub, I built a bridge between JavaScript and Python to allow the bot to communicate with my friends. Knowing a few technologically-adept friends would try to mess with it, I took care to implement rate-limiting, and prevent SQL injection (one person tried bobby tables).

Once I confirmed it was working, I let it do it’s magic for an afternoon, checking on it occasionally, and stepping in when things got out of control.

 

The Results

A few people messaged me that afternoon and the bot responded. Here are a few highlights (blue is me / the bot, and names have been altered). I only trained it on the first two seasons, but I’ve got plans to include all soon.

Roy Is My Mom

James
hey man, what’s up?
Me
Hey.
James
what’s up with you?
Me
 I have the chills.
James
why? are you sick?
Me
 I, I was gonna say, I think that um, we’re gonna help Roy’s cousin move.
James
who is roy?
Me
My mom.

 

He Just Wants To Be Alone

Ashley
have you started the project yet?
Me
 It’s right here on the desk, yeah.
Ashley
 so you’re done? what was your topic
Me
 Ah… adapt, react, re-adapt, act.
Ashley
Do you think she’ll give us an extension?
Me
 No.
Ashley
Yeah you’re probably right
Me
 Thanks you guys. I just need some alone time.

 

Interrupting A Group Chat

Elizabeth
Happy Birthday Dan!
George
Happy Birthday!
Me
 I don’t have any brothers. but I have a lot of clones.