Use Cases

HashRobot: a social media assistant built with MonkeyLearn

Ryan Smith
by Ryan Smith

HashRobot: a social media assistant built with MonkeyLearn

Contributed by Ryan Smith, co-creator of HashRobot.

HashRobot is a social media assistant we built with MonkeyLearn that helps Twitter users pick the right hashtags for their tweets. With HashRobot it’s easy to identify the most popular hashtags within a certain topic. Twitter users can add these hashtags to their tweets to have an edge in getting more views and increase visibility.

You can find the code on GitHub and find the app at www.hashrobot.com

Why we built HashRobot

The project was created by Ryan Smith, Jeff Demers, and Chris Wu during General Assembly’s 12-week Web Development Immersive course. It took us about three weeks to complete. HashRobot is built with Ruby on Rails, a bit of jQuery, MonkeyLearn and hosted on Heroku.

Jeff came up with the initial concept for HashRobot. He had some friends arguing about why one friend’s Instagram posts were getting more likes. It boiled down to the fact that one friend was picking the right hashtags, and as a result, people had an easier time finding those posts. We decided to make an app that could solve that problem for Twitter users and help them pick the right hashtags for their tweets.

We wanted to separate each hashtag into a tag so users could just pick from a dropdown list based on what they were planning on tweeting about, then get some recommended hashtags based on that tag. After some back and forth about what tag we should be using, we stumbled on MonkeyLearn’s generic topic classifier. We decided to take just the top-level tags (16 total), but there are quite a few sub-tags that we could have used too. This solved a few issues for us. First, we didn’t have to pick the tags, and most importantly, we now had a way to take a tweet, figure out what it was about, and then apply that tag to the hashtags within that particular tweet. In MonkeyLearn’s new version, you won’t have to create tag trees since we now use tag lists which are much more user-friendly and provide similar results.

Twitter API

First we started by grabbing some tweets. We used the Twitter gem to get access to the Twitter API and started saving tweets to our database with the following parameters: 1) no re-tweets, 2) only English language, 3) must contain hash tags, and 4) within a 5-mile radius of Hollywood Blvd. and Vine Street in LA. The location of the tweets was somewhat arbitrary, but we were working from downtown LA at the time, so we decided to only grab tweets from that area.  Below is the code used to search for tweets via the Twitter API.  

The rest of the code to connect with Twitter can be found on GitHub.

MonkeyLearn API

Once we had a set of tweets to work with, we passed them as an array to the MonkeyLearn API. Below is the function we used to get a tag for each tweet. Most of the code was taken from the MonkeyLearn documentation.

When the data comes back you get a JSON object containing a tag and a confidence score for each tag. The confidence score is extremely helpful when dealing with tweets. Because tweets are short, and many times use slang, it can be difficult for even a human to tell what tag it should belong to. As a result, we excluded tweets and their hashtags, that had a low probability of having the correct tag assigned to them.  

Once we had the response from MonkeyLearn, we extracted the hashtags from the tweets and associated the tag and its confidence score with the hashtags from the original tweet. We then saved all that information to our database so each row in the table has a tag, a confidence score, and an array of hashtags. If you’d like to see the full process you can check out the code on GitHub.

HashRobot API

Now that we had all the data we needed, we wanted to expose our results as an API, and then consume it on the front end with jQuery.  

Before we exposed the data, we needed to see if a hashtag had been used multiple times in a given tag, and then give those hashtags a higher rank. That final ranking also needed to take into account the probability we received back from MonkeyLearn. The confidence score from MonkeyLearn is returned as a float between 0-1. We multiplied the confidence by the number of times the hashtag appears in a given tag and that gave us our final ranking. At this point, we again removed hashtags with a low ranking. You can check out the code on GitHub.

Once we had our final rankings in place, we exposed that data at an API endpoint for each tag and then displayed that data with jQuery based on what tag the user picked. If for some reason we didn’t have any hashtags to display for a particular tag, we just defaulted to a hashtag with the name of the tag requested. An example of code to display the “Animals” tag is below.

Conclusion

When we started the project we didn’t quite understand that we needed a natural language processor to classify the tweets. At one point we were thinking of picking keywords, then see if they appear in the tweets, then creating our own tags. That would have been a complete mess considering we only had three weeks to complete the project. MonkeyLearn not only classified the tweets for us, it made it super easy to pick the tags. It was a great way to get a huge amount of functionality into our app without writing a ton of code.  

Ryan Smith

Ryan Smith

Ryan Smith is the co-creator of HashRobot, a social media assistant built with MonkeyLearn that helps Twitter users pick the right hashtags for their tweets. With HashRobot it’s easy to identify the most popular hashtags within a certain topic. Twitter users can add these hashtags to their tweets to have an edge in getting more views and increase visibility.

Notification

Have something to say?

Text Analysis with Machine Learning

Turn tweets, emails, documents, webpages and more into actionable data. Automate
business processes and save hours of manual data processing.