Transcription

1 Scalable Sentiment Classification for Big Analysis Using Naïve Bayes Classifier Bingwei Liu, Erik Blasch, Yu Chen, Dan Shen and Genshe Chen Intelligent Fusion Technology, Inc. Germantown, Maryland, USA {bingwei.liu, dshen, Air Force Research Laboratory, Rome, New York, USA Binghamton University, Binghamton, New York,USA Abstract A typical method to obtain valuable information is to extract the sentiment or opinion from a message. Machine learning technologies are widely used in sentiment classification because of their ability to learn from the training dataset to predict or support decision making with relatively high accuracy. However, when the dataset is large, some algorithms might not scale up well. In this paper, we aim to evaluate the scalability of Naïve Bayes classifier (NBC) in large datasets. Instead of using a standard library (e.g., Mahout), we implemented NBC to achieve fine-grain control of the analysis procedure. A Big analyzing system is also design for this study. The result is encouraging in that the accuracy of NBC is improved and approaches 82% when the dataset size increases. We have demonstrated that NBC is able to scale up to analyze the sentiment of millions movie reviews with increasing throughput. Keywords Cloud computing, Big data, Polarity mining, sentiment classification I. INTRODUCTION on the web has been explosively increasing in the past few decades. The ability to automatically mine useful information from massive data has been a common concern for organizations who own large datasets. The MapReduce framework [1] is commonly used to analyze extremely large datasets such as tweets collections, online documents or largescale graphs [2] [3] [4]. The framework provides a simple and powerful interface for programmers to solve large-scale problems using a cluster of commodity computers. A typical method to obtain valuable information is to extract the sentiment or opinion from a message. Sentiment classification is useful for the business consumer industry or online recommendation systems. For example, online product reviews are usually analyzed by manufacturers to decide what products they will produce in the future to reduce risk. Machine learning technologies, such as Naïve Bayes and support vector machine, are widely used in sentiment classification [5] [6] [7] [8] [9] [10] because of their ability to learn from the training dataset to make decisions with on-line data, to predict salient features, and to provide real-time analysis with relatively high accuracy. Naïve Bayes (NB) classifiers are widely used in information fusion. Current trends in data fusion include machine analytics for big data [11], use of NB for cloud computing applications of simultaneous target tracking and classification [12], and robotics control [13]. Techniques for big data analysis are needed imaging, text, and cyber analysis which includes scalable and elastic learning methods [14]. When the datasets are large, some information fusion algorithms might not scale up well. For example, if an algorithm needs to load data into memory constantly, the program may run out of memory for large datasets. One promising approach is to utilize and adapt MapReduce for some machine learning technologies to resolve these large-scale problems. Apache Mahout 1 is a machine learning library for clustering, classification and filtering, implemented on top of Hadoop, the open source version of MapReduce. Although there are some machine learning algorithms implemented in Mahout, it is still helpful to study how to convert a machine learning algorithm to a Hadoop program and to optimize the algorithm scalability in large datasets. In this paper, we aim to evaluate the scalability of Naïve Bayes classifier (NBC) in large-scale datasets. Instead of using Mahout library, we implemented NBC to achieve fine-grain control of the analysis procedure for a Hadoop implementation. The result is encouraging in that the accuracy of NBC is improved and approaches 82% when the dataset size increases. We have demonstrated that NBC is able to scale up to analyze the sentiment of millions movie reviews with increasing throughput. The rest of this paper is organized as follows. Section II introduces the background of this study. Section III illustrates the system we design to analyze big dataset which is built on top of Hadoop basic components. The details of implementing Naïve Bayes classifier are addressed in section IV. Section V shows the experiment and results. Finally, we conclude in Section VI. A. MapReduce II. BACKGROUND The MapReduce framework has been used to process large datasets since the original paper [1] was published. Google s clusters process more than 20 Petabytes of data every day by running one hundred thousand MapReduce jobs on average [15]. Using this framework, programmers only need to focus 1

2 on problem solving versus implementation. The MapReduce runtime system will take care of the underlining parallelization, fault tolerance, data distribution and load balance. Google file system (GFS) is a distributed file system that MapReduce uses for the storage of large amount of data across inexpensive hard drives. The availability and reliability of underlining unreliable hardware are provided by replicating file blocks and distributing them across different nodes. A MapReduce job consists of at least a map function and a reduce function, called mapper and reducer respectively. The mapper takes as input a pair of key/value and produces a set of key/value pairs. All key/value pairs are sorted by their keys and sent to different reducers, indexed by the key. Each reducer receives a key and a set of values that has the same key. This makes MapReduce an excellent tool for computations that need sorting or counting. The map and reduce functions are left to the user to implement their desired functionalities to process each key/value pair. Hadoop 2 is an open source implementation of the MapReduce framework that is commonly used by academic and industry for Big analysis. In the core of Hadoop are Hadoop MapReduce and Hadoop Distributed File System (HDFS), the open source counterpart of GFS. There are also a bundle of Hadoop-related projects supported by Apache Foundation, such as HBase (database), Hive (data warehouse), Pig (highlevel data-flow), Zookeeper (high-performance coordination) and Mahout (scalable machine learning and data mining). Therefore, we choose Hadoop as the develop platform to study the scalability of Naïve Bayes classifier. B. Naïve Bayes Classification Naïve Bayes has proven to be a simple and effective machine learning method in previous text classification studies. It is even optimal in some cases [16] [17]. Suppose there are m possible classes C = {c 1, c 2,, c m } for a domain of documents D = {d 1, d 2,, d n }. Let W = {w 1, w 2,, w s } be the set of unique words, each of which appears at least once in one of the documents in D. The probability of a document d being in class c can be computed using Bayes rule: P (c d) = P (c)p (d c). (1) P (d) Since P (d) is a constant for the known data set size, the denominator of (1) is typically not calculated for maximum a posteriori (MAP) common for parametric statistical problems. A Naïve Bayes model assumes that each term or word, w k, in a document occurs independently in the document given the class c. Therefore, equation (1) becomes: P (c d) P (c) n d k=1 [P (w k c)] t k, where n d is the number of unique words in document d and t k is the frequency of each word w k. To avoid floating point underflow, we use the equivalent equation: n d log P (c d) log P (c) + [t k log P (w k c)]. (2) 2 k=1 Raw Parser Hadoop Work Flow Controller Name HDFS User Terminal Result Collector Fig. 1. A simple system to process data using Naïve Bayes classifier on Hadoop. The class of d is decided as the class, c, which maximizes log P (c d) in equation (2). } n d c = argmax c C {log P (c) + [t k log P (w k c)] (3) k=1 When applying Naïve Bayes classifier (NBC), we can estimate P (c) and P (w k c) as: P (c) = N c N and P (w k c) = N wk w i W N w i where N is the total number of documents, N c is the number of documents in class c and N wi is the frequency of a word w i in class c. With these estimations, the calculation of the right hand side of equation (3) is essentially a counting problem. This makes MapReduce a suitable framework for the implementation of NBC in large-scale datasets. III. SYSTEM DESCRIPTION On top of Hadoop MapReduce and HDFS, we designed a Big analyzing system to evaluate whether Naïve Bayes classifier can scale up to classify millions of movie reviews. This section explains the four modules of the system and important steps of the work flow. A. System Components As shown in Fig. 1, the system adds four modules on top of Hadoop: the work flow controller (WFC), the data parser, the user terminal and the result collector. We design this system based on our need to generate different sizes of datasets and test the Hadoop program on them respectively. We also need to perform ten-fold cross validation for accuracy computation that requires calling the same program multiple times. Our raw data comes from large sets of movie reviews collected by research communities. The data parser is responsible to produce the desired data format to assist the program to efficiently process each review. The user submits jobs through the user terminal. Experiment results are also accessible through the user terminal after the result collector finishes collection. The work flow controller manages the work flow of the whole system, which includes:

3 1) Instruct data parser of the format of input data and the desired output; 2) Transmit source code to the name node and execute Hadoop jobs; and 3) Trigger the result collector to collect computing results once they are available on Hadoop Distributed File System (HDFS). B. set In our experiments, we use two datasets: the Cornell University movie review dataset 3 and Stanford SNAP Amazon movie review dataset 4. The Cornell dataset has 1000 positive and 1000 negative reviews, which makes P (c) in equation (3) 0.5 for both class. A review s class is then decided by the frequency of each word that appears in the model obtained from training dataset. The Amazon movie review dataset is organized into eight lines for each review, with additional information such product identification (ID), user ID, profilename, score, summary etc. Since it is a 5 points rating system, we simply divide all reviews into positive and negative subset using 3.0 as a threshold. We consider unigrams only for the Naïve Bayes model. C. Overall Work Flow 1) Pre-processing Raw set: The data parser first preprocesses all reviews into a common format. After the processing, each review is one line in the dataset, with document ID and sentiment (positive or negative) prefixed. This is useful because by default MapReduce splits the input files by line and passes each line to a mapper. To pre-process a raw review from the dataset, we simply delete unwanted context such as punctuation, special symbols and numbers. We did not introduce a lexicon or vocabulary to filter out meaningless words. Table I lists four sample reviews after pre-processing. Each review is one line in the dataset file. We use two prefixed tags: sentiment of either positive or negative and document ID, which is a number. The two tags are both surrounded by colons to help the program differentiate them from review text. Note that there are some isolated single letters resulting from the remove of punctuation. For example, the p.s. in review ID 41 becomes p s after removing the two dots. The preprocessing procedure didn t remove these meaningless letters. All pre-processed reviews are stored in the name node as a repository, waiting for further sampling. 2) Preparing Input sets: The WFC and the data parser work together to prepare input datasets for all test trials. When the WFC requests a dataset with certain size, the data parser extracts from the repository the desired number of positive reviews, as well as the same amount of negative reviews. The result is an input dataset of two equal size classes of movie reviews. After a dataset is generated, the data parser divides it into 10 subsets for the convenience of ten-fold cross validation. The WFC then moves them to the right locations in HDFS for every trial and calls the Hadoop NBC program TABLE I. SAMPLE REVIEWS AFTER PRE-PROCESSING. :POS: :41: i disagree with the reviewers who said the movie was predictable and drawn out it was a movie with heart and you could feel the main characters plight when he lost his companion being an animal lover i was pulling for the happy ending of course i am disney s biggest fan and i love this movie right along with the others p s i am a grandmother to eleven thank heavens for disney movies :POS: :85: sit back and enjoy the interesting and exciting story of the count of monte cristo great rainy day movie :POS: :95: a very well done film and an excellent cast i d put it right up with the three and four musketeers movies york reed chamberlain heston etc :POS: :96: this is an excellent movie and i never read the book the acting and the plot was very nice done it is one of my favorite movies Training Fig. 2. Positive Negative Training Job Model Classify Job Combining Job Intermediate Table Job sequence of Naïve Bayes Classifier on Hadoop. Test 3) Sentiment Classification Using Hadoop: The sentiment classification is the key step in the work flow. Fig. 2 shows the job sequence of this step. Once the training data and test data are ready in HDFS, the WFC starts the training job to build a model. The combining job then combines test data with the model, resulting an intermediate table. Finally, the classify job simultaneously computes the probabilities of each review in the two classes respectively and makes a decision about the sentiment of this review. The statistics of true positive, true negative, false positive and false negative are also recorded. 4) Result Collection: After the classify job finished, the result collector retrieves the model, intermediate table, classification results and statistics of the test from HDFS. D. Automatic Scheduling The WFC coordinates the automation of the whole system. For the Amazon dataset, we conducted 120 test trials in total on twelve sizes of datasets. All test trials are automatically scheduled by the WFC without supervision. The only parameters that need to be decided by human is the sizes of experiment datasets. This automatic scheduling method can be easily applied to other programs with minor change of the parameters. IV. IMPLEMENTATION OF NAÏVE BAYES IN HADOOP A. Defining the Problem We first define our task as to classify the sentiment of a movie review, positive or negative. Hence, we only have two classes of documents. To simplify the problem, we choose the same number of positive and negative reviews, which makes the P (c) in equation (3) a constant. The estimation of P (w k c) is computed by the relative frequency of w k in all documents in c. The classification problem is then converted to a counting problem on the training and test datasets.

4 Algorithm 1 Training Job Input: The training reviews. Output: Model. 1: function MAPPER(key, value) 2: s = parsesentiment(value) 3: for all w d do 4: emit(w, 1 : s) 5: end for 6: end function 7: function REDUCER(key, values) 8: possum = 0; negsum = 0; 9: for all value values do 10: [s, count] = parse(value) 11: if s == positive then 12: possum+ = count; 13: else 14: negsum+ = count; 15: end if 16: end for 17: emit(key, possum, negsum) 18: end function Algorithm 2 Combining Job Input: The test reviews and the model. Output: Intermediate results for classify job input. 1: function MAPPER(key, value) 2: if value model then 3: [word, pos s um, neg s um] = parse(value) 4: emit(word, pos s um, neg s um) 5: else 6: [docid, sentiment] = parse(value) 7: for all word value do 8: emit(word,1,docid,sentiment) 9: end for 10: end if 11: end function 12: function REDUCER(key, values) 13: for all value values do 14: if value model then 15: outstr.append(value) 16: else 17: [count, docid] = parse(value) 18: docs[docid].add(count) 19: end if 20: end for 21: for all docid docs do 22: outstr.append(count,docid) 23: end for 24: emit(word, outstr) 25: end function B. Algorithms After the simplification of the problem, the task can be divided into three sequential jobs as follows. 1) Training job (Algorithm 1). All training reviews are fed into this job to produce a model for all unique words with their their frequency in positive and negative review documents respectively. 2) Combining job (Algorithm 2). In this job, the model and the test reviews are combined to a intermediate table with all necessary information for the final classification. 3) Classify job (Algorithm 3). This job classifies all reviews simultaneously and writes the classification results to HDFS. Algorithm 1-3 are the pseudo-codes for the three jobs. These jobs are executed in sequence because the dependencies between them, as shown in Fig. 2. The training job produces a model that is used to compute the probability of each word in the two classes. The combining job then associates the test data with the model, excluding the words that appear in test data but not in the model. The intermediate table produced by the combining job is then fed to the classify job. By the end of classify job, all reviews are classified into positive or negative classes. The actual Hadoop code we develop is less than five hundred programming lines, including comments and package import statements. With such a simple program, the results are surprisingly good, considering the difficulties of mining sentiment using computer programs. Algorithm 3 Classify Job Input: The intermediate results. Output: Classification results and accuracy. 1: function MAPPER(key, value) 2: for all item value do 3: [docid, count, pos s um, neg s um] = parse(value) 4: emit(docid, count, pos s um, neg s um) 5: end for 6: end function 7: function REDUCER(key, values) 8: [docid, truesentiment]=parse(key) 9: for all value values do 10: calculate pos prob 11: calculate neg prob 12: end for 13: predict = (pos prob > neg prob)? pos : neg 14: if predict = truesentiment then 15: correct = true 16: correct count : else 18: correct = false 19: end if 20: emit(docid, predict, correct) 21: end function A. Cloud Infrastructure V. EXPERIMENTAL STUDY Virtual Hadoop cluster is a fast and easy way to test a Hadoop program in the Cloud, although the performance might be weaker compared to a physical Hadoop cluster. Our cloud infrastructure is built on a Dell server with 12 Intel Xeon E GHz cores and 32G memory. We use Xen Cloud Platform (XCP) 1.6 as the hypervisor. On top of XCP 1.6, we built a virtual Hadoop cluster of seven nodes. There is one special node, the manager, that we use to manage the Hadoop

