|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.classify.TrainableClassifier
Classifiers extending this abstract class must provide a training mechanism
by implementing the doTrain(FeatureVector, String)
method. This
class supports error-driven learning ("train only errors") which often leads
to better prediction models than brute-force training.
The code in this class is thread-safe.
Field Summary |
Fields inherited from interface de.fu_berlin.ties.classify.Classifier |
CONFIG_CLASSIFIER |
Constructor Summary | |
TrainableClassifier(Set allValidClasses,
FeatureTransformer trans)
Creates a new instance. |
Method Summary | |
PredictionDistribution |
classify(FeatureVector features,
Set candidateClasses)
Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes. |
static TrainableClassifier |
createClassifier(Set allValidClasses)
Factory method that delegates to createClassifier(Set, TiesConfiguration) using the
standard configuration. |
static TrainableClassifier |
createClassifier(Set allValidClasses,
File runDirectory,
TiesConfiguration config)
Factory method that creates a trainable classifier based on the Classifier.CONFIG_CLASSIFIER key in the provided configuration.
|
static TrainableClassifier |
createClassifier(Set allValidClasses,
TiesConfiguration config)
Factory method that delegates to createClassifier(Set, File, TiesConfiguration) without
specifying an run directory. |
protected abstract PredictionDistribution |
doClassify(FeatureVector features,
Set candidateClasses)
Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes. |
protected abstract void |
doTrain(FeatureVector features,
String targetClass)
Incorporates an item that is represented by a feature vector into the classification model. |
Set |
getAllClasses()
Returns the set of all valid classes. |
String |
toString()
Returns a string representation of this object. |
void |
train(FeatureVector features,
String targetClass)
Incorporates an item that is represented by a feature vector into the classification model. |
PredictionDistribution |
trainOnError(FeatureVector features,
String targetClass,
Set candidateClasses)
Handles error-driven learning ("train only errors"): the specified feature vector is trained into the model only if the predicted class for the feature vector differs from the specified target class. |
protected boolean |
trainOnErrorHook(PredictionDistribution predDist,
FeatureVector features,
String targetClass,
Set candidateClasses)
Subclasses can implement this hook for more refined error-driven learning. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public TrainableClassifier(Set allValidClasses, FeatureTransformer trans)
allValidClasses
- the set of all valid classestrans
- the last transformer in the transformer chain to use, or
null
if no feature transformers should be usedMethod Detail |
public static TrainableClassifier createClassifier(Set allValidClasses) throws IllegalArgumentException, ProcessingException
createClassifier(Set, TiesConfiguration)
using the
standard configuration.
allValidClasses
- the set of all valid classes
IllegalArgumentException
- if the value of the
Classifier.CONFIG_CLASSIFIER
key is missing or invalid
ProcessingException
- if an error occurred while creating the
classifierpublic static TrainableClassifier createClassifier(Set allValidClasses, TiesConfiguration config) throws IllegalArgumentException, ProcessingException
createClassifier(Set, File, TiesConfiguration)
without
specifying an run directory.
allValidClasses
- the set of all valid classesconfig
- the configuration to use
IllegalArgumentException
- if the value of the
Classifier.CONFIG_CLASSIFIER
key is missing or invalid
ProcessingException
- if an error occurred while creating the
classifierpublic static TrainableClassifier createClassifier(Set allValidClasses, File runDirectory, TiesConfiguration config) throws IllegalArgumentException, ProcessingException
Classifier.CONFIG_CLASSIFIER
key in the provided configuration.
Currently supported values:
"Ext" for ExternalClassifier
,
"Winnow" for Winnow
,
"ucWinnow" for UltraconservativeWinnow
.
Otherwise the value must be the qualified name of a
TrainableClassifier subclass accepting a Set
(of all valid class
names) as first argument, a FeatureTransformer
as second argument
and a TiesConfiguration
as third argument.
allValidClasses
- the set of all valid classesrunDirectory
- the directory to run the classifier in; used for
ExternalClassifier
instead of the
configured directory
if not null
; ignored otherwiseconfig
- the configuration to use
IllegalArgumentException
- if the value of the
Classifier.CONFIG_CLASSIFIER
key is missing or invalid
ProcessingException
- if an error occurred while creating the
classifierpublic final PredictionDistribution classify(FeatureVector features, Set candidateClasses) throws IllegalArgumentException, ProcessingException
doClassify(FeatureVector, Set)
method.
classify
in interface Classifier
features
- the feature vector to considercandidateClasses
- an set of classes that are allowed for this item
PredictionDistribution.best()
to get the most probably class
IllegalArgumentException
- if the
set of valid classes does not contain all
candidate classes
ProcessingException
- if an error occurs during classificationprotected abstract PredictionDistribution doClassify(FeatureVector features, Set candidateClasses) throws ProcessingException
features
- the feature vector to considercandidateClasses
- an set of classes that are allowed for this item
PredictionDistribution.best()
to get the most probably class
ProcessingException
- if an error occurs during classificationprotected abstract void doTrain(FeatureVector features, String targetClass) throws ProcessingException
features
- the feature vector to considertargetClass
- the class of this feature vector
ProcessingException
- if an error occurs during trainingpublic Set getAllClasses()
public String toString()
public final void train(FeatureVector features, String targetClass) throws IllegalArgumentException, ProcessingException
doTrain(FeatureVector, String)
method.
features
- the feature vector to considertargetClass
- the class of this feature vector
IllegalArgumentException
- if the target class is not in the
set of valid classes
ProcessingException
- if an error occurs during trainingpublic final PredictionDistribution trainOnError(FeatureVector features, String targetClass, Set candidateClasses) throws ProcessingException
features
- the feature vector to considertargetClass
- the expected class of this feature vector; must be
contained in the set of candidateClasses
candidateClasses
- an set of classes that are allowed for this item
(the actual targetClass
must be one of them)
null
if no
training was necessary (the prediction was already correct)
ProcessingException
- if an error occurs during trainingprotected boolean trainOnErrorHook(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses) throws ProcessingException
trainOnError(FeatureVector, String, Set)
method after
classifying. This method can do any necessary training itself and
return true
to signal that no further action is necessary.
This implementation is just a placeholder that always returns
false
.
predDist
- the prediction distribution returned by
classify(FeatureVector, Set)
features
- the feature vector to considertargetClass
- the expected class of this feature vector; must be
contained in the set of candidateClasses
candidateClasses
- an set of classes that are allowed for this item
(the actual targetClass
must be one of them)
false
; subclasses
can return true
to signal that any error-driven learning was
already handled
ProcessingException
- if an error occurs during training
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |