Sentiment Analysis

Teaching machines about feelings!

Sentiment Analysis
  • NodeJs
  • BrainJs
  • TypeScript
  • Yarn

The aim of this project was to experience first hand all the hype with AI. Because AI can be very abstract and difficult to grasp, I wanted something somewhat easy to understand and easy to apply, so I chose sentiments analysis. How can I make a program that understands a message and it's able to classify it into these 3 categories: good, neutral, bad.

I had to start somewhere, so I simplified the problem instead of texts of various sizes I would do tweets that are much more compact and follow a set of rules. After reading, I understood that they key of a good AI relies on a good set of data, so I started creating my own dataset with tweets after some minutes I figured that there should already some publicly available databases with tweets already classified. And yes, after some searching, I got 1.500.000 tweets classified. With these tweets I could start training my model and then testing it, here are some examples:

  • I love my dog.
  • Terrible service.
  • It's ok, I guess.
  • Tomorrow is Monday.
  • I love to pay taxes.

The results were pretty awesome, for the most part it worked as expected, but there were some behaviours to iron out, for example, I exclusively rely on the neural network to do all the work, I could really use another algorithm to work alongside to find a solution using other methods such as dictionaries or other neural networks.

As for sentences, ironic or sarcastic are pretty much out of the scope of this project as it adds another whole level of complexity, but I would lie if I don't smirk when "I love to pay taxes" is marked as positive sentence.

End note:

Sentiment analysis is not new, and it is still being used to gather data on product reviews or opinions on a topic, there is a huge interest in getting this kind of information. On the web there are tons of information on how to approach this problem, I would recommend don't get hasty and play with it, it's fun once you get the hang of it!