Machines With a Sense of Humor?

Tony Tonev
DataDrivenInvestor

--

Photo by Dan Cook on Unsplash

Machines can do some amazing things these days, but can they know what’s funny? I entered my very first data science competition to try to answer that question, and got 2nd place out of 67 in just a few days!

I’ve had a passion for AI and machine learning since college, and I’ve recently started taking online classes to build my skills. I’ve finished the classes Machine Learning and Neural Networks and Deep Learning from Stanford professor Andrew Ng on Coursera. The classes are really fantastic, and I highly recommend them to anyone, but I felt like the homework projects hold your hand a little too much. They do everything for you except for one blank and tell you exactly what to put in that blank. I understand why they do it that way — to make it easy to follow for everyone, but I wanted to work on a more autonomous project.

So, before starting the next class in the series, I wanted to take two days to complete a data science competition. I decided to start with the Joke Rating Prediction Challenge from analyticsvidhya.com. You are given a training data set which has users’ ratings of jokes, and your task is to predict how much a user would like a joke they haven’t seen before. These sort of recommender systems are a really common use of machine learning by big companies like Netflix, YouTube, Amazon, Spotify, etc. It seemed like the perfect place to start because I can apply one of the techniques I learned called collaborative filtering.

Photo by Franck V. on Unsplash

Collaborative filtering is an algorithm where we learn a fixed number of features, each of which represents some quality of the underlying data. For jokes, one feature might correspond to knock-knock jokes, another might be puns, and another might be offensive jokes. These features are automatically learned from user preferences. People with similar tastes will tend to like the same set of jokes. Based on that, we can learn that those jokes must have some feature in common. At the same time, we’re also learning about each user’s preferences. Maybe this person loves puns but hates offensive jokes. We’ll adjust the user’s parameter weights accordingly. So, we’re learning weights for both jokes and users at the same time for each feature. We learn if a joke has a feature (knock-knock joke?) and which users like which feature (hates knock-knock jokes) simultaneously. It sounds complicated, but it’s relatively straightforward to implement.

Photo by Ian Stauffer on Unsplash

Using the code from the one of the homework in the Machine Learning class as an example, I re-wrote it in Python using pandas and numpy. When I had run through a quick and dirty model and spit out the predictions, I wanted to do a test submission to see if I was outputting the predictions in the right format. Much to my surprise, my name shows up at number 3 out of 67 on the leaderboard on my first attempt!! Not bad for just two day’s work. When I tweaked the hyperparameters a bit, I was able to get to 2nd place! My score is within 0.01 of the top solution, so it’s basically a tie 😂. I cleaned up the code and put it on github for you to enjoy if you’re interested.

This gave me a lot of confidence and makes me excited to keep doing more projects and getting better.

--

--