|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.classify.TrainableClassifier
de.fu_berlin.ties.classify.TieClassifier
public class TieClassifier
A tie classifier combines several layers of classifiers. If the probabilities of the two best predictions of a layer are close to each other, the next layer is invoked to resolve this "tie".
This classifier supports only error-driven training since it
necessary to TOE train each classifier to decide whether to train the next
one. Thus you always have to use the
TrainableClassifier.trainOnError(FeatureVector, String, Set)
method. Trying to
call the TrainableClassifier.train(FeatureVector, String)
method instead will result in an
UnsupportedOperationException
.
Instances of this class are thread-safe if and only if instances of the wrapped classifier are.
Field Summary | |
---|---|
(package private) static QName |
ATTRIB_TIE_THRESHOLD
Attribute name used for XML serialization. |
Fields inherited from class de.fu_berlin.ties.classify.TrainableClassifier |
---|
ATTRIB_CLASSES, ATTRIB_TRAIN_ALL, ELEMENT_MAIN, META_CLASSIFIER, MULTI_CLASSIFIER, OAR_CLASSIFIER, TIE_CLASSIFIER |
Fields inherited from interface de.fu_berlin.ties.classify.Classifier |
---|
CONFIG_CLASSIFIER |
Constructor Summary | |
---|---|
TieClassifier(Element element)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface. |
|
TieClassifier(Set<String> allValidClasses,
FeatureTransformer trans,
File runDirectory,
String[] innerSpec,
int layers,
double threshold,
TiesConfiguration conf)
Creates a new instance. |
|
TieClassifier(Set<String> allValidClasses,
FeatureTransformer trans,
File runDirectory,
String[] innerSpec,
TiesConfiguration conf)
Creates a new instance. |
Method Summary | |
---|---|
void |
destroy()
Destroys the classifer. |
protected PredictionDistribution |
doClassify(FeatureVector features,
Set candidateClasses,
ContextMap context)
Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes. |
protected void |
doTrain(FeatureVector features,
String targetClass,
ContextMap context)
This classifier supports only error-driven training, so you always have to use the TrainableClassifier.trainOnError(FeatureVector, String, Set)
method instead of this one. |
protected boolean |
doTrainOnError(PredictionDistribution predDist,
FeatureVector features,
String targetClass,
Set candidateClasses,
ContextMap context)
The core of the TrainableClassifier.trainOnError(FeatureVector, String, Set) method. |
void |
reset()
Resets the classifer, completely deleting the prediction model. |
protected boolean |
shouldTrain(String targetClass,
PredictionDistribution predDist,
ContextMap context)
Invoked by TrainableClassifier.trainOnError(FeatureVector, String, Set) to decide
whether to train an instance. |
ObjectElement |
toElement()
Stores all relevant fields of this object in an XML element for serialization. An equivalent object can be created by calling ObjectElement.createObject(org.dom4j.Element,
Class) on the created element.
Subclasses of TrainableClassifier should extend this method and
the corresponding constructor from Element to
ensure (de)serialization works as expected. |
String |
toString()
Returns a string representation of this object. |
protected boolean |
trainOnErrorHook(PredictionDistribution predDist,
FeatureVector features,
String targetClass,
Set candidateClasses,
ContextMap context)
Subclasses can implement this hook for more refined error-driven learning. |
Methods inherited from class de.fu_berlin.ties.classify.TrainableClassifier |
---|
classify, createClassifier, createClassifier, createClassifier, createClassifier, createClassifier, getAllClasses, getConfig, train, trainOnError |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final QName ATTRIB_TIE_THRESHOLD
Constructor Detail |
---|
public TieClassifier(Element element) throws InstantiationException
XMLStorable
interface.
element
- the XML element containing the serialized representation
InstantiationException
- if the given element does not contain
a valid classifier descriptionpublic TieClassifier(Set<String> allValidClasses, FeatureTransformer trans, File runDirectory, String[] innerSpec, TiesConfiguration conf) throws ProcessingException
allValidClasses
- the set of all valid classestrans
- the last transformer in the transformer chain to use, or
null
if no feature transformers should be usedrunDirectory
- optional run directory passed to inner classifiers
of the ExternalClassifier
typeinnerSpec
- the specification used to initialize the inner
classifiers, passed to the
TrainableClassifier.createClassifier(Set, File,
FeatureTransformer, String[], TiesConfiguration)
factory methodconf
- used to configure this instance and the inner classifiers
ProcessingException
- if an error occurred while creating this
classifier or one of the wrapped classifierspublic TieClassifier(Set<String> allValidClasses, FeatureTransformer trans, File runDirectory, String[] innerSpec, int layers, double threshold, TiesConfiguration conf) throws ProcessingException
allValidClasses
- the set of all valid classestrans
- the last transformer in the transformer chain to use, or
null
if no feature transformers should be usedrunDirectory
- optional run directory passed to inner classifiers
of the ExternalClassifier
typeinnerSpec
- the specification used to initialize the inner
classifiers, passed to the
TrainableClassifier.createClassifier(Set, File,
FeatureTransformer, String[], TiesConfiguration)
factory methodlayers
- the number of layers to use, must be at least 1threshold
- the next layer is invoked if the relative probability
of the second best prediction as above or equal to this threshold;
must be a number between 0 and 1conf
- used to configure this instance as well as the inner
classifiers
ProcessingException
- if an error occurred while creating this
classifier or one of the wrapped classifiersMethod Detail |
---|
public void destroy() throws ProcessingException
TrainableClassifier.reset()
, but subclasses can overwrite this behaviour if
appropriate.
destroy
in interface Classifier
destroy
in class TrainableClassifier
ProcessingException
- if an error occurs while the classifier is
being destroyedprotected PredictionDistribution doClassify(FeatureVector features, Set candidateClasses, ContextMap context) throws ProcessingException
doClassify
in class TrainableClassifier
features
- the feature vector to considercandidateClasses
- an set of classes that are allowed for this itemcontext
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
PredictionDistribution.best()
to get the most probably class
ProcessingException
- if an error occurs during classificationprotected void doTrain(FeatureVector features, String targetClass, ContextMap context) throws UnsupportedOperationException
TrainableClassifier.trainOnError(FeatureVector, String, Set)
method instead of this one. Trying to call this method instead will
result in anUnsupportedOperationException
.
doTrain
in class TrainableClassifier
features
- ignored by this methodtargetClass
- ignored by this methodcontext
- ignored by this method
UnsupportedOperationException
- always thrown by this method;
use TrainableClassifier.trainOnError(FeatureVector, String, Set)
insteadprotected boolean doTrainOnError(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses, ContextMap context) throws ProcessingException
TrainableClassifier.trainOnError(FeatureVector, String, Set)
method.
Generally there is no need for subclasses to modify this method.
doTrainOnError
in class TrainableClassifier
predDist
- the prediction distribution returned by
TrainableClassifier.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)context
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
TrainableClassifier.shouldTrain(String,
PredictionDistribution, ContextMap)
method
ProcessingException
- if an error occurs during trainingpublic void reset() throws ProcessingException
reset
in class TrainableClassifier
ProcessingException
- if an error occurs during resetprotected boolean shouldTrain(String targetClass, PredictionDistribution predDist, ContextMap context)
TrainableClassifier.trainOnError(FeatureVector, String, Set)
to decide
whether to train an instance. The default behavior is to train if the
best prediction was wrong or didn't yield a positive probability
("train only errors"). Subclasses can override this method to
add their own behavior, e.g. reinforcement training (thick threshold
heuristic).
shouldTrain
in class TrainableClassifier
targetClass
- the expected class of this feature vector; must be
contained in the set of candidateClasses
predDist
- the prediction distribution returned by
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
context
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
public ObjectElement toElement()
ObjectElement.createObject(org.dom4j.Element,
Class)
on the created element.
Subclasses of TrainableClassifier
should extend this method and
the corresponding constructor from Element
to
ensure (de)serialization works as expected.
toElement
in interface XMLStorable
toElement
in class TrainableClassifier
public String toString()
toString
in class TrainableClassifier
protected boolean trainOnErrorHook(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses, ContextMap context) throws ProcessingException
TrainableClassifier.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
.
trainOnErrorHook
in class TrainableClassifier
predDist
- the prediction distribution returned by
TrainableClassifier.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)context
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
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 |