|
||||||||||
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.ExternalClassifier
public class ExternalClassifier
A proxy that provides a trainable classifier by communicating with an external (non-Java) program. Program name and command line options of the external classifier can be configured.
Instances of this class are thread-safe if and only if several instances of the external classifier can reliably run in parallel.
Field Summary | |
---|---|
static String |
CONFIG_DIR
Configuration key: the directory to run the classifier in (optional, defaults to current working directory). |
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 | |
---|---|
ExternalClassifier(Set<String> allValidClasses)
Creates a new instance based on the standard configuration. |
|
ExternalClassifier(Set<String> allValidClasses,
FeatureTransformer trans,
File runDirectory,
TiesConfiguration config)
Creates a new instance based on the provided arguments. |
|
ExternalClassifier(Set<String> allValidClasses,
TiesConfiguration config)
Creates a new instance based on the provided configuration. |
Method Summary | |
---|---|
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)
Incorporates an item that is represented by a feature vector into the classification model. |
void |
reset()
Resets the classifer, completely deleting the prediction model. |
protected boolean |
shouldTrain(String targetClass,
PredictionDistribution predDist,
ContextMap context)
This implementation uses reinforcement training, if a thick threshold is configured. |
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. Currently, this classifier does not support XML
serialization, throwing an UnsupportedOperationException instead. |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class de.fu_berlin.ties.classify.TrainableClassifier |
---|
classify, createClassifier, createClassifier, createClassifier, createClassifier, createClassifier, destroy, doTrainOnError, getAllClasses, getConfig, train, trainOnError, trainOnErrorHook |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String CONFIG_DIR
Constructor Detail |
---|
public ExternalClassifier(Set<String> allValidClasses) throws ProcessingException
allValidClasses
- the set of all valid classes
ProcessingException
- if an I/O error occurs during initializationpublic ExternalClassifier(Set<String> allValidClasses, TiesConfiguration config) throws ProcessingException
allValidClasses
- the set of all valid classesconfig
- contains configuration properties
ProcessingException
- if an I/O error occurs during initializationpublic ExternalClassifier(Set<String> allValidClasses, FeatureTransformer trans, File runDirectory, TiesConfiguration config) 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
- the directory to run the classifier in; used instead
of the configured directory if not
null
config
- contains configuration properties
ProcessingException
- if an I/O error occurs during initializationMethod Detail |
---|
protected PredictionDistribution doClassify(FeatureVector features, Set candidateClasses, ContextMap context) throws ProcessingException
doClassify
in class TrainableClassifier
features
- the feature vector to considercandidateClasses
- an array of the classes that are allowed for
this itemcontext
- ignored by this implementation
PredictionDistribution.best()
to get the most probably class;
this classifier returns only the best prediction, so
PredictionDistribution.size()
will be 1
ProcessingException
- if an I/O error occurs during communication
with the external programprotected void doTrain(FeatureVector features, String targetClass, ContextMap context) throws ProcessingException
doTrain
in class TrainableClassifier
features
- the feature vector to considertargetClass
- the class of this feature vectorcontext
- 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
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() throws UnsupportedOperationException
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. Currently, this classifier does not support XML
serialization, throwing an UnsupportedOperationException
instead.
toElement
in interface XMLStorable
toElement
in class TrainableClassifier
UnsupportedOperationException
- always thrown by this
implementationpublic String toString()
toString
in class TrainableClassifier
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |