Question? Leave a message!




Retrieval Support Vector Machine (SVM)

Retrieval Support Vector Machine (SVM)
Introduction to Information Retrieval Introduction to Information Retrieval Support vector machines and machine learning on documents www.ThesisScientist.comIntroduction to Information Retrieval Text classification: Up until now and today  Previously: 3 algorithms for text classification  Naive Bayes classifier  K Nearest Neighbor classification  Simple, expensive at test time, high variance, nonlinear  Vector space classification using centroids and hyperplanes that split them  Simple, linear discriminant classifier; perhaps too simple  (or maybe not)  Today  SVMs  Some empirical evaluation and comparison  Textspecific issues in classification www.ThesisScientist.comIntroduction to Information Retrieval Ch. 15 Linear classifiers: Which Hyperplane  Lots of possible solutions for a, b, c.  Some methods find a separating hyperplane, This line but not the optimal one according to some represents the criterion of expected goodness decision  E.g., perceptron boundary:  Support Vector Machine (SVM) finds an ax + by− c = 0 optimal solution.  Maximizes the distance between the hyperplane and the “difficult points” close to decision boundary  One intuition: if there are no points near the decision surface, then there are no very uncertain classification decisions www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Another intuition  If you have to place a fat separator between classes, you have less choices, and so the capacity of the model has been decreased www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Support Vector Machine (SVM) Support vectors  SVMs maximize the margin around the separating hyperplane.  A.k.a. large margin classifiers  The decision function is fully specified by a subset of training samples, the support vectors.  Solving SVMs is a quadratic Maximizes programming problem Narrower margin  Seen by many as the most margin successful current text classification method but other discriminative methods www.ThesisScientist.com often perform very similarlyIntroduction to Information Retrieval Sec. 15.1 Maximum Margin: Formalization  w: decision hyperplane normal vector  x : data point i i  y : class of data point i (+1 or 1) NB: Not 1/0 i T  Classifier is: f(x ) = sign(w x + b) i i T  Functional margin of x is: y (w x + b) i i i  But note that we can increase this margin simply by scaling w, b….  Functional margin of dataset is twice the minimum functional margin for any point  The factor of 2 comes from measuring the whole width of the margin www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Geometric Margin T w x +b r = y  Distance from example to the separator is w  Examples closest to the hyperplane are support vectors.  Marginρ of the separator is the width of separation between support vectors of classes. ρ x Derivation of finding r: Dotted line x’−x is perpendicular to r decision boundary so parallel to w. x′ Unit vector is w/w, so line is rw/w. x’ = x– yrw/w. T x’ satisfies w x’+b = 0. T So w (x–yrw/w) + b = 0 T Recall that w = sqrt(w w). T So w x–yrw + b = 0 w So, solving for r gives: www.ThesisScientist.com T r = y(w x + b)/wIntroduction to Information Retrieval Sec. 15.1 Linear SVM Mathematically The linearly separable case  Assume that all data is at least distance 1 from the hyperplane, then the following two constraints follow for a training set (x ,y ) i i T w x + b ≥ 1 if y = 1 i i T w x + b ≤ −1 if y = −1 i i  For support vectors, the inequality becomes an equality  Then, since each example’s distance from the hyperplane is T w x +b r = y w  The margin is: 2 r = w www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Linear Support Vector Machine (SVM) T w x + b = 1 a ρ T w x + b = 1 b  Hyperplane T w x + b = 0  Extra scale constraint: T min w x + b = 1 i=1,…,n i  This implies: T w (x –x ) = 2 a b ρ = x –x = 2/w a b 2 2 T w x + b = 0 www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Linear SVMs Mathematically (cont.)  Then we can formulate the quadratic optimization problem: Find w and b such that 2 r = is maximized; and for all (x , y ) i i w T T w x + b ≥ 1 if y =1; w x + b ≤ 1 if y = 1 i i i i  A better formulation (min w = max 1/ w ): Find w and b such that T Φ(w) =½ w w is minimized; T and for all (x ,y ): y (w x + b) ≥ 1 i i i i www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Solving the Optimization Problem Find w and b such that T Φ(w) =½ w w is minimized; T and for all (x ,y ): y (w x + b) ≥ 1 i i i i  This is now optimizing a quadratic function subject to linear constraints  Quadratic optimization problems are a wellknown class of mathematical programming problem, and many (intricate) algorithms exist for solving them (with many special ones built for SVMs)  The solution involves constructing a dual problem where a Lagrange multiplierα is associated with every constraint in the primary problem: i Find α…α such that 1 N T Q(α) =Σα ½ΣΣαα y y x x is maximized and i i j i j i j (1) Σα y = 0 i i (2) α ≥ 0 for all α i i www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 The Optimization Problem Solution  The solution has the form: T w =Σα y x b= y w x for any x such that α 0 i i i k k k k  Each nonzero α indicates that corresponding x is a support vector. i i  Then the classifying function will have the form: T f(x) = Σα y x x + b i i i  Notice that it relies on an inner product between the test point x and the support vectors x i  We will return to this later.  Also keep in mind that solving the optimization problem involved T computing the inner products x x between all pairs of training points. i j www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.1 Soft Margin Classification  If the training data is not linearly separable, slack variablesξ can be added to i allow misclassification of difficult or noisy examples.  Allow some errors ξ i  Let some points be moved ξ to where they belong, at a j cost  Still, try to minimize training set errors, and to place hyperplane “far” from each class (large margin) www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.1 Soft Margin Classification Mathematically  The old formulation: Find w and b such that T Φ(w) =½ w w is minimized and for all (x ,y ) i i T y (w x + b) ≥ 1 i i  The new formulation incorporating slack variables: Find w and b such that T Φ(w) =½ w w + CΣξ is minimized and for all (x ,y ) i i i T y (w x + b) ≥ 1ξ and ξ ≥ 0 for all i i i i i  Parameter C can be viewed as a way to control overfitting  A regularization term www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.1 Soft Margin Classification – Solution  The dual problem for soft margin classification: Find α…α such that 1 N T Q(α) =Σα ½ΣΣαα y y x x is maximized and i i j i j i j (1) Σα y = 0 i i (2) 0 ≤α ≤ C for all α i i  Neither slack variables ξ nor their Lagrange multipliers appear in the dual i problem  Again, x with nonzero α will be support vectors. i i  Solution to the dual problem is: w is not needed explicitly w = Σα y x for classification i i i T b = y (1ξ ) w x where k = argmax α k k k k’ T k’ f(x) = Σα y x x + b i i i www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.1 Classification with SVMs  Given a new point x, we can score its projection onto the hyperplane normal: T T  I.e., compute score: w x + b = Σα y x x + b i i i  Decide class based on whether or 0  Can set confidence threshold t. Score t: yes Score t: no 1 0 Else: don’t know 1 www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.1 Linear SVMs: Summary  The classifier is a separating hyperplane.  The most “important” training points are the support vectors; they define the hyperplane.  Quadratic optimization algorithms can identify which training points x are i support vectors with nonzero Lagrangian multipliers α . i  Both in the dual formulation of the problem and in the solution, training points appear only inside inner products: T Find α…α such that 1 N f(x) = Σα y x x + b i i i T Q(α) =Σα ½ΣΣαα y y x x is maximized and i i j i j i j (1) Σα y = 0 i i (2) 0 ≤α ≤ C for all α i i www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.3 Nonlinear SVMs  Datasets that are linearly separable (with some noise) work out great: x 0  But what are we going to do if the dataset is just too hard x 0  How about … mapping data to a higherdimensional space: 2 x x 0 www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.3 Nonlinear SVMs: Feature spaces  General idea: the original feature space can always be mapped to some higherdimensional feature space where the training set is separable: Φ: x → φ(x) www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.3 The “Kernel Trick” T  The linear classifier relies on an inner product between vectors K(x ,x )=x x i j i j  If every datapoint is mapped into highdimensional space via some transformation Φ: x→ φ(x), the inner product becomes: T K(x ,x )= φ(x ) φ(x ) i j i j  A kernel function is some function that corresponds to an inner product in some expanded feature space.  Example: T 2 2dimensional vectors x=x x ; let K(x ,x )=(1 + x x ) 1 2 i j i j , T Need to show that K(x ,x )= φ(x ) φ(x ): i j i j T 2 2 2 2 2 K(x ,x )=(1 + x x ) = 1+ x x + 2 x x x x + x x + 2x x + 2x x = i j i j , i1 j1 i1 j1 i2 j2 i2 j2 i1 j1 i2 j2 2 2 T 2 2 = 1 x√2 x x x√2x√2x 1 x√2 x x x√2x√2x i1 i1 i2 i2 i1 i2 j1 j1 j2 j2 j1 j2 T 2 2 = φ(x ) φ(x ) where φ(x) = 1 x√2 x x x√2x√2x i j 1 1 2 2 1 2 www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.3 Kernels  Why use kernels  Make nonseparable problem separable.  Map data into better representational space  Common kernels  Linear T d  Polynomial K(x,z) = (1+x z)  Gives feature conjunctions  Radial basis function (infinite dimensional space)  Haven’t been very useful in text classification www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 Evaluation: Classic Reuters21578 Data Set  Most (over)used data set  21578 documents  9603 training, 3299 test articles (ModApte/Lewis split)  118 categories  An article can be in more than one category  Learn 118 binary category distinctions  Average document: about 90 types, 200 tokens  Average number of classes assigned  1.24 for docs with at least one category  Only about 10 out of 118 categories are large • Earn (2877, 1087) • Trade (369,119) Common categories • Acquisitions (1650, 179) • Interest (347, 131) (train, test) • Moneyfx (538, 179) • Ship (197, 89) • Grain (433, 149) • Wheat (212, 71) www.ThesisScientist.com • Crude (389, 189) • Corn (182, 56)Introduction to Information Retrieval Sec. 15.2.4 Reuters Text Categorization data set (Reuters21578) document REUTERS TOPICS="YES" LEWISSPLIT="TRAIN" CGISPLIT="TRAININGSET" OLDID="12981" NEWID="798" DATE 2MAR1987 16:51:43.42/DATE TOPICSDlivestock/DDhog/D/TOPICS TITLEAMERICAN PORK CONGRESS KICKS OFF TOMORROW/TITLE DATELINE CHICAGO, March 2 /DATELINEBODYThe American Pork Congress kicks off tomorrow, March 3, in Indianapolis with 160 of the nations pork producers from 44 member states determining industry positions on a number of issues, according to the National Pork Producers Council, NPPC. Delegates to the three day Congress will be considering 26 resolutions concerning various issues, including the future direction of farm policy and the tax law as it applies to the agriculture sector. The delegates will also debate whether to endorse concepts of a national PRV (pseudorabies virus) control and eradication program, the NPPC said. A large trade show, in conjunction with the congress, will feature the latest in technology in all areas of the industry, the NPPC added. Reuter 3;/BODY/TEXT/REUTERS www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 Per class evaluation measures c ii  Recall: Fraction of docs in class i c å ij classified correctly: j c ii    Precision: Fraction of docs assigned c å ji class i that are actually about class i: j c å ii i    Accuracy: (1 error rate) Fraction of c åå ij docs classified correctly: j i www.ThesisScientist.com   Introduction to Information Retrieval Sec. 15.2.4 Micro vs. MacroAveraging  If we have more than one class, how do we combine multiple performance measures into one quantity  Macroaveraging: Compute performance for each class, then average.  Microaveraging: Collect decisions for all classes, compute contingency table, evaluate. www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 Micro vs. MacroAveraging: Example Class 1 Class 2 Micro Ave. Table Truth: Truth: Truth: Truth: Truth: Truth: yes no yes no yes no Classifi 10 10 Classifi 90 10 Classifier: 100 20 er: yes er: yes yes Classifi 10 970 Classifi 10 890 Classifier: 20 1860 er: no er: no no  Macroaveraged precision: (0.5 + 0.9)/2 = 0.7  Microaveraged precision: 100/120 = .83  Microaveraged score is dominated by score on common classes www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 www.ThesisScientist.comIntroduction to Information Retrieval Precisionrecall for category: Crude 1 0.9 0.8 0.7 0.6 0.5 Recall LSVM 0.4 Decision Tree 0.3 Naïve Bayes 0.2 Rocchio 0.1 0 Dumais 0 0.2 0.4 0.6 0.8 1 (1998) Precision www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 Precisionrecall for category: Ship 1 0.9 0.8 0.7 0.6 0.5 Recall LSVM 0.4 Decision Tree 0.3 Naïve Bayes 0.2 Rocchio 0.1 0 Dumais 0 0.2 0.4 0.6 0.8 1 (1998) Precision www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 YangLiu: SVM vs. Other Methods www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.2.4 Good practice department: Make a confusion matrix This (i, j) entry means 53 of the docs actually in class i were put in class j by the classifier. Class assigned by classifier 53  In a perfect classification, only the diagonal has nonzero entries  Look at common confusions and how they might be addressed www.ThesisScientist.com Actual ClassIntroduction to Information Retrieval Sec. 15.3 The Real World P. Jackson and I. Moulinier. 2002. Natural Language Processing for Online Applications  “There is no question concerning the commercial value of being able to classify documents automatically by content. There are myriad potential applications of such a capability for corporate intranets, government departments, and Internet publishers”  “Understanding the data is one of the keys to successful categorization, yet this is an area in which most categorization tool vendors are extremely weak. Many of the ‘one size fits all’ tools on the market have not been tested on a wide range of content types.” www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 The Real World  Gee, I’m building a text classifier for real, now  What should I do  How much training data do you have  None  Very little  Quite a lot  A huge amount and its growing www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 Manually written rules  No training data, adequate editorial staff  Never forget the handwritten rules solution  If (wheat or grain) and not (whole or bread) then  Categorize as grain  In practice, rules get a lot bigger than this  Can also be phrased using tf or tf.idf weights  With careful crafting (human tuning on development data) performance is high:  Construe: 94 recall, 84 precision over 675 categories (Hayes and Weinstein 1990)  Amount of work required is huge  Estimate 2 days per class … plus maintenance www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 Very little data  If you’re just doing supervised classification, you should stick to something high bias  There are theoretical results that Naïve Bayes should do well in such circumstances (Ng and Jordan 2002 NIPS)  The interesting theoretical answer is to explore semi supervised training methods:  Bootstrapping, EM over unlabeled documents, …  The practical answer is to get more labeled data as soon as you can  How can you insert yourself into a process where humans will be willing to label data for you www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 A reasonable amount of data  Perfect  We can use all our clever classifiers  Roll out the SVM  But if you are using an SVM/NB etc., you should probably be prepared with the “hybrid” solution where there is a Boolean overlay  Or else to use userinterpretable Booleanlike models like decision trees  Users like to hack, and management likes to be able to implement quick fixes immediately www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 A huge amount of data  This is great in theory for doing accurate classification…  But it could easily mean that expensive methods like SVMs (train time) or kNN (test time) are quite impractical  Naïve Bayes can come back into its own again  Or other advanced methods with linear training/test complexity like regularized logistic regression (though much more expensive to train) www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.1 Accuracy as a function of data size  With enough data the choice of classifier may not matter much, and the best choice may be unclear  Data: Brill and Banko on contextsensitive spelling correction  But the fact that you have to keep doubling your data to improve performance is a little unpleasant www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 How many categories  A few (well separated ones)  Easy  A zillion closely related ones  Think: Yahoo Directory, Library of Congress classification, legal applications  Quickly gets difficult  Classifier combination is always a useful technique  Voting, bagging, or boosting multiple classifiers  Much literature on hierarchical classification  Mileage fairly unclear, but helps a bit (TieYan Liu et al. 2005)  May need a hybrid automatic/manual solution www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 How can one tweak performance  Aim to exploit any domainspecific useful features that give special meanings or that zone the data  E.g., an author byline or mail headers  Aim to collapse things that would be treated as different but shouldn’t be.  E.g., part numbers, chemical formulas  Does putting in “hacks” help  You bet  Feature design and nonlinear weighting is very important in the performance of realworld systems www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 Upweighting  You can get a lot of value by differentially weighting contributions from different document zones:  That is, you count as two instances of a word when you see it in, say, the abstract  Upweighting title words helps (Cohen Singer 1996)  Doubling the weighting on the title words is a good rule of thumb  Upweighting the first sentence of each paragraph helps (Murata, 1999)  Upweighting sentences that contain title words helps (Ko et al, 2002) www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 Two techniques for zones 1. Have a completely separate set of features/parameters for different zones like the title 2. Use the same features (pooling/tying their parameters) across zones, but upweight the contribution of different zones  Commonly the second method is more successful: it costs you nothing in terms of sparsifying the data, but can give a very useful performance boost  Which is best is a contingent fact about the data www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 Text Summarization techniques in text classification  Text Summarization: Process of extracting key pieces from text, normally by features on sentences reflecting position and content  Much of this work can be used to suggest weightings for terms in text categorization  See: Kolcz, Prabakarmurthi, and Kalita, CIKM 2001: Summarization as feature selection for text categorization  Categorizing purely with title,  Categorizing with first paragraph only  Categorizing with paragraph with most keywords  Categorizing with first and last paragraphs, etc. www.ThesisScientist.comIntroduction to Information Retrieval Sec. 15.3.2 Does stemming/lowercasing/… help  As always, it’s hard to tell, and empirical evaluation is normally the gold standard  But note that the role of tools like stemming is rather different for TextCat vs. IR:  For IR, you often want to collapse forms of the verb oxygenate and oxygenation, since all of those documents will be relevant to a query for oxygenation  For TextCat, with sufficient training data, stemming does no good. It only helps in compensating for data sparseness (which can be severe in TextCat applications). Overly aggressive stemming can easily degrade performance. www.ThesisScientist.comIntroduction to Information Retrieval Measuring Classification Figures of Merit  Not just accuracy; in the real world, there are economic measures:  Your choices are:  Do no classification  That has a cost (hard to compute)  Do it all manually  Has an easytocompute cost if doing it like that now  Do it all with an automatic classifier  Mistakes have a cost  Do it with a combination of automatic classification and manual review of uncertain/difficult/”new” cases  Commonly the last method is most cost efficient and is adopted www.ThesisScientist.comIntroduction to Information Retrieval A common problem: Concept Drift  Categories change over time  Example: “president of the united states”  1999: clinton is great feature  2010: clinton is bad feature  One measure of a text classification system is how well it protects against concept drift.  Favors simpler models like Naïve Bayes  Feature selection: can be bad in protecting against concept drift www.ThesisScientist.comIntroduction to Information Retrieval Summary  Support vector machines (SVM)  Choose hyperplane based on support vectors  Support vector = “critical” point close to decision boundary  (Degree1) SVMs are linear classifiers.  Kernels: powerful and elegant way to define similarity metric  Perhaps best performing text classifier  But there are other methods that perform about as well as SVM, such as regularized logistic regression (Zhang Oles 2001)  Partly popular due to availability of good software  SVMlight is accurate and fast – and free (for research)  Now lots of good software: libsvm, TinySVM, ….  Comparative evaluation of methods  Real world: exploit domain specific structure www.ThesisScientist.comIntroduction to Information Retrieval Ch. 15 Resources for today’s lecture  Christopher J. C. Burges. 1998. A Tutorial on Support Vector Machines for Pattern Recognition  S. T. Dumais. 1998. Using SVMs for text categorization, IEEE Intelligent Systems, 13(4)  S. T. Dumais, J. Platt, D. Heckerman and M. Sahami. 1998. Inductive learning algorithms and representations for text categorization. CIKM ’98, pp. 148155.  Yiming Yang, Xin Liu. 1999. A reexamination of text categorization methods. 22nd Annual International SIGIR  Tong Zhang, Frank J. Oles. 2001. Text Categorization Based on Regularized Linear Classification Methods. Information Retrieval 4(1): 531  Trevor Hastie, Robert Tibshirani and Jerome Friedman. Elements of Statistical Learning: Data Mining, Inference and Prediction. SpringerVerlag, New York.  T. Joachims, Learning to Classify Text using Support Vector Machines. Kluwer, 2002.  Fan Li, Yiming Yang. 2003. A Loss Function Analysis for Classification Methods in Text Categorization. ICML 2003: 472479.  TieYan Liu, Yiming Yang, Hao Wan, et al. 2005. Support Vector Machines Classification with Very Large Scale Taxonomy, SIGKDD Explorations, 7(1): 3643. ‘Classic’ Reuters21578 data set: http://www.daviddlewis.com /resources /testcollections/reuters21578/ www.ThesisScientist.com
Website URL
Comment