Connecting the dots for a Deep Learning App
We show how to build a Deep Learning app which does sentiment analysis on movie reviews. Try it yourself!
Dot 4: CNN-GRU Architecture
Many of you might be wondering, Convolution Neural Networks(CNN’s) works great with images but how does it fare with text. In fact, CNN’s have a lot of advantages in training NLP models due to their faster training time and when accurately tuned, they become a deadly tool to train text data as well.
Here we have used CNN’s to capture the local and deep relationship between the words for our review encoding, where the idea is taken from “Convolutional Neural Networks for Sentence Classification”(Kim, 2014). Since movie reviews can be few long sentences, long term dependencies need to be captured effectively. In this regard, two options come to mind namely LSTM(Long Short Term Memory Neural Networks) and GRU(Gated Recurrent Neural Networks).
Good way to understand both these networks is to head to http://colah.github.io/
In our experiments, GRU performed better than LSTM in terms of training speed and also accuracy.
Final Model which gave best accuracy and performance over this gold dataset:
Dot 5: App
Once the best model is built then the remaining and the last dot is how this can be used as an app for inference/prediction. Inference uses CPU since the each request is processed asynchronously. Training was done on both CPU and GPU. Training per epoch on CPU took 140s on an average whereas on Nvidia 1080 GPU it took ~3x faster time.
Simplest bet is to have something lightweight and when we talk about lightweight the first thing which comes to mind is Flask.
Read More about Flask: http://flask.pocoo.org/
Flask needs the following files or directories:
app.py: Flask app code. This calls the predict function which fetches the prediction from the loaded best model.
Templates: Directory where the HTML files reside.
Start with a simple User Interface(UI) always and based on the user feedback you can add more features.
We decided to go with jQuery UI Bootstrap (https://jquery-ui-bootstrap.github.io/jquery-ui-bootstrap/ ) since we wanted to develop the first iteration of the UI using existing UI components and secondly because it supports the mobile views accurately. Thanks to Arjun Upadhyaya for coming up with this UI approach.
The idea was to present the user with the option to enter the text input and display the results as a progress graph. In this way, the results can be perceived very quickly by the end user.
Finally, we brainstormed and added the pick-list of 5 sample movie review inputs to allow the user to test the model without having to input the text manually.
Finally, What are you waiting for ?. Please go ahead and give it a try, to enter a movie review of your choice and see whats the sentiment of it!!!
Did I miss anything? Is anything wrong? Let me know by leaving a reply below.
Original. Reposted with permission.
Bio: Janardhan Shetty is a Deep-Learning practitioner solving general AI problems.
- Why Swarm Intelligence is a Better Way to Read Emotions
- The Analytics of Emotion and Depression
- Bad Data + Good Models = Bad Results