1 Text Categorization CSE 454. Administrivia Project Warmup –Out today Naïve Bayes classifier for web pages Run using Hadoop –Due 10/16 noon –Done individually.

Slides:



Advertisements
Similar presentations
Text Categorization.
Advertisements

Naïve Bayes. Bayesian Reasoning Bayesian reasoning provides a probabilistic approach to inference. It is based on the assumption that the quantities of.
Naïve-Bayes Classifiers Business Intelligence for Managers.
Uncertainty Everyday reasoning and decision making is based on uncertain evidence and inferences. Classical logic only allows conclusions to be strictly.
Text Categorization CSC 575 Intelligent Information Retrieval.
Ai in game programming it university of copenhagen Statistical Learning Methods Marco Loog.
Learning for Text Categorization
Bayesian Learning Rong Jin. Outline MAP learning vs. ML learning Minimum description length principle Bayes optimal classifier Bagging.
Bayes Rule How is this rule derived? Using Bayes rule for probabilistic inference: –P(Cause | Evidence): diagnostic probability –P(Evidence | Cause): causal.
1 Text Categorization CSE 454. Administrivia Mailing List Groups for PS1 Questions on PS1? Groups for Project Ideas for Project.
CSE 5731 Lecture 26 Introduction to Machine Learning CSE 573 Artificial Intelligence I Henry Kautz Fall 2001.
Data Mining with Decision Trees Lutz Hamel Dept. of Computer Science and Statistics University of Rhode Island.
Machine Learning CSE 473. © Daniel S. Weld Topics Agency Problem Spaces Search Knowledge Representation Reinforcement Learning InferencePlanning.
1er. Escuela Red ProTIC - Tandil, de Abril, Bayesian Learning 5.1 Introduction –Bayesian learning algorithms calculate explicit probabilities.
Learning Bayesian Networks
Text Categorization Moshe Koppel Lecture 2: Naïve Bayes Slides based on Manning, Raghavan and Schutze.
CS Bayesian Learning1 Bayesian Learning. CS Bayesian Learning2 States, causes, hypotheses. Observations, effect, data. We need to reconcile.
1 Text Categorization. 2 Categorization Given: –A description of an instance, x  X, where X is the instance language or instance space. –A fixed set.
Classification and Prediction: Basic Concepts Bamshad Mobasher DePaul University Bamshad Mobasher DePaul University.
For Monday after Spring Break Read Homework: –Chapter 13, exercise 6 and 8 May be done in pairs.
1 Text Categorization  Assigning documents to a fixed set of categories  Applications:  Web pages  Recommending pages  Yahoo-like classification hierarchies.
1 Naïve Bayes A probabilistic ML algorithm. 2 Axioms of Probability Theory All probabilities between 0 and 1 True proposition has probability 1, false.
1 CSE 446 Machine Learning Daniel Weld Xiao Ling Congle Zhang.
DATA MINING : CLASSIFICATION. Classification : Definition  Classification is a supervised learning.  Uses training sets which has correct answers (class.
Fall 2004 TDIDT Learning CS478 - Machine Learning.
Processing of large document collections Part 2 (Text categorization) Helena Ahonen-Myka Spring 2006.
1 Text Categorization. 2 Categorization Given: –A description of an instance, x  X, where X is the instance language or instance space. –A fixed set.
Bayesian Networks. Male brain wiring Female brain wiring.
Processing of large document collections Part 2 (Text categorization, term selection) Helena Ahonen-Myka Spring 2005.
Text Classification, Active/Interactive learning.
1 CS 343: Artificial Intelligence Probabilistic Reasoning and Naïve Bayes Raymond J. Mooney University of Texas at Austin.
Naive Bayes Classifier
1 CS 391L: Machine Learning: Bayesian Learning: Naïve Bayes Raymond J. Mooney University of Texas at Austin.
1 CS 391L: Machine Learning: Experimental Evaluation Raymond J. Mooney University of Texas at Austin.
CSE 446: Point Estimation Winter 2012 Dan Weld Slides adapted from Carlos Guestrin (& Luke Zettlemoyer)
Empirical Research Methods in Computer Science Lecture 7 November 30, 2005 Noah Smith.
1 Text Categorization. 2 Categorization Given: –A description of an instance, x  X, where X is the instance language or instance space. –A fixed set.
Bayesian Classification. Bayesian Classification: Why? A statistical classifier: performs probabilistic prediction, i.e., predicts class membership probabilities.
Classification Techniques: Bayesian Classification
1 Naïve Bayes Classification CS 6243 Machine Learning Modified from the slides by Dr. Raymond J. Mooney
For Monday No new reading Homework: –Chapter 18, exercises 3 and 4.
CS Machine Learning 15 Jan Inductive Classification.
CHAPTER 6 Naive Bayes Models for Classification. QUESTION????
1 CS 391L: Machine Learning Text Categorization Raymond J. Mooney University of Texas at Austin.
KNN & Naïve Bayes Hongning Wang Today’s lecture Instance-based classifiers – k nearest neighbors – Non-parametric learning algorithm Model-based.
1 Text Categorization Slides based on R. Mooney (UT Austin)
1 Text Categorization CSE Categorization Given: –A description of an instance, x  X, where X is the instance language or instance space. –A fixed.
CS 8751 ML & KDDComputational Learning Theory1 Notions of interest: efficiency, accuracy, complexity Probably, Approximately Correct (PAC) Learning Agnostic.
Bayesian Learning Bayes Theorem MAP, ML hypotheses MAP learners
Machine Learning Chapter 7. Computational Learning Theory Tom M. Mitchell.
CS 2750: Machine Learning Probability Review Prof. Adriana Kovashka University of Pittsburgh February 29, 2016.
Naïve Bayes Classifier April 25 th, Classification Methods (1) Manual classification Used by Yahoo!, Looksmart, about.com, ODP Very accurate when.
BAYESIAN LEARNING. 2 Bayesian Classifiers Bayesian classifiers are statistical classifiers, and are based on Bayes theorem They can calculate the probability.
Machine Learning & Datamining CSE 454. © Daniel S. Weld 2 Project Part 1 Feedback Serialization Java Supplied vs. Manual.
1 Text Categorization  Assigning documents to a fixed set of categories  Applications:  Web pages  Recommending pages  Yahoo-like classification hierarchies.
Introduction to Information Retrieval Introduction to Information Retrieval Lecture 15: Text Classification & Naive Bayes 1.
KNN & Naïve Bayes Hongning Wang
Naive Bayes Classifier. REVIEW: Bayesian Methods Our focus this lecture: – Learning and classification methods based on probability theory. Bayes theorem.
Naive Bayes Classifier
Lecture 15: Text Classification & Naive Bayes
Intelligent Information Retrieval
Data Mining Lecture 11.
Classification Techniques: Bayesian Classification
Text Categorization (continued)
Text Categorization Assigning documents to a fixed set of categories
Where did we stop? The Bayes decision rule guarantees an optimal classification… … But it requires the knowledge of P(ci|x) (or p(x|ci) and P(ci)) We.
Why Machine Learning Flood of data
Text Categorization CSE 454.
Hankz Hankui Zhuo Text Categorization Hankz Hankui Zhuo
Hankz Hankui Zhuo Bayesian Networks Hankz Hankui Zhuo
Presentation transcript:

1 Text Categorization CSE 454

Administrivia Project Warmup –Out today Naïve Bayes classifier for web pages Run using Hadoop –Due 10/16 noon –Done individually Main Project –Form teams –Proposals by 10/11 if other than default 2

Administrivia II Sean McCarthy Luo Pan Jordan Ludke Brian Ngo Nina Chyi Liong Kansu Dincer Brandon Bell Aron Ritchie Christopher Lim Christopher C. White 3 David Balatero Christopher S. Schlechty Robert Gay Felix Chu Jeffrey Hebrank Kyle Johnson Brian Steadman Vjekoslav Brajkovic Alyssa Harding Ting-You Wang

Syllabus Text Processing Tasks –Classification –Retrieval (Similarity Measures) –Extraction (NL text  database records) Techniques –Machine Learning –Vector-Space Model –Syntactic Analysis –Hyperlinks & Web Structure Scaling –Parallelism –Indexing Special Topics 1/15/2016 6:10 PM 4

5 Categorization 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.

6 Sample Category Learning Problem Instance language: –size  {small, medium, large} –color  {red, blue, green} –shape  {square, circle, triangle} C = {positive, negative} D: ExampleSizeColorShapeCategory 1smallredcirclepositive 2largeredcirclepositive 3smallredtrianglenegative 4largebluecirclenegative

Another Example: County vs. Country? 7

Example: County vs. Country? 8 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.

9 Text Categorization Assigning documents to a fixed set of categories, e.g. Web pages –Categories in search (see microsoft.com) –Yahoo-like classification Newsgroup Messages –Recommending –Spam filtering News articles –Personalized newspaper messages –Routing –Prioritizing –Folderizing –spam filtering

10 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)

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

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

