25
TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

  • View
    228

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

TEXT CLASSIFICATION

CC437

(Includes some original material by Chris Manning)

Page 2: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

CATEGORIZATION / CLASSIFICATION

Given:– A description of an instance, xX, where X is the

instance language or instance space. E.g: how to represent text documents.

– A fixed set of categories C = {c1, c2,…, cn}

Determine:– The category of x: c(x)C, where c(x) is a

categorization function whose domain is X and whose range is C.

Page 3: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

A GRAPHICAL VIEW OF TEXT CLASSIFICATION

NLP

Graphics

AI

Theory

Arch.

Page 4: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

TEXT CLASSIFICATION

This concerns you as a patient.

Our medical records indicate you have had a history of illness. We are now encouraging all our patients to use this highly effective and safe solution.

Proven worldwide, feel free to read the many reports on our site from the BBC & ABC News.

We highly recommend you try this Anti-Microbial Peptide as soon as possible since its world supply is limited. The results will show quickly.

Regards, http://www.superbiograde.us/bkhog/ 85% of all email!!

Page 5: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

EXAMPLES OF TEXT CATEGORIZATION

LABELS=BINARY– “spam” / “not spam”

LABELS=TOPICS– “finance” / “sports” / “asia”

LABELS=OPINION– “like” / “hate” / “neutral”

LABELS=AUTHOR– “Shakespeare” / “Marlowe” / “Ben Jonson”– The Federalist papers

Page 6: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Methods (1)

Manual classification– Used by Yahoo!, Looksmart, about.com, ODP, Medline– very accurate when job is done by experts– consistent when the problem size and team is small– difficult and expensive to scale

Automatic document classification– Hand-coded rule-based systems

Reuters, CIA, Verity, … Commercial systems have complex query languages

(everything in IR query languages + accumulators)

Page 7: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Methods (2)

Supervised learning of document-label assignment function: Autonomy, Kana, MSN, Verity, …

Naive Bayes (simple, common method) k-Nearest Neighbors (simple, powerful) Support-vector machines (new, more powerful) … plus many other methods No free lunch: requires hand-classified training data But can be built (and refined) by amateurs

Page 8: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Bayesian Methods

Learning and classification methods based on probability theory (see spelling / POS)

Bayes theorem plays a critical role Build a generative model that approximates how

data is produced 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.

Page 9: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Bayes’ Rule

)()|()()|(),( CPCXPXPXCPXCP

)(

)()|()|(

XP

CPCXPXCP

Page 10: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Maximum a posteriori Hypothesis

)|(argmax DhPhHh

MAP

)(

)()|(argmax

DP

hPhDPh

HhMAP

)()|(argmax hPhDPhHh

MAP

Page 11: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Maximum likelihood Hypothesis

If all hypotheses are a priori equally likely, we only

need to consider the P(D|h) term:

)|(argmax hDPhHh

ML

Page 12: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Naive Bayes Classifiers

Task: Classify a new instance based on a tuple of attribute values

nxxx ,,, 21

),,,|(argmax 21 njCc

MAP xxxcPcj

),,,(

)()|,,,(argmax

21

21

n

jjn

CcMAP cccP

cPcxxxPc

j

)()|,,,(argmax 21 jjnCc

MAP cPcxxxPcj

Page 13: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Naïve Bayes Classifier: Assumptions

P(cj)– Can be estimated from the frequency of classes in

the training examples.

P(x1,x2,…,xn|cj) – Need very, very large number of training examples

Conditional Independence Assumption:

Assume that the probability of observing the conjunction of attributes is equal to the product of the individual probabilities.

Page 14: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Flu

X1 X2 X5X3 X4

feversinus coughrunnynose muscle-ache

The Naïve Bayes Classifier

Conditional Independence Assumption: features are independent of each other given the class:

)|()|()|()|,,( 52151 CXPCXPCXPCXXP

Page 15: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Learning the Model

Common practice:maximum likelihood– simply use the frequencies in the data

)(

),()|(ˆ

j

jiiji cCN

cCxXNcxP

C

X1 X2 X5X3 X4 X6

N

cCNcP j

j

)()(ˆ

Page 16: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Using Naive Bayes Classifiers to Classify Text: Basic method

Attributes are text positions, values are words.

Still too many possibilities Assume that classification is independent of the

positions of the words– Use same parameters for each position

)|text""()|our""()(argmax

)|()(argmax

1j

j

jnjjCc

ijij

CcNB

cxPcxPcP

cxPcPc

Page 17: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Textj single document containing all docsj

for each word xk in Vocabulary

– nk number of occurrences of xk in Textj

Text Classification Algorithms: Learning

From training corpus, extract Vocabulary Calculate required P(cj) and P(xk | cj) terms

– For each cj in C do docsj subset of documents for which the target class is cj

||

1)|(

Vocabularyn

ncxP k

jk

|documents # total|

||)( j

j

docscP

Page 18: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Text Classification Algorithms: Classifying

positions all word positions in current document which contain tokens

found in Vocabulary

Return cNB, where

positionsi

jijCc

NB cxPcPc )|()(argmaxj

Page 19: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Naïve Bayes Posterior Probabilities

Classification results of naïve Bayes (the class with maximum posterior probability) are usually fairly accurate.

However, due to the inadequacy of the conditional independence assumption, the actual posterior-probability numerical estimates are not.– Output probabilities are generally very close to 0 or

1.

Page 20: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

Feature selection via Mutual Information

We might not want to use all words, but just reliable, good discriminators

In training set, choose k words which best discriminate the categories.

One way is in terms of Mutual Information:

– For each word w and each category c

}1,0{ }1,0{ )()(

),(log),(),(

w ce e cw

cwcw epep

eepeepcwI

Page 21: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

OTHER APPROACHES TO FEATURE SELECTION

T-TEST CHI SQUARE TF/IDF (CFR. IR lectures) Yang & Pedersen 1997: eliminating features

leads to improved performance

Page 22: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

NAÏVE BAYES NOT SO NAIVE

Naïve Bayes: First and Second place in KDD-CUP 97 competition, among 16 (then) state of the art algorithms

Robust to Irrelevant FeaturesIrrelevant Features cancel each other without affecting resultsInstead Decision Trees & Nearest-Neighbor methods can heavily suffer from this.

Very good in Domains with many equally important featuresDecision Trees suffer from fragmentation in such cases – especially if little data

A good dependable baseline for text classification (but not the best)! Optimal if the Independence Assumptions hold:

– If assumed independence is correct, then it is the Bayes Optimal Classifier for problem

Very Fast: – Learning with one pass over the data; testing linear in the number of attributes,

and document collection size Low Storage requirements Handles Missing Values

Page 23: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

PANTEL AND LIN: SPAMCOP

Uses a Naïve Bayes classifier M is spam if P(Spam|M) > P(NonSpam|M) Method

– Tokenize message using Porter Stemmer– Estimate P(W|C) using m-estimate (a form of smoothing) – Remove words that do not satisfy certain conditions– Train: 160 spams, 466 non-spams– Test: 277 spams, 346 non-spams

Results: ERROR RATE of 4.33%– Worse results using trigrams

Page 24: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

OTHER CLASSIFICATION METHODS

K-NN DECISION TREES LOGISTIC REGRESSION SUPPORT VECTOR MACHINES

Page 25: TEXT CLASSIFICATION CC437 (Includes some original material by Chris Manning)

REFERENCES

Mosteller, F., & Wallace, D. L. (1984). Applied Bayesian and Classical Inference: the Case of the Federalist Papers (2nd ed.). New York: Springer-Verlag.

P. Pantel and D. Lin, 1998. “SPAMCOP: A Spam classification and organization program”, In Proc. Of the 1998 workshop on learning for text categorization, AAAI

Sebastiani, F., 2002, “Machine Learning in Automated Text Categorization”, ACM Computing Surveys, 34(1), 1-47