sentiment analysis on movie reviews by...

21
SENTIMENT ANALYSIS ON MOVIE REVIEWS BY RECURRENT NEURAL NETWORKS AND LONG SHORT-TERM MEMORY MOHAMAD SHAHNIZAM BIN ABD SAINI UNIVERSITI TEKNOLOGI MALAYSIA

Upload: lymien

Post on 09-May-2019

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

SENTIMENT ANALYSIS ON MOVIE REVIEWS BY RECURRENT NEURAL

NETWORKS AND LONG SHORT-TERM MEMORY

MOHAMAD SHAHNIZAM BIN ABD SAINI

UNIVERSITI TEKNOLOGI MALAYSIA

Page 2: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

SENTIMENT ANALYSIS ON MOVIE REVIEWS BY RECURRENT NEURAL

NETWORKS AND LONG SHORT-TERM MEMORY

MOHAMAD SHAHNIZAM BIN ABD SAINI

A project report submitted in fulfilment of the

requirement for the award of the degree of

Master of Engineering (Computer and Microelectronic Systems)

Faculty of Electrical Engineering

Universiti Teknologi Malaysia

JUNE 2018

Page 3: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

iii

Specially dedicated

to my supervisor and family who encouraged

me throughout my journey of

education.

Page 4: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

iv

ACKNOWLEDGEMENT

Alhamdulillah, the highest thank to Allah S.W.T for blessing me with good

health, physical and mental and time, also giving me patient and spirit through this

starting of my final year project. With willingness from Allah S.W.T, therefore I’m

possible to complete this final year project.

First of all, we would like to express my gratitude and appreciation toward my

supervisor Assoc. Prof. Muhammad Mun’Im Ahmad Zabidi for his assistance and

guidance to complete this thesis. All his support, opinion, and firmness had made this

thesis more quality

I would like to take the opportunity to give a big thank to my family for their

support and encouragement in completing this thesis.

I also want to thank to Faculty of Electrical Engineering, Universiti Teknologi

Malaysia for giving me the opportunity to complete this course as the core subject in

semester 4 and this thesis.

I owe my gratitude to many people who helped and supported me during the

completion of this project.

Page 5: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

v

ABSTRACT

Sentiment analysis has become important tool that can analyse review on any

product or service that can be reviewed. Same goes to movie, all the audient are freely

to make their own reviews on the movie that they watch and the reviews can be positive

or negative based on audient satisfactions. Automated sentiment analysis is very

important to make sure the analysis produce an accurate result and in faster time. By

using the deep learning as the based to create the automated sentiment analysis it will

be the great decision because of the deep learning structure that have multilevel of

layer that can have sensitive process to classify the data. Upgrading the sentiment

analysis using Recurrent Neural Networks (RNNs) and addition of Long Short-term

Memory (LSTM) and also some modification on the number of layer with the

mathematical calculation can improve the analysis accuracy. The dataset of the movie

reviews will be collected on IMDB movie reviews database.

Page 6: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

vi

ABSTRAK

Analisis sentimen telah menjadi alatan penting untuk menganalisis pandangan

pengguna terhadap produk barangan mahupun perkhidmatan. Ini juga boleh terjadi

terhadap filem, penonton bebas untuk memberikan pandangan terhadap filem yang

mereka tonton dan pandangan yang diberi boleh menjurus kepada positif ataupun

negatif bergantung kepada keppuasan penonton. Menganalisis sentimen secara

automatik adalah sangat penting untuk memastikan analisis yang dihasilkan adalah

tepat dan juga mengambil masa yang singkat untuk memperoleh keputusan analisis.

Dengan menggunakan deep learning sebagai asas untuk menghasilkan analisis

sentimen secara automatik, ia adalah keputusan yang tepat kerana struktur deep

learning mempunyai pelbagai lapisan yang mempu memproses untuk mengkasifikasi

data yang sangat sensitif. Menambah baik analisa sentimen dengan menggunakan

RNN dan tambahan dari LSTM dan juga modifikasi kepada bilangan lapisan dengan

munggunakan pengiraan matematik mampu memperbaiki ketepatan analisis. Set data

untuk pandangan filem akan diambil dari pengkalan data IMDB.

Page 7: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

vii

TABLE OF CONTENTS

CHAPTER TITLE PAGE

DECLARATION

ii

DEDICATION iii ACKNOWLEDGEMENT iv ABSTRACT v ABSTRAK vi TABLE OF CONTENTS vii LIST OF TABLES x LIST OF FIGURES xi LIST OF ABBREVIATION xii LIST OF SYMBOLS xiii LIST OF APPENDICES xiv

1

INTRODUCTION

1

1.1 Introduction 1 1.2 Problem Statement 2 1.3 Research Aim and Objective 3 1.4 Scope of Project 3 1.5 Organization of Thesis 3

2

LITERATURE REVIEW

5

2.1 Introduction 5 2.2 Deep Learning 5 2.3 Recurrent Neural Networks 7 2.3.1 Vanishing and exploding gradients 9

Page 8: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

ix

2.4 Long Short-Term Memory 11

2.5 Sentiment analysis 13

2.5.1 Methods 13

2.5.2 Previous works 14

2.5.2.1 Machine learning 14

2.5.2.2 Deep learning 15

2.6 Conclusion 18

3 METHODOLOGY 19

3.1 Introduction 19

3.2 Research Design 21

3.3 Tools Familiarization 21

3.4 Deep Neural Networks Selection 22

3.5 Input Data Selection 23

3.5.1 Internet Movie Reviews Database (IMDB) 23

3.5.2 Global Vector for Word Representation (GloVe) 23

3.6 Deep Neural Networks Workflow 24

3.7 Sentiment analysis process 25

3.8 Conclusion 25

4 RESULTS AND DISCUSSION 26

4.1 Introduction 26

4.2 Results and Discussion 26

4.2.1 Accuracy based on LSTM+RNN layer 26

4.2.2 Accuracy based on datasets use for training and testing 28

4.3 Conclusion 29

5 CONCLUSION AND PLANNING 30

5.1 Conclusion 30

5.2 Planning and Execution 30

REFERENCES 32

Appendices A-C 36-44

Page 9: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

x

LIST OF TABLES

TABLE NO. TITLE PAGE

2.1 Algorithm use for sentiment analysis 13

2.2 Summarize of previous work (1) 17

2.3 Summarize of previous work (2) 18

3.1 Tools and description 21

4.1 Accuracy obtain based on networks layer 27

4.2 Accuracy obtain based on number of training datasets 28

Page 10: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

xi

LIST OF FIGURES

FIGURE NO. TITLE PAGE

1.1 Sample of movie reviews 2

2.1 Neural Networks Architecture 6

2.2 RNNs model single and series 8

2.3 Structure inside the RNNs model 8

2.4 RNNs model 9

2.5 Effects of applying a sigmoid function over and over again 10

2.6 Architecture of LSTM 11

3.1 Project flow 20

3.2 LSTM model implement in RNN 22

3.3 DNNs workflow to classify the review polarity 24

3.3 Sentiment analysis using LSTM+RNN process 25

4.1 Graph of accuracy based on networks layer 27

4.2 Graph of accuracy based on amount of datasets for training purpose 29

Page 11: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

xii

LIST OF ABBREVIATION

CNN - Convolutional Neural Network

LSTM - Long Short-term Memory

NLP - Natural Language Processing

RNN - Recurrent Neural Network

SDRNN - Supervised dual recurrent neural network

IMDB - Internet Movie Database

SVM - Support Vector Machine

GloVe - Global Vector for Word Representation

Page 12: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

xiii

LIST OF SYMBOLS

ℎ𝑡𝑡 - Hidden state vector / output vector of LSTM bock

𝜎𝜎 - Sum of two term

𝑊𝑊𝐻𝐻 - Recurrent weight matrix multiply with hidden state vector

𝑊𝑊 𝑋𝑋 - Weight matrix multiply with input vector

ℎ𝑡𝑡−1 - Hidden state vector at previous time

𝑥𝑥𝑡𝑡 - Input vector / input vector to LSTM block

𝑓𝑓𝑡𝑡 - Forget gate’s activation vector

𝑖𝑖𝑡𝑡 - Input gate’s activation vector

𝑜𝑜𝑡𝑡 - Output gate’s activation vector

𝑐𝑐𝑡𝑡 - Cell state vector

𝑊𝑊&𝑈𝑈𝑓𝑓,𝑖𝑖,𝑜𝑜,𝑐𝑐 - Weight matrices

𝜎𝜎𝑔𝑔 - Sigmoid function

𝜎𝜎𝑐𝑐&𝜎𝜎ℎ - Hyperbolic tangent function

𝑏𝑏𝑓𝑓,𝑖𝑖,𝑜𝑜,𝑐𝑐 - Bias vector

⊙ - Multiplication point by point

Page 13: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

xiv

LIST OF APPENDICES

APPENDIX TITLE PAGE

A Project Timeline (Project 1) 36

B Project Timeline (Project 2) 37

C Project Source Code 38

Page 14: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

CHAPTER 1

INTRODUCTION

1.1 Introduction

Nowadays monitoring customer feedback and reviews is considered an

important tool from a business perspective such as in the film industry. Filmmakers

can create and present their masterpieces to the audience but getting timely reviews is

a major input to planning the next business move. To overcome this issue the

filmmaker need to analyse the movie reviews and identify the audience sentiment from

the good and bad reviews. Sentiment analysis or opinion mining enable the filmmaker

to analyse the reviews from social media websites automatically. Sentiment analysis

also can be applied in many products or services. Therefore, developing automated

tools for sentiment analysis is a big step in business.

Lately, deep learning is a popular research topic in natural language processing.

Deep learning is an improvement from the machine learning. Deep learning is about

learning multiple level of the architecture that help to make sense of data such as text,

image and sound. Currently, deep learning applied to many natural language

processing area such as text, voice and speech and come out with a good result. One

of the deep learning algorithm is Recurrent Neural Networks (RNNs) deep learning.

Although many researcher have applied automated sentiment analysis using

the deep learning, the accuracy can still be improved. Figure 1.1 shows an example of

movie review that randomly pick from the datasets. Based on current trend the

Page 15: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

2

automated sentiment analysis with good accuracy is really important to improve the

movie quality that been produce.

Figure 1.1 : Sample of movie reviews

1.2 Problem Statement

Movie reviews produce a lot of data. Reaching up to millions of reviews for

one movie, analysing all the reviews manually will consume a lot of time. Manual

analysis also can have problem on miss count the number of reviews because it will

have some of human error. This is a challenging issued on sentiment analysis

effectiveness. Although there are some researcher that create automated sentiment

analysis using machine learning and deep learning, the accuracy is still relatively low.

This issues arises because the machine learning algorithms used cannot process the big

sized data that need to be analysed. Deep learning is able to address the big data issue,

but the deep neural network architectures can be improved to increase the accuracy on

the analysis. Some work on deep learning by recurrent neural networks (RNNs) have

been done and the results achieve good accuracy, but RNNs itself have some issue on

the memory side. RNNs alone will create problem called vanishing gradient and

exploding gradient which can reduce the accuracy on learning side. When the learning

of the model has issues, it will affect the inference process, and this will drop the RNNs

accuracy during the sentiment analysis.

Page 16: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

3

1.3 Research Aim and Objective

The aim of this research is to produce accurate sentiment analysis on movie

reviews by recurrent neural networks and long short-term memory. The research

objectives are:

• To investigate the previous sentiment analysis works and use as benchmarking • To design sentiment analysis using RNNs and LSTM model. • To evaluate the accuracy of the sentiment analysis using propose architecture.

1.4 Scope of Project

The scope of the study are as below:

