Transcript TEXT CLASSIFICATION
TEXT CLASSIFICATION
CC437 (Includes some original material by Chris Manning)
CATEGORIZATION / CLASSIFICATION
Given: – A description of an instance,
x
X
, where X is the
instance language
or
instance space
.
– E.g: how to represent text documents.
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
whose range is
C
.
and
A GRAPHICAL VIEW OF TEXT CLASSIFICATION
Graphics Arch.
Theory NLP AI
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!!
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
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
)
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
Bayesian Methods
Learning and classification methods based on probability theory (see spelling / POS) Bayes theorem plays a critical role Build a
generative model
how data is produced that approximates 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.
Bayes’ Rule
P
(
C
,
X
)
P
(
C
|
X
)
P
(
X
)
P
(
X
|
C
)
P
(
C
)
P
(
C
|
X
)
P
(
X
|
C
)
P
(
C
)
P
(
X
)
Maximum a posteriori Hypothesis
h MAP
argmax
h
H P
(
h
|
D
)
h MAP
argmax
h
H P
(
D
|
h
)
P
(
h
)
P
(
D
)
h MAP
argmax
h
H P
(
D
|
h
)
P
(
h
)
Maximum likelihood Hypothesis
If all hypotheses are a priori equally likely, we only need to consider the
P
(
D|h
) term:
h ML
argmax
h
H P
(
D
|
h
)
Naive Bayes Classifiers
Task: Classify a new instance based on a tuple of attribute values
x
1 ,
x
2 , ,
x n c MAP
argmax
c
C j P
(
c j
|
x
1 ,
x
2 , ,
x n
)
c MAP
argmax
c
C j P
(
x
1 ,
x
2 , ,
x n
|
c j
)
P
(
c j
)
P
(
c
1 ,
c
2 , ,
c n
)
c MAP
argmax
c
C j P
(
x
1 ,
x
2 , ,
x n
|
c j
)
P
(
c j
)
Naïve Bayes Classifier: Assumptions
P
(
c j
) – Can be estimated from the frequency of classes in the training examples.
P
(
x 1 ,x 2 ,…,x n |c j
) – 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.
The Naïve Bayes Classifier
Flu X 1
runnynose
X 2
sinus
X 3
cough
X 4
fever
X 5
muscle-ache
Conditional Independence Assumption:
features are independent of each other given the class:
P
(
X
1 , ,
X
5 |
C
)
P
(
X
1 |
C
)
P
(
X
2 |
C
)
P
(
X
5 |
C
)
Learning the Model
C
X 1 X 2 X 3 X 4 X 5 X 6
Common practice:maximum likelihood – simply use the frequencies in the data ˆ (
c j N N
c j
) ( , ) (
x i
|
c j
)
N X N i
(
C x i
C c j
)
c j
Using Naive Bayes Classifiers to Classify Text: Basic method
Attributes are text positions, values are words.
c NB
argmax
c
j
C
argmax
c
j
C P
(
c j
)
i P
(
x i P
(
c j
)
P
(
x
1 |
c j
) " our" |
c j
)
P
(
x n
" text" |
c j
) Still too many possibilities Assume that classification is
independent
of the positions of the words – Use same parameters for each position
Text Classification Algorithms: Learning
From training corpus, extract
Vocabulary
Calculate required
P
(
c j
) – and
P
(
x k | c j
) terms For each
c j
in
C
docs c j j
do subset of documents for which the target class is | |
P
(
c
)
docs j
j
| total # documents |
Text j
single document containing all
docs j
for each word
x k
–
n k
in
Vocabulary
number of occurrences of
x k
in
Text j
–
P
(
x k
|
c j
)
n k
1
n
|
Vocabulary
|
Text Classification Algorithms: Classifying
positions all word positions in current document which contain tokens found in
Vocabulary
Return
c NB
, where
c NB
argmax
c
j
C P
(
c j
)
P
(
i
positions x i
|
c j
)
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.
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:
I
(
w
,
c
)
e w
{ { 0 , 1 }
e c
0 , 1 }
p
(
e w
,
e c p
( ) log
p
(
e w e w
) ,
e c p
(
e
)
c
) – For each word
w
and each category
c
OTHER APPROACHES TO FEATURE SELECTION
T-TEST CHI SQUARE TF/IDF (CFR. IR lectures) Yang & Pedersen 1997: eliminating features leads to improved performance
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 Features Irrelevant Features cancel each other without affecting results Instead Decision Trees & Nearest-Neighbor methods can heavily suffer from this.
Very good in Domains with many equally important features Decision 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
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
OTHER CLASSIFICATION METHODS
K-NN DECISION TREES LOGISTIC REGRESSION SUPPORT VECTOR MACHINES
REFERENCES
Mosteller, F., & Wallace, D. L. (1984).
Federalist Papers Applied Bayesian and Classical Inference: the Case of the
(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