5 Accuracy REVIEWS/SECOND set size (K) Fig. 3. The accuracy of Naïve Bayes classifier when the dataset size increases % 45.00% 40.00% 35.00% 30.00% 25.00% 20.00% 15.00% 10.00% 5.00% 0.00% ACCURACY BREAKDOWN DATASET SIZE (K) True Positive True Negative False Positive False Negative Fig. 4. The accuracy breakdown of Naïve Bayes classifier when the dataset size increases. cluster. The rest of six nodes form the actual Hadoop cluster, with one name node and six data nodes. We allocate each VM two virtual CPU and 4GB of memory to provide sufficient computing resources for each Hadoop node. B. Experiment Setup First we tested our code on Cornell dataset and resulted in a 80.85% average accuracy. Without changing the Hadoop code, our program was able to classify different subsets of Amazon movie review dataset with comparable accuracy. To test the scalability of Naïve Bayes classifier, the size of dataset in our experiment varies from one thousand to one million reviews in each class. C. Results The result statistics include the classification accuracy, the computation time and the throughput of the system. Fig. 3 shows the average accuracy of our NBC program on various sizes of datasets. Each accuracy number is the average of ten trials. When the dataset is relatively small, the accuracy is unstable because the training data are not big enough for the model to learn enough knowledge about each class. As the dataset size increases above 400K, the Fig TABLE II DATASET SIZE (K) Throughput of the System with respect to dataset size. PROCESSING TIME (SECOND) EVERY 1000 REVIEWS. set size (K) Second/10K reviews set size (K) Second/10K reviews accuracy gradually climbs above 80% and approaching 82%. This demonstrates that the accuracy of NBC is stable when the dataset increases. To further examine the classification results, we plot in Fig. 4 the breakdown of accuracy into true positive and true negative, accompanied by false positive and false negative. As we expected, the true positive and true negative increase with respect to the dataset size, while the false positive and false negative decrease. Table II shows that the processing time for every ten thousand reviews in our Hadoop NBC program decreases when the dataset size increases. A dataset of 2K reviews did not benefit from the parallelization of Hadoop because the input data is smaller that the size of one block in HDFS. Although three replicas are distributed in different nodes, there are at most three nodes in the Hadoop cluster that can access the input data locally. After the input data increasing to a certain size, the advantage of Hadoop starts to appear in that the processing time for the same amount of reviews is drastically reduced compare to the 2K case. To observe the resutls in another dimension, Fig. 5 shows the throughput of the system with respect to the size of dataset. The number of reviews that the system can processes in one second increase from 22 (2K case) to 4304 (2000K case). Overall, our implementation of NBC is able to scale up to two million reviews sampled from the Amazon dataset. The accuracy tends to stable when the dataset size increases. These results are based on the simple processing of review texts. Further filtering of the input data might be able to increase the accuracy. VI. CONCLUSION In this paper, we presented a simple and complete system for sentiment mining on large datasets using a Naïve Bayes classifier with the Hadoop framework. We implemented the NBC on top of Hadoop framework, with additional modules to automate the experiment. We also provide the implementation