i) Datasets use from the movie reviews that extract from IMDB. ii) Word vector get from glove and prepared by Stanford NLP. iii) Language use to train and test the model is in English. iv) Deep learning system is based on RNNs and LSTM architecture. v) Using python as the only programming language in this project. vi) ANACONDA is use as the simulation software in the analysis process.

1.5 Organization of Thesis

Chapter 1 represent the background of study, problem statement, objectives of

project, scope of project, and project limitation.

Chapter 2 describes the literature review of sentiment analysis, for both

machine learning and deep learning method.

Chapter 3 illustrate the design methodology proposed based on deep neural

networks using RNNs and LSTM. Also cover the project flowchart.

Page 17: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

4

In chapter 4, present the preliminary result, analysis and discussion of the work

done in this research.

Lastly in chapter 5, a conclusion of the research work is given. The discussion

on the recommendation for future work and contribution will also include in this last

chapter.

Page 18: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

32

REFERENCES

[1] L. Deng and D. Yu, “Deep Learning: Methods and Applications,” Found.

Trends® Signal Process., vol. 7, no. 3–4, pp. 197--387, 2013.

[2] H.-F. Yang, K. Lin, and C.-S. Chen, “Supervised Learning of Semantics-

Preserving Hash via Deep Convolutional Neural Networks,” vol. 8828, no. c,

pp. 1–14, 2015.

[3] K. Makantasis, K. Karantzalos, A. Doulamis, and N. Doulamis, “Deep

Supervised Learning for Hyperspectral Data Classification through

Convolutional Neural Networks,” IGARSS 2015. 2015 IEEE Int. Geosci.

Remote Sens. Symp. Proc. \, pp. 4959–4962, 2015.

[4] S. Yang, L. Li, S. Wang, W. Zhang, and Q. Huang, “A Graph Regularized

Deep Neural Network for Unsupervised Image Representation Learning,”

Cvpr, pp. 1203–1211, 2017.

[5] S. Mohammed and I. Tashev, “Unsupervised deep representation learning to

remove motion artifacts in free-mode body sensor networks,” 2017 IEEE 14th

Int. Conf. Wearable Implant. Body Sens. Networks, BSN 2017, pp. 183–188,

2017.

[6] P. Panda and K. Roy, “Unsupervised regenerative learning of hierarchical

features in Spiking Deep Networks for object recognition,” Proc. Int. Jt. Conf.

Neural Networks, vol. 2016–Octob, pp. 299–306, 2016.

[7] J. Zeng, S. Tan, B. Li, and J. Huang, “Large-scale JPEG image steganalysis

using hybrid deep-learning framework,” IEEE Trans. Inf. Forensics Secur.,

vol. 6013, no. c, pp. 1–1, 2017.

[8] L. Lin, S. Zhong, C. Jia, and K. Chen, “Insider Threat Detection Based on

Deep Belief Network Feature Representation,” 2017 Int. Conf. Green

Informatics, pp. 54–59, 2017.

Page 19: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

33

[9] W. Choi et al., “Hybrid network-on-chip architectures for accelerating deep

learning kernels on heterogeneous manycore platforms,” Proc. Int. Conf.

Compil. Archit. Synth. Embed. Syst. - CASES ’16, pp. 1–10, 2016.

[10] B. Kingsbury, T. Sainath, and H. Soltau, “Scalable minimum Bayes risk

training of deep neural network acoustic models using distributed hessian-free

optimization,” Proc. Annu. Conf. Int. Speech Commun. Assoc.

INTERSPEECH, pp. 1–4, 2012.

[11] R. Pascanu, T. Mikolov, and Y. Bengio, “On the difficulty of training

Recurrent Neural Networks,” no. 2, 2012.

[12] L. Deng and J. Chen, “Sequence classification using the high-level features

extracted from deep neural networks,” ICASSP 2014 - 2014 IEEE Int. Conf.

Acoust. Speech Signal Process., pp. 6844–6848, 2014.

[13] Y. Bengio, A. Courville, and P. Vincent, “Representation Learning : A Review

and New Perspectives,” no. 1993, pp. 1–30, 2012.

[14] J. Chen and L. Deng, “A Primal-Dual Method for Training Recurrent Neural

Networks Constrained by the Echo-State Property,” Proc. ICLR, pp. 1–17,

2014.

[15] Y. Bengio, “Deep learning of representations: Looking forward,” Lect. Notes

Comput. Sci. (including Subser. Lect. Notes Artif. Intell. Lect. Notes

Bioinformatics), vol. 7978 LNAI, pp. 1–37, 2013.

[16] I. Sutskever, “Training Recurrent neural Networks,” PhD thesis, p. 101, 2013.

[17] T. Mikolov, M. Karafiat, L. Burget, J. Cernocky, and S. Khudanpur,

“Recurrent Neural Network based Language Model,” Proc. Annu. Conf. Int.

Speech Commun. Assoc. INTERSPEECH, no. September, pp. 1045–1048,

2015.

Page 20: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

34

[18] G. Mesnil, X. He, L. Deng, Y. Bengio, and F. Flight, “Investigation of

Recurrent Neural Network Architectures and Learning Methods for Spoken

Language Understanding,” Proc. Interspeech 2013, vol. 2, pp. 3771–3775,

2013.

[19] K. Yao, G. Zweig, and M. Y. Hwang, “Recurrent neural networks for

language understanding,” Proceeding of Interspeech, no. 1, pp. 2–6, 2013.

[20] W. Medhat, A. Hassan, and H. Korashy, “Sentiment analysis algorithms and

applications: A survey,” Ain Shams Eng. J., vol. 5, no. 4, pp. 1093–1113,

2014.

[21] A. khan, B. Baharudin, and K. khan, “Sentence based sentiment classification

from online customer reviews,” Proc. 8th Int. Conf. Front. Inf. Technol. - FIT

’10, pp. 1–6, 2010.

[22] A. K. Behera, “Performance Analysis of Supervised Machine Learning

Techniques for Sentiment Analysis,” pp. 128–133, 2017.

[23] A. Hassan and A. Mahmood, “Deep Learning approach for sentiment analysis

of short texts,” 2017 3rd Int. Conf. Control. Autom. Robot., pp. 705–710,

2017.

[24] Q. Vo, H. Nguyen, B. Le, and M. Nguyen, “Multi-channel LSTM-CNN model

for Vietnamese sentiment analysis,” 2017.

[25] W. Rong, B. Peng, Y. Ouyang, C. Li, and Z. Xiong, “Semi-supervised dual

recurrent neural network for sentiment analysis,” Proc. - 2013 IEEE 11th Int.

Conf. Dependable, Auton. Secur. Comput. DASC 2013, pp. 438–445, 2013.

[26] K. Devarajegowda, J. Schreiner, R. Findenig, and W. Ecker, “Python based

Framework for HDSLs with an underlying Formal Semantics,” pp. 1005–

1011, 2017.

Page 21: SENTIMENT ANALYSIS ON MOVIE REVIEWS BY …eprints.utm.my/id/eprint/79373/1/MohamadShahnizamMFKE2018.pdf · Menambah baik analisa sentimen dengan menggunakan RNN dan tambahan dari

35

[27] R. Phelps, M. Krasnicki, R. A. Rutenbar, L. R. Carley, and J. R. Hellums,

“{ANACONDA}: robust synthesis of analog circuits via stochastic pattern

search,” {IEEE} Cust. Integr. Circuits, pp. 567–570, 1999.

[28] M. Abadi et al., “TensorFlow: Large-Scale Machine Learning on

Heterogeneous Distributed Systems,” 2016.

[29] K. Wongsuphasawat et al., “Visualizing Dataflow Graphs of Deep Learning

Models in TensorFlow,” IEEE Trans. Vis. Comput. Graph., vol. 24, no. 1, pp.

1–12, 2017.

[30] Pennington, J., Socher, R., & Manning, C. D. (2014). GloVe: Global Vectors

for Word Representation. In Empirical Methods in Natural Language

Processing (EMNLP) (pp. 1532–1543).