Text Categorization CSE 454. (Based on slides by Dan Weld, Tom Mitchell, and others)

Similar documents
Classification Algorithms

Classification Algorithms

Bayes Theorem & Naïve Bayes. (some slides adapted from slides by Massimo Poesio, adapted from slides by Chris Manning)

Naïve Bayes. Vibhav Gogate The University of Texas at Dallas

Logistics. Naïve Bayes & Expectation Maximization. 573 Schedule. Coming Soon. Estimation Models. Topics

Lecture 9: Naive Bayes, SVM, Kernels. Saravanan Thirumuruganathan

Why Probability? It's the right way to look at the world.

Bayesian Learning. Examples. Conditional Probability. Two Roles for Bayesian Methods. Prior Probability and Random Variables. The Chain Rule P (B)

Today. Statistical Learning. Coin Flip. Coin Flip. Experiment 1: Heads. Experiment 1: Heads. Which coin will I use? Which coin will I use?

Introduction to Machine Learning

Introduction to Machine Learning

Bayesian Learning. Artificial Intelligence Programming. 15-0: Learning vs. Deduction

Naïve Bayes classification

CSCE 478/878 Lecture 6: Bayesian Learning

Stephen Scott.

Naïve Bayes classification. p ij 11/15/16. Probability theory. Probability theory. Probability theory. X P (X = x i )=1 i. Marginal Probability

Behavioral Data Mining. Lecture 2

CSCE 478/878 Lecture 6: Bayesian Learning and Graphical Models. Stephen Scott. Introduction. Outline. Bayes Theorem. Formulas

9/12/17. Types of learning. Modeling data. Supervised learning: Classification. Supervised learning: Regression. Unsupervised learning: Clustering

10/15/2015 A FAST REVIEW OF DISCRETE PROBABILITY (PART 2) Probability, Conditional Probability & Bayes Rule. Discrete random variables

Introduction to Machine Learning. Introduction to ML - TAU 2016/7 1

Last Time. Today. Bayesian Learning. The Distributions We Love. CSE 446 Gaussian Naïve Bayes & Logistic Regression

Chapter 6 Classification and Prediction (2)

Probabilistic Classification

Information Retrieval and Organisation

Machine Learning

Which coin will I use? Which coin will I use? Logistics. Statistical Learning. Topics. 573 Topics. Coin Flip. Coin Flip

Machine Learning

Be able to define the following terms and answer basic questions about them:

Introduction to AI Learning Bayesian networks. Vibhav Gogate

Final Examination CS 540-2: Introduction to Artificial Intelligence

Stephen Scott.

Tutorial 6. By:Aashmeet Kalra

Classification CE-717: Machine Learning Sharif University of Technology. M. Soleymani Fall 2012

Machine Learning. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 8 May 2012

CS 6375 Machine Learning

CS 188: Artificial Intelligence. Machine Learning

Bayesian Inference. Definitions from Probability: Naive Bayes Classifiers: Advantages and Disadvantages of Naive Bayes Classifiers:

Machine Learning

A REVIEW ARTICLE ON NAIVE BAYES CLASSIFIER WITH VARIOUS SMOOTHING TECHNIQUES

The Naïve Bayes Classifier. Machine Learning Fall 2017

Generative Models. CS4780/5780 Machine Learning Fall Thorsten Joachims Cornell University

Probability Review and Naïve Bayes

Lecture 9: Bayesian Learning

Bayesian Learning. Instructor: Jesse Davis

CS 188: Artificial Intelligence Spring Today

Naïve Bayes Classifiers and Logistic Regression. Doug Downey Northwestern EECS 349 Winter 2014

CSCI-567: Machine Learning (Spring 2019)

Machine Learning for natural language processing

Topics. Bayesian Learning. What is Bayesian Learning? Objectives for Bayesian Learning

COMP 328: Machine Learning

