Sentiment analysis is a common task in the data science world. A company may want to monitor mentions of its products on Twitter or Facebook in order to detect (and resolve) customer satisfaction issues proactively. But human language is rich and complex; there are myriad ways to feel positive or negative emotion about something—and for each of those feelings there are, in turn, many ways to express that feeling. Among machine learning techniques for sentiment analysis, deep learning has proven to excel at making sense of these complex inputs.
In this tutorial, we'll classify sentiment by building a neural network using Apache MXNet. Ultimately, we'll build up to a classifier that can take the text of a brief movie review as input and try to identify it and express a positive or negative opinion about the movie. We will start with a simple dense model and then build a model similar to the convolutional architecture described in this paper by Yoon Kim. We will also visualize the output using t-sne, a visualization technique for high-dimensional data. Finally, we will use transfer learning to use the pre-built embedding glove in our neural network to classify sentences. Although there are many deep learning frameworks, such as TensorFlow, Keras, Torch, and Caffe, we'll use Apache MXNet, which is gaining popularity due to its flexibility and scalability across multiple GPUs.
I encourage you to download the notebook, where we've created and run all this code, and play with it! Adjust the hyperparameters and experiment with different approaches to neural network architecture or data preparation—and see if you can beat our accuracy.
This notebook expects you to have a basic understanding of convolution operation, neural networks, activation units, gradient descent, and NumPy.
By the end of the notebook, you will be able to:
Understand the complexity of sentiment analysis.
Understand word embedding and its use.
Prepare data sets for training the neural network.
Implement custom neural network architecture for classifying sentiments using various different models.
Visualize the result and understand our model using t-sne.
Use a prebuilt embedding like glove to train on data with constraints (small data set or small sentences).