Machine Learning, Perceptrons and Ruby

Machine learning(ML) refers to a collection of programming techniques that allow computers to make distinctions or recognize patterns without explicit commands. This field is based on statistical methods and emerged from artificial intelligence research in the late 1950s and early 1960s. Applications of ML include optical character recognition, sentiment analysis, computer vision and prediction making. People with experience in ML are highly desired in the job market and learning based algorithms are making more and more important decisions in our society. So as an emerging programer its probably worth while to learn a bit about how machines learn.

Use conventional code if you can articulate a concrete series of actions that would produce the desired functionality.
Should I use Machine Learning? (Source: Learning Machines)

 

As an introduction to ML this post will walk through how to build a single layer perceptron in Ruby. The perceptron was one of the first functional ML algorithms. It was developed by Frank Rosenblatt in 1957 and was used to build a machine that could identify certain objects. At the time Rosenblatt stated that the “perceptron [is] “the embryo of an electronic computer that [the Navy] expects will be able to walk, talk, see, write, reproduce itself and be conscious of its existence.”

I am far from an expert in this field but luckily perceptrons are relatively straight forward models to build. I have seen them written in python, Java, and javascript but had a hard time finding a ruby version. Attempting to build this out in ruby seemed like a decent contribution that I could make.

Using a common biological analogy, a perceptron is like a single neuron in a larger brain. It is designed to take in inputs and based on those inputs generate an output for other neurons.

 

Diagram of a neuron
Neurons (Source: Nature of Code)

 

A diagram of a single layer perceptron
Perceptron (Source: Nature of Code)
A diagram that illustrates how a perceptron can be useful
Example use case (Source: Learning Machines)

Read More

Eat Your Feelings DB CLI

Eat Your Feelings DB (EYF) is a simple command line project that Edward N, and I developed for our Module One final project at the Flatiron school in 2018. EYF accesses restaurant reviews via the Google places API and associates each review with an emotional analysis from Parallel Dots. We built an OO model and active record database to select for restaurants and reviewers based on the emotional content of their respective reviews.

This app can be forked on GitHub and cloned to a local machine. To re-seed the database drop the existing tables and re-migrate. Enter Parallel Dots and Google Places API keys in the appropriate spots in the db/seeds.rb file. If you’d like to analyze different restaurants replace the strings in the “Places” array with alternative Google Place IDs. Once you have done this run “bundle install” then “rake db:seed” in terminal and it should populate your database with reviews and emotional analysis. Then you should be able to enter “Ruby bin/run.rb” in terminal and launch our application. Enter “all restaurants” to confirm the data was properly entered.

We would value any contributions in areas of user interface, automatically selecting / adding new restaurants, and performing more analytical operations on the dataset.

Process:
We ran into a few interesting things while working on this project. First we spent a while looking through different APIs and the values that they returned to find what would fit our concept the best. Originally we envisioned using Yelp and IBM Watson but both APIs proved too restrictive and too generalized. Parallel Dots and Google Places on the other hand worked very well with some minor restrictions, mainly Google Places limits each query to 4 reviews which was fine for our purposes but may limit more rigorous analysis.

Another API related challenge we are still working on is how to manage API keys while regularly pushing to GitHub. We ultimately had to reset our API keys after accidentally making them public. Attempts to undo this were frustrating and we still have a lot to learn about protecting credentials like this. [Update: We learned how to use gitignore!]

Lastly, building the interface and having a good framework for what our methods should be returning was a recurring issue. In some cases we wanted the object methods “puts-ing” text to the screen other times we wanted a second helper method to format the output for the user. It was hard to figure out how to make this consistent and what our data types should be. There is probably a lot of room for improvement here too. Ultimately we are happy with our final product and think that EYF represents a great proof of concept for how machine learning and sentiment analysis can be applied.

Building simple Twitter bots with Ruby!

Build your own bot

If you’re interested in building interactive web based software twitter bots are a great place to start. Twitter is a fairly open platform that can be easily access through API’s and libraries which are available for many different programming languages. Combining this access with other API’s, datasets and original content allows for thousands of possibilities and projects that can be completed with only a couple of hours of work.

Some fun example bots:

Think Piece Bot – This bot generates headlines for imaginary opinion articles.

Census American Bot – Tweets anonymized details from real US census forms.

Stealth Mountain – This bot replies to anyone who writes about a “sneak peak” rather than a “sneak peek”, a major problem among media types.

New York Times First Said – Tweets each time the NYTs uses a word for the first time in their history.

Fast Plants & News – This account tweets a picture of some hydroponics plants and associates that with news clips.

Read More