Naïve Bayes. Jia-Bin Huang. Virginia Tech Spring 2019 ECE-5424G / CS-5824

Bayesian Learning Features of Bayesian learning methods:

Generative Classifiers: Part 1. CSC411/2515: Machine Learning and Data Mining, Winter 2018 Michael Guerzhoy and Lisa Zhang

Logistic Regression. Machine Learning Fall 2018

Generative Models for Classification

Modern Information Retrieval

Numerical Learning Algorithms

Bayesian Learning. CSL603 - Fall 2017 Narayanan C Krishnan

MIDTERM: CS 6375 INSTRUCTOR: VIBHAV GOGATE October,

Bayesian Learning. Two Roles for Bayesian Methods. Bayes Theorem. Choosing Hypotheses

MODULE -4 BAYEIAN LEARNING

CS 446 Machine Learning Fall 2016 Nov 01, Bayesian Learning

Applied Logic. Lecture 4 part 2 Bayesian inductive reasoning. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Relationship between Least Squares Approximation and Maximum Likelihood Hypotheses

Classification (Categorization) CS 391L: Machine Learning: Inductive Classification. Raymond J. Mooney. Sample Category Learning Problem

Bayesian Learning Extension

Generative Techniques: Bayes Rule and the Axioms of Probability

Midterm Exam, Spring 2005

Click Prediction and Preference Ranking of RSS Feeds

Algorithm-Independent Learning Issues

Pattern Recognition and Machine Learning. Learning and Evaluation of Pattern Recognition Processes

Machine Learning 2010

SUPERVISED LEARNING: INTRODUCTION TO CLASSIFICATION

CS4705. Probability Review and Naïve Bayes. Slides from Dragomir Radev

Bayesian Methods: Naïve Bayes

Categorization ANLP Lecture 10 Text Categorization with Naive Bayes

ANLP Lecture 10 Text Categorization with Naive Bayes

[read Chapter 2] [suggested exercises 2.2, 2.3, 2.4, 2.6] General-to-specific ordering over hypotheses

DATA MINING LECTURE 10

Probabilistic Graphical Models

Naïve Bayes Classifiers

Machine learning comes from Bayesian decision theory in statistics. There we want to minimize the expected value of the loss function.

2.4. Conditional Probability

Bayes Formula. MATH 107: Finite Mathematics University of Louisville. March 26, 2014

naive bayes document classification

CPSC 340: Machine Learning and Data Mining. MLE and MAP Fall 2017

Module 2 : Conditional Probability

Classification: Naïve Bayes. Nathan Schneider (slides adapted from Chris Dyer, Noah Smith, et al.) ENLP 19 September 2016

Outline. CSE 573: Artificial Intelligence Autumn Agent. Partial Observability. Markov Decision Process (MDP) 10/31/2012

Be able to define the following terms and answer basic questions about them:

From inductive inference to machine learning

Decision Trees (Cont.)

CS-E3210 Machine Learning: Basic Principles

Generative Models for Discrete Data

Gaussian discriminant analysis Naive Bayes

Naive Bayes classification

CS 6375: Machine Learning Computational Learning Theory

Mining of Massive Datasets Jure Leskovec, AnandRajaraman, Jeff Ullman Stanford University

Lecture 25 of 42. PAC Learning, VC Dimension, and Mistake Bounds

Transcription:

Text Categorization CSE 454 (Based on slides by Dan Weld, Tom Mitchell, and others) 1

Given: Categorization A description of an instance, x X, where X is the instance language or instance space. A fixed set of categories: C={c 1, c 2, c n } Determine: The category of x: c(x) C, where c(x) is a categorization function whose domain is X and whose range is C. 2

Sample Category Learning Problem Instance language: <size, color, shape> size {small, medium, large} color {red, blue, green} shape {square, circle, triangle} C = {positive, negative} D: Example Size Color Shape Category 1 small red circle positive 2 large red circle positive 3 small red triangle negative 4 large blue circle negative 3