Function Approximation 13 c(x) x May not be any perfect fit Classification ~ discrete functions h(x)

14 General Learning Issues Many hypotheses are usually 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

15 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. Occam’s razor: –Finding a simple hypothesis helps ensure generalization.

© Daniel S. Weld 16 Why is Learning Possible? Experience alone never justifies any conclusion about any unseen instance. Learning occurs when PREJUDICE meets DATA! Learning a “FOO”

© Daniel S. Weld 17 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 18 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 19 A Learning Problem

© Daniel S. Weld 20 Hypothesis Spaces

© Daniel S. Weld 21 Terminology

© Daniel S. Weld 22 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.

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

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

25 Probability: Simple & Logical

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

27 Independence A and B are independent iff: Therefore, if A and B are independent: These two constraints are logically equivalent

Conditional Independence P(A|B) = P(A) –Nice simple independence PA|B,C) = P(A|C) –“A is conditionally independent of B given C” 28 ABCABC

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

30 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(E) can be determined since categories are complete and disjoint.

31 Bayesian Categorization (cont.) Need to know: –Priors: P(c i ) –Conditionals: P(E | c i ) P(c i ) are easily estimated from data. –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: Too many possible instances (exponential in m) to estimate all P(E | c i ) Huh???

32 Naïve Bayesian Motivation Problem: Too many possible instances (exponential in m) to estimate all P(E | c i ) If we assume features of an instance are independent given the category (c i ) (conditionally independent). Therefore, we then only need to know P(e j | c i ) for each feature and category.

33 Naïve Bayes Example C = {allergy, cold, well} e 1 = sneeze; e 2 = cough; e 3 = fever E = {sneeze, cough,  fever} ProbWellColdAllergy P(c i ) P(sneeze|c i ) P(cough|c i ) P(fever|c i )

34 Naïve Bayes Example (cont.) 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) = = P(well | E) = 0.23 P(cold | E) = 0.26 P(allergy | E) = 0.50 ProbabilityWellColdAllergy P(c i ) P(sneeze | c i ) P(cough | c i ) P(fever | c i ) E={sneeze, cough,  fever}

35 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: 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

36 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. For binary features, p is simply assumed to be 0.5. = (n ij + 1) / (n i + 2)

37 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.

38 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|)

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

40 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. Similar to Rocchio time complexity.

41 Easy to Implement But… If you do… it probably won’t work…

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

43 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.

44 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.