Upload
butest
View
906
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Statistische Methoden in der ComputerlinguistikStatistical Methods in Computational Linguistics
7. Machine Learning
Jonas Kuhn
Universität Potsdam, 2007
Addition: Good-Turing Smoothing
Use discounted estimates (r*) only up to a threshold k For types that occurred more often than k, relative frequency
estimates are used (Jurafsky/Martin, p. 216) With threshold k:
Machine Learning Overview
Tom Mitchell (1997): Machine Learning, McGraw Hill.
Slides mainly based on slides by Joakim Nivre and Tom Mitchell
Machine Learning
Idea: Synthesize computer programs by learning from representative examples of input (and output) data.
Rationale:1. For many problems, there is no known
method for computing the desired output from a set of inputs.
2. For other problems, computation according to the known correct method may be too expensive.
Well-Posed Learning Problems
A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.
Examples:1. Learning to classify chemical compounds
2. Learning to drive an autonomous vehicle
3. Learning to play bridge
4. Learning to parse natural language sentences
Designing a Learning System
In designing a learning system, we have to deal with (at least) the following issues:
1. Training experience2. Target function3. Learned function4. Learning algorithm
Example: Consider the task T of parsing English sentences, using the performance measure P of labeled precision and recall in a given test corpus (gold standard).
Training Experience
Issues concerning the training experience:1. Direct or indirect evidence (supervised or
unsupervised).2. Controlled or uncontrolled sequence of training
examples.3. Representativity of training data in relation to test
data. Training data for a syntactic parser:
1. Treebank versus raw text corpus.2. Constructed test suite versus random sample.3. Training and test data from the same/similar/different
sources with the same/similar/different annotations.
Target Function and Learned Function
The problem of improving performance can often be reduced to the problem of learning some particular target function. A shift-reduce parser can be trained by learning a
transition function f : C C, where C is the set of possible parser configurations.
In many cases we can only hope to acquire some approximation to the ideal target function. The transition function f can be approximated by a
function : Action from stack (top) symbols to parse actions.
f̂
Learning Algorithm
In order to learn the (approximated) target function we require:1. A set of training examples (input arguments)
2. A rule for estimating the value corresponding to each training example (if this is not directly available)
3. An algorithm for choosing the function that best fits the training data
Given a treebank on which we can simulate the shift-reduce parser, we may decide to choose the function that maps each stack symbol to the action that occurs most frequently when is on top of the stack.
Supervised Learning
Let X and Y be the set of possible inputs and outputs, respectively.1. Target function: Function f from X to Y.
2. Training data: Finite sequence D of pairs <x, f(x)> (x X).
3. Hypothesis space: Subset H of functions from X to Y.
4. Learning algorithm: Function A mapping a training set D to a hypothesis h H.
If Y is a subset of the real numbers, we have a regression problem; otherwise we have a classification problem.
Variations of Machine Learning
Unsupervised learning: Learning without output values (data exploration, e.g. clustering).
Query learning: Learning where the learner can query the environment about the output associated with a particular input.
Reinforcement learning: Learning where the learner has a range of actions which it can take to attempt to move towards states where it can expect high rewards.
Batch vs. online learning: All training examples at once or one at a time (with estimate and update after each example).
Learning and Generalization
Any hypothesis that correctly classifies all the training examples is said to be consistent. However:1. The training data may be noisy so that there is no
consistent hypothesis at all.2. The real target function may be outside the hypothesis
space and has to be approximated.3. A rote learner, which simply outputs y for every x such
that <x, y> D is consistent but fails to classify any x not in D.
A better criterion of success is generalization, the ability to correctly classify instances not represented in the training data.
Approaches to Machine Learning
Decision trees Artificial neural networks Bayesian learning Instance-based learning (cf. Memory-based
learning/MBL) Genetic algorithms Relational learning (cf. Inductive logical
programming/ILP)
First focus:Naïve Bayes
classifier
Decision Tree Example: Name Recognition
Capitalized?
Sentence-Inital?
Yes No
No
0
0
1
1
Decision Tree Example: Name Recognition
Bayesian Learning
Two reasons for studying Bayesian learning methods:1. Efficient learning algorithms for certain kinds of
problems2. Analysis framework for other kinds of learning
algorithms Features of Bayesian learning methods:
1. Assign probabilities to hypotheses (not accept or reject)
2. Combine prior knowledge with observed data3. Permit hypotheses that make probabilistic predictions4. Permit predictions based on multiple hypotheses,
weighted by their probabilities
Towards Naive Bayes Classification
Let H be a hypothesis space defined over the instance space X, where the task is to learn a target function f : X Y, where Y is a finite set of classes used to classify instances in X, and where a1, …, an are the attributes used to represent an instance x X.
Bayes’ Theorem
Maximize numerator for finding most probable y with a given x (and its attribute representation a1, …, an
Numerator is equivalent to joint probability
),...,,(
)()|,...,,(),...,,|(
21
2121
n
nn aaaP
yPyaaaPaaayP
),...,,,( 21 naaayP
Towards Naive Bayes Classification
Reformulate numerator (using chain rule)
(Naïve) conditional independence assumption: For any attributes ai, aj (ij):
Hence:
),...,,|(...),|()|()(
...
),,|,...,(),|()|()(
),|,...,()|()(
)|,...,,()(),...,,,(
11121
213121
121
2121
nn
n
n
nn
aayaPayaPyaPyP
aayaaPayaPyaPyP
ayaaPyaPyP
yaaaPyPaaayP
)|(),|( yaPayaP iji
)|(...)|()|()(),...,,,( 2121 yaPyaPyaPyPaaayP nn
Naive Bayes Classifier
The naive Bayes classification of a new instance is:
i
iYy yaPyP )|()(maxarg
Learning a Naive Bayes Classifier
Estimate probabilities from training data using ML estimation:
Smoothe probability estimates to compensate for sparse data, e.g. using an m-estimate:
where m is a constant called the equivalent sample size and p is a prior probability (usually assumed to be uniform).
|})(|{|
},)(|{)|(
||
})(|{)(
yxfDx
xayxfDxyaP
D
yxfDxyP
iiML
ML
myxfDx
mpxayxfDxyaP
mD
mpyxfDxyP
iiML
ML
|})(|{|
},)(|{)|(ˆ
||
})(|{)(ˆ
Naive Bayes
Naive Bayes classifiers work surprisingly well for text classification tasks
Decision Tree Learning
Decision trees classify instances by sorting them down the tree from the root to some leaf node, where:1. Each internal node specifies a test of some attribute.2. Each branch corresponds to a value for the tested
attribute.3. Each leaf node provides a classification for the
instance. Decision trees represent a disjunction of conjunctions
of constraints on the attribute values of instances.1. Each path from root to leaf specifies a conjunction of
tests.2. The tree itself represents the disjunction of all paths.
Example: Name Recognition
Capitalized?
Sentence-Inital?
Yes No
No
0
0
1
1
PlayTennis example
Appropriate Problems for Decision Tree Learning Instances are represented by attribute-value
pairs. The target function has discrete output
values. Disjunctive descriptions may be required. The training data may contain errors. The training data may contain missing
attribute values.
The ID3 Learning Algorithm
ID3(X = instances, Y = classes, A = attributes):1. Create a root node R for the tree.
2. If all instances in X are in class y, return R with label y.
3. Else let the decision attribute for R be the attribute a A that best classifies X and for each value vi of a:
(a) Add a branch below R for the test a = vi.
(b) Let Xi be the subset of X that have a = vi. If Xi is empty then add a leaf labeled with the most common class in X; else add the subtree ID3(Xi, Y, A − a).
4. Return R.
Selecting the Best Attribute
ID3 uses the measure Information Gain (IG) to decide which attribute a best classifies a set of examples X:
where Va is the set of possible values for a, Xv is the subset of X for which a = v, and Entropy(X) is defined as follows:
An alternative measure is Gain Ratio (GR):
)()(),( VVv
V XEntropyX
XXEntropyaXIG
a
)(log)()( 2 yPyPYEntropyYy
)(
),(),(
aVEntropy
aXIGaXGR
Information Gain
Training examples
Selecting the next attribute
Hypothesis Space Search and Inductive Bias Characteristics of ID3:
1. Searches a complete hypothesis space of target functions2. Maintains a single current hypothesis throughout the search3. Performs a hill-climbing search (susceptible to local
minima)4. Uses all training examples at each step in the search
Inductive bias:1. Prefers shorter trees over longer ones2. Prefers trees with informative attributes close to the root3. Preference bias (incomplete search of complete space)
Overfitting
The problem of overfitting: A hypothesis h is overfitted to the training data if there
exists an alternative hypothesis h’ with higher training error but lower test error.
Two approaches for avoiding overfitting in decision tree learning:1. Stop growing the tree before it overfits the training
data.
2. Allow overfitting and then post-prune the tree. Both methods require a stopping criterion and can
be validated using held-out data.