Applications of Categorization Credit card fraud Product placement / consumer behavior Recommender systems Speech recognition Most mature & successful area of AI Daniel S. Weld 4

Example: County vs. Country? Given: A description of an instance, x X, where X is the instance language or instance space. A fixed set of categories: C={c 1, c 2, c n } Determine: The category of x: c(x) C, where c(x) is a categorization function whose domain is X and whose range is C. 5

Text Categorization Assigning documents to a fixed set of categories, e.g. Web pages Yahoo-like classification What else? Email messages Spam filtering Prioritizing Folderizing News articles Personalized newspaper Web Ranking Is page related to selling something? 6

Approach: Procedural Classification Write a procedure to determine a document s class E.g., Spam?

Learning for Text Categorization Hard to construct text categorization functions. Learning Algorithms: Bayesian (naïve) Neural network Relevance Feedback (Rocchio) Rule based (C4.5, Ripper, Slipper) Nearest Neighbor (case based) Support Vector Machines (SVM) 8

Learning for Categorization A training example is an instance x X, paired with its correct category c(x): <x, c(x)> for an unknown categorization function, c. Given a set of training examples, D. {<, county>, <, country>, Find a hypothesized categorization function, h(x), such that: < x ( ) > : ( ) = Consistency, c x D h x c( x) 9

ML = Function Approximation May not be any perfect fit Classification ~ discrete functions h(x) = contains(`nigeria, x) contains(`wire-transfer, x) h(x) c(x) 10 x

Generalization Hypotheses must generalize to correctly classify instances not in the training data. Simply memorizing training examples is a consistent hypothesis that does not generalize. 11

Why is Learning Possible? Experience alone never justifies any conclusion about any unseen instance. Learning occurs when PREJUDICE meets DATA! Learning a Frobnitz Daniel S. Weld 12

Bias The nice word for prejudice is bias. What kind of hypotheses will you consider? What is allowable range of functions you use when approximating? What kind of hypotheses do you prefer? Daniel S. Weld 13

Some Typical Biases Occam s razor It is needless to do more when less will suffice William of Occam, died 1349 of the Black plague MDL Minimum description length Concepts can be approximated by... conjunctions of predicates... by linear functions... by short decision trees Daniel S. Weld 14

A Learning Problem Daniel S. Weld 15

Hypothesis Spaces Daniel S. Weld 16

Terminology Daniel S. Weld 17

General Learning Issues Many hypotheses consistent with the training data. Bias Any criteria other than consistency with the training data that is used to select a hypothesis. Classification accuracy % of instances classified correctly (Measured on independent test data.) Training time Efficiency of training algorithm Testing time Efficiency of subsequent classification 18

Two Strategies for ML Restriction bias: use prior knowledge to specify a restricted hypothesis space. Naïve Bayes Classifier Preference bias: use a broad hypothesis space, but impose an ordering on the hypotheses. Decision trees. Daniel S. Weld 19

Bayesian Methods Learning and classification methods based on probability theory. Uses prior probability of each category Given no information about an item. Produces a posterior probability distribution over possible categories Given a description of an item. Bayes theorem plays a critical role in probabilistic learning and classification. 20

Axioms of Probability Theory All probabilities between 0 and 1 0 P( A) 1 Probability of truth and falsity P(true) = 1 P(false) = 0. The probability of disjunction is: P( A B) = P( A) + P( B) P( A B) A A B B 21

Probability: Simple & Logical 22

Conditional Probability P(A B) is the probability of A given B Assumes: B is all and only information known. Defined by: P( A B) P( A B) = P( B) A A B B 23

Independence A and B are independent iff: P ( A B) = P( A) These constraints are logically equivalent P ( B A) = P( B) Therefore, if A and B are independent: P( A B) P ( A B) = = P( A) P( B) P ( A B) = P( A) P( B) 24

Daniel S. Weld 25 Independence P(A B) = P(A)P(B) A A B True B

Daniel S. Weld 26 Independence Is Rare A&B not independent, since P(A B) P(A) A B A P(A) = 25% P(B) = 80% True B P(A B) =? 1/7

Daniel S. Weld 27 Conditional Independence Are A & B independent? P(A B)? P(A) A A B P(A)=(.25+.5)/2 =.375 P(B)=.75 B P(A B)=(.25+.25+.5)/3 =.3333

Daniel S. Weld 28 A, B Conditionally Independent Given C P(A B,C) = P(A C) C = spots A C P(A C) =.25 C

Daniel S. Weld 29 A, B Conditionally Independent Given C P(A B,C) = P(A C) C = spots P(A C) =.25 P(B C) = 1.0 B C

Daniel S. Weld 30 A, B Conditionally Independent Given C P(A B,C) = P(A C) C = spots A B C B C P(A C) =.25 P(B C) = 1.0 P(A B,C)=.25

Daniel S. Weld 31 A, B Conditionally Independent Given C P(A B,C) = P(A C) C = spots A C A B C B C P(A C) =.25 P(B C) = 1.0 P(A B,C)=.25 P(A C) =.5 P(B C) =.5 P(A B, C)=.5

Daniel S. Weld 32 Conditional Independence = The Next Best Thing to Independence A, B Conditionally Independent Given C P(A B,C) = P(A C) = P(A C)

33 Bayes Theorem Simple proof from definition of conditional probability: ) ( ) ( ) ( ) ( E P H P H E P E H P = ) ( ) ( ) ( E P E H P E H P = ) ( ) ( ) ( H P H E P E H P = QED: (Def. cond. prob.) (Def. cond. prob.) ) ( ) ( ) ( ) ( E P H P H E P E H P = (Mult both sides of 2 by P(H).) (Substitute 3 in 1.) 1702-1761 ) ( ) ( ) ( H E P H P E H P =

Bayesian Categorization Let set of categories be {c 1, c 2, c n } Let E be description of an instance. Determine category of E by determining for each c i P( ci E) = P( c i ) P( E P( E) c i ) P(E) can be ignored since is factor categories P( ci E) ~ P( ci ) P( E ci ) 34

Bayesian Categorization P( ci E) ~ P( ci ) P( E ci ) Need to know: Priors: P(c i ) Conditionals: P(E c i ) P(c i ) are easily estimated from data. Problem! If n i of the examples in D are in c i,then P(c i ) = n i / D Assume instance is a conjunction of binary features: E = e1 e2 e m Too many possible instances (exponential in m) to estimate all P(E c i ) 35

36 Naïve Bayesian Motivation Problem: Too many possible instances (exp in m) to estimate all P(E c i ) Assume features of an instance are conditionally independent given the category (c i ) Now we only need to know P(e j c i ) for each feature and category. ) ( ) ( ) ( 1 2 1 = = = m j i j i m i c e P c e e e P c E P

Conditional Independence?? spam? due? egg? nigera? viagra? widow? P(nigeria spam) = P(nigeria spam, widow) P(nigeria spam) = P(nigeria spam, viagra)

Naïve Bayes Example C = {allergy, cold, well} e 1 = sneeze; e 2 = cough; e 3 = fever E = {sneeze, cough, fever} Prob Well Cold Allergy P(c i ) 0.9 0.05 0.05 P(sneeze c i ) 0.1 0.9 0.9 P(cough c i ) 0.1 0.8 0.7 P(fever c i ) 0.01 0.7 0.4 38

Naïve Bayes Example (cont.) Probability Well Cold Allergy P(c i ) 0.9 0.05 0.05 P(sneeze c i ) 0.1 0.9 0.9 E={sneeze, cough, fever} P(cough c i ) 0.1 0.8 0.7 P(fever c i ) 0.01 0.7 0.4 P(well E) = (0.9)(0.1)(0.1)(0.99)/P(E)=0.0089/P(E) P(cold E) = (0.05)(0.9)(0.8)(0.3)/P(E)=0.01/P(E) P(allergy E) = (0.05)(0.9)(0.7)(0.6)/P(E)=0.019/P(E) Most probable category: allergy P(E) = 0.089 + 0.01 + 0.019 = 0.0379 P(well E) = 0.23 P(cold E) = 0.26 P(allergy E) = 0.50 39

Estimating Probabilities Normally, probabilities are estimated based on observed frequencies in the training data. If D contains n i examples in category c i, and n ij of these n i examples contains feature e j, then: nij P ( e j ci ) = n However, estimating such probabilities from small training sets is error-prone. If due only to chance, a rare feature, e k, is always false in the training data, c i :P(e k c i ) = 0. If e k then occurs in a test example, E, the result is that c i : P(E c i ) = 0 and c i : P(c i E) = 0 i 40

Smoothing To account for estimation from small samples, probability estimates are adjusted or smoothed. Laplace smoothing using an m-estimate assumes that each feature is given a prior probability, p, that is assumed to have been previously observed in a virtual sample of size m. nij + mp P( e j ci ) = = (n ij + 1) / (n i + 2) n + m For binary features, p is simply assumed to be 0.5. i 41

Naïve Bayes for Text Modeled as generating a bag of words for a document in a given category by repeatedly sampling with replacement from a vocabulary V = {w 1, w 2, w m } based on the probabilities P(w j c i ). Smooth probability estimates with Laplace m-estimates assuming a uniform distribution over all words (p = 1/ V ) and m = V Equivalent to a virtual sample of seeing each word in each category exactly once. 42

Text Naïve Bayes Algorithm (Train) Let V be the vocabulary of all words in the documents in D For each category c i C Let D i be the subset of documents in D in category c i P(c i ) = D i / D Let T i be the concatenation of all the documents in D i Let n i be the total number of word occurrences in T i For each word w j V Let n ij be the number of occurrences of w j in T i Let P(w i c i ) = (n ij + 1) / (n i + V ) 43

Text Naïve Bayes Algorithm (Test) Given a test document X Let n be the number of word occurrences in X Return the category: argmax P( c c i C i ) n i= 1 P( a i c i where a i is the word occurring the ith position in X ) 44

Naïve Bayes Time Complexity Training Time: O( D L d + C V )) where L d is the average length of a document in D. Assumes V and all D i, n i, and n ij pre-computed in O( D L d ) time during one pass through all of the data. Generally just O( D L d ) since usually C V < D L d Test Time: O( C L t ) where L t is the average length of a test document. Very efficient overall, linearly proportional to the time needed to just read in all the data. 45

Easy to Implement But If you do it probably won t work 46

Probabilities: Important Detail! P(spam E 1 E n ) = Π P(spam E i ) i Any more potential problems here? We are multiplying lots of small numbers Danger of underflow! 0.5 57 = 7 E -18 Solution? Use logs and add! p 1 * p 2 = e log(p1)+log(p2) Always keep in log form

Underflow Prevention Multiplying lots of probabilities, which are between 0 and 1 by definition, can result in floating-point underflow. Since log(xy) = log(x) + log(y), it is better to perform all computations by summing logs of probabilities rather than multiplying probabilities. Class with highest final un-normalized log probability score is still the most probable. 48

Naïve Bayes Posterior Probabilities Classification results of naïve Bayes I.e. the class with maximum posterior probability Usually fairly accurate (?!?!?) However, due to the inadequacy of the conditional independence assumption Actual posterior-probability estimates not accurate. Output probabilities generally very close to 0 or 1. 49

Multi-Class Categorization Pick the category with max probability Create many 1 vs other classifiers Use a hierarchical approach (wherever hierarchy available) Entity Person Location Scientist Artist City County Country 50