Hadoop implementation of MapReduce computational model Ján Vaňo What is MapReduce? A computational model published in a paper by Google in 2004 Based on distributed computation Complements Google s distributed

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY A PATH FOR HORIZING YOUR INNOVATIVE WORK A REVIEW ON HIGH PERFORMANCE DATA STORAGE ARCHITECTURE OF BIGDATA USING HDFS MS.

BIG DATA What it is and how to use? Lauri Ilison, PhD Data Scientist 21.11.2014 Big Data definition? There is no clear definition for BIG DATA BIG DATA is more of a concept than precise term 1 21.11.14

Large scale processing using Hadoop Ján Vaňo What is Hadoop? Software platform that lets one easily write and run applications that process vast amounts of data Includes: MapReduce offline computing engine

Data Mining with Hadoop at TACC Weijia Xu Data Mining & Statistics Data Mining & Statistics Group Main activities Research and Development Developing new data mining and analysis solutions for practical

MapReduce and Implementation Hadoop Parallel Data Processing Kai Shen A programming interface (two stage Map and Reduce) and system support such that: the interface is easy to program, and suitable for

Hadoop http://hadoop.apache.org/ What Is Apache Hadoop? The Apache Hadoop software library is a framework that allows for the distributed processing of large data sets across clusters of computers using

Hadoop Ecosystem B Y R A H I M A. History of Hadoop Hadoop was created by Doug Cutting, the creator of Apache Lucene, the widely used text search library. Hadoop has its origins in Apache Nutch, an open

CS 698: Special Topics in Big Data Chapter 4. Big Data Analytics Platforms Chase Wu New Jersey Ins0tute of Technology Some of the slides have been provided through the courtesy of Dr. Ching-Yung Lin at

Introduction to Hadoop and MapReduce THE CONTRACTOR IS ACTING UNDER A FRAMEWORK CONTRACT CONCLUDED WITH THE COMMISSION Large-scale Computation Traditional solutions for computing large quantities of data

Online Failure Prediction in Cloud Datacenters Yukihiro Watanabe Yasuhide Matsumoto Once failures occur in a cloud datacenter accommodating a large number of virtual resources, they tend to spread rapidly

Chapter 7 Using Hadoop Cluster and MapReduce Modeling and Prototyping of RMS for QoS Oriented Grid Page 152 7. Using Hadoop Cluster and MapReduce for Big Data Problems The size of the databases used in

Open source software framework designed for storage and processing of large scale data on clusters of commodity hardware Created by Doug Cutting and Mike Carafella in 2005. Cutting named the program after

A Brief Introduction to Apache Tez Introduction It is a fact that data is basically the new currency of the modern business world. Companies that effectively maximize the value of their data (extract value

Chapter 11 Map-Reduce, Hadoop, HDFS, Hbase, MongoDB, Apache HIVE, and Related Summary Xiangzhe Li Nowadays, there are more and more data everyday about everything. For instance, here are some of the astonishing

Hadoop and Map-reduce computing 1 Introduction This activity contains a great deal of background information and detailed instructions so that you can refer to it later for further activities and homework.

BIG DATA TRENDS AND TECHNOLOGIES THE WORLD OF DATA IS CHANGING Cloud WHAT IS BIG DATA? Big data are datasets that grow so large that they become awkward to work with using onhand database management tools.

Analytics in the Cloud Peter Sirota, GM Elastic MapReduce Data-Driven Decision Making Data is the new raw material for any business on par with capital, people, and labor. What is Big Data? Terabytes of