With the rapid development of the Internet, more and more users expressed their views on the Internet. Therefore, the big data of texts are generated on the Internet. Social media is generating a vast amount of sentiment rich data in the form of tweets, status updates, blog posts etc. In the era of big data and deep learning, mining the sentiment tendencies contained in massive texts on the Internet through natural language processing technology has become an important way of public opinion supervision. This analysis has a vast and great applications such as stock price prediction, election result prediction, and so on. In this paper, I have applied a simple and efficient Neural Language Model approach for text classification (Sentiment Analysis) that relies only on unsupervised word representation inputs along with word embedding technique, which has improved the model to capture syntactic and semantic word relationships. This paper shows that applying the RNN, LSTM, GRU, Bidirectional RNN models achieves excellent result on the customer review dataset.
I have applied four models for sentiment analysis and trained and tested them over the customer review dataset.
- RNN model that employs embedding layer followed by a simple RNN layer followed by a fully connected layer with dropouts and then by an activation layer. Drive Link
- LSTM model that employs embedding layer followed by an LSTM layer followed by a fully connected layer with dropouts and then by an activation layer. Drive Link
- GRU model that employs embedding layer followed by a GRU layer followed by a fully connected layer with dropouts and then by an activation layer. Drive Link
- Bidirectional RNN model that employs embedding layer followed by a bidirectional LSTM layer followed by a fully connected layer with dropouts and then by an activation layer. Drive Link
- The RNN model achieved an accuracy of 77.85% with a loss score of 0.506 on the testing data.
- The LSTM model achieved an accuracy of 88.94% with a loss score of 0.323 on the testing data.
- The GRU model achieved an accuracy of 84.94% with a loss score of 0.342 on the testing data.
- The bidirectional RNN model achieved an accuracy of 90.57% with a loss score of 0.317 on the testing data.
RNN Structure | LSTM Structure | GRU Structure |
Bi LSTM | Accuracy plot of RNN | Accuracy plot of LSTM |
Accuracy plot of GRU | Accuracy plot of Bi LSTM | Confusion matrix of RNN |
Confusion matrix of LSTM | Confusion matrix of GRU | Confusion matrix of Bi LSTM |
- Tensorflow : Used as the Deep Learning Library.
- Keras : For Models.
- Kaggle : For Datasets.
- SK Learn : For Data Preprocessing & Results.
- Applying in real time applications like Election Result Prediction and Stock Price Estimation.
- Fake News Prediction
You are welcome to contribute :
- Fork it (https://github.com/roysaurabh1308/Sentiment-Analysis-using-RNN-LSTM-GRU-Bi.LSTM/fork)
- Create new branch :
git checkout -b new_feature
- Commit your changes :
git commit -am 'Added new_feature'
- Push to the branch :
git push origin new_feature
- Submit a pull request !
Thanks for going through this Repository! Have a nice day.
Have any querry? Feel free to contact me.
Saurabh Roy
This Project is licensed under the MIT License, see the LICENSE file for details.