Package edu.stanford.nlp.ie
Class ClassifierCombiner<IN extends CoreMap & HasWord>
- java.lang.Object
-
- edu.stanford.nlp.ie.AbstractSequenceClassifier<IN>
-
- edu.stanford.nlp.ie.ClassifierCombiner<IN>
-
- Direct Known Subclasses:
NERClassifierCombiner
public class ClassifierCombiner<IN extends CoreMap & HasWord> extends AbstractSequenceClassifier<IN>
Merges the outputs of two or more AbstractSequenceClassifiers according to a simple precedence scheme: any given base classifier contributes only classifications of labels that do not exist in the base classifiers specified before, and that do not have any token overlap with labels assigned by higher priority classifiers.This is a pure AbstractSequenceClassifier, i.e., it sets the AnswerAnnotation label. If you work with NER classifiers, you should use NERClassifierCombiner. This class inherits from ClassifierCombiner, and takes care that all AnswerAnnotations are also copied to NERAnnotation.
You can specify up to 10 base classifiers using the -loadClassifier1 to -loadClassifier10 properties. We also maintain the older usage when only two base classifiers were accepted, specified using -loadClassifier and -loadAuxClassifier.
ms 2009: removed all NER functionality (see NERClassifierCombiner), changed code so it accepts an arbitrary number of base classifiers, removed dead code.
- Author:
- Chris Cox, Mihai Surdeanu
-
-
Field Summary
-
Fields inherited from class edu.stanford.nlp.ie.AbstractSequenceClassifier
classIndex, featureFactories, flags, knownLCWords, pad, windowSize
-
-
Constructor Summary
Constructors Constructor Description ClassifierCombiner(AbstractSequenceClassifier<IN>... classifiers)Combines a series of base classifiers.ClassifierCombiner(edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode combinationMode, String... loadPaths)Loads a series of base classifiers from the paths specified using the Properties specified.ClassifierCombiner(ObjectInputStream ois, Properties props)ClassifierCombiner(String... loadPaths)Loads a series of base classifiers from the paths specified.ClassifierCombiner(Properties p)ClassifierCombiner(Properties props, edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode combinationMode, String... loadPaths)Loads a series of base classifiers from the paths specified using the Properties specified.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<IN>classify(List<IN> tokens)Generates the AnswerAnnotation labels of the combined model for the given tokens, storing them in place in the tokens.List<IN>classifyWithGlobalInformation(List<IN> tokenSeq, CoreMap doc, CoreMap sent)static voidexamineCRF(ClassifierCombiner cc, String crfNameOrIndex, SeqClassifierFlags flags, String testFile, String testFiles, DocumentReaderAndWriter<CoreLabel> readerAndWriter)static edu.stanford.nlp.ie.ClassifierCombiner.CombinationModeextractCombinationMode(Properties p)Either finds COMBINATION_MODE_PROPERTY or returns a default value.static edu.stanford.nlp.ie.ClassifierCombiner.CombinationModeextractCombinationModeSafe(Properties p)Either finds COMBINATION_MODE_PROPERTY or returns a default value.static ClassifierCombinergetClassifier(ObjectInputStream ois, Properties props)static ClassifierCombinergetClassifier(String loadPath, Properties props)Set<String>labels()voidloadClassifier(ObjectInputStream in, Properties props)Load a classifier from the specified input stream.static <INN extends CoreMap & HasWord>
AbstractSequenceClassifier<INN>loadClassifierFromPath(Properties props, String path)static voidmain(String[] args)Some basic testing of the ClassifierCombiner.voidserializeClassifier(ObjectOutputStream oos)Serialize a sequence classifier to an object output streamvoidserializeClassifier(String serializePath)Serialize a sequence classifier to a file on the given path.static voidshowCCInfo(ClassifierCombiner cc)voidtrain(Collection<List<IN>> docs, DocumentReaderAndWriter<IN> readerAndWriter)Trains a classifier from a Collection of sequences.-
Methods inherited from class edu.stanford.nlp.ie.AbstractSequenceClassifier
apply, backgroundSymbol, classify, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswersKBest, classifyAndWriteAnswersKBest, classifyAndWriteViterbiSearchGraph, classifyFile, classifyFilesAndWriteAnswers, classifyFilesAndWriteAnswers, classifyKBest, classifyRaw, classifySentence, classifySentenceWithGlobalInformation, classifyStdin, classifyStdin, classifyToCharacterOffsets, classifyToString, classifyToString, classifyWithInlineXML, countResults, countResultsSegmenter, defaultReaderAndWriter, dumpFeatures, finalizeClassification, getKnownLCWords, getSampler, getSequenceModel, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, makeObjectBankFromFile, makeObjectBankFromFile, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromReader, makeObjectBankFromString, makePlainTextReaderAndWriter, makePlainTextReaderAndWriter, makeReaderAndWriter, plainTextReaderAndWriter, printFeatureLists, printFeatures, printProbs, printProbs, printProbsDocument, printProbsDocuments, printResults, reinit, segmentString, segmentString, train, train, train, train, train, train, windowSize, writeAnswers
-
-
-
-
Constructor Detail
-
ClassifierCombiner
public ClassifierCombiner(Properties p) throws IOException
- Parameters:
p- Properties File that specifiesloadClassifierandloadAuxClassifierproperties or, alternatively,loadClassifier[1-10]properties.- Throws:
FileNotFoundException- If classifier files not foundIOException
-
ClassifierCombiner
public ClassifierCombiner(Properties props, edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode combinationMode, String... loadPaths) throws IOException
Loads a series of base classifiers from the paths specified using the Properties specified.- Parameters:
props- Properties for the classifier to use (encodings, output format, etc.)combinationMode- How to handle multiple classifiers specifying the same entity typeloadPaths- Paths to the base classifiers- Throws:
IOException- If IO errors in loading classifier files
-
ClassifierCombiner
public ClassifierCombiner(edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode combinationMode, String... loadPaths) throws IOExceptionLoads a series of base classifiers from the paths specified using the Properties specified.- Parameters:
combinationMode- How to handle multiple classifiers specifying the same entity typeloadPaths- Paths to the base classifiers- Throws:
IOException- If IO errors in loading classifier files
-
ClassifierCombiner
public ClassifierCombiner(String... loadPaths) throws IOException
Loads a series of base classifiers from the paths specified.- Parameters:
loadPaths- Paths to the base classifiers- Throws:
FileNotFoundException- If classifier files not foundIOException
-
ClassifierCombiner
@SafeVarargs public ClassifierCombiner(AbstractSequenceClassifier<IN>... classifiers)
Combines a series of base classifiers.- Parameters:
classifiers- The base classifiers
-
ClassifierCombiner
public ClassifierCombiner(ObjectInputStream ois, Properties props) throws IOException, ClassNotFoundException, ClassCastException
-
-
Method Detail
-
extractCombinationMode
public static edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode extractCombinationMode(Properties p)
Either finds COMBINATION_MODE_PROPERTY or returns a default value.
-
extractCombinationModeSafe
public static edu.stanford.nlp.ie.ClassifierCombiner.CombinationMode extractCombinationModeSafe(Properties p)
Either finds COMBINATION_MODE_PROPERTY or returns a default value. If the value is not a legal value, a warning is printed.
-
loadClassifierFromPath
public static <INN extends CoreMap & HasWord> AbstractSequenceClassifier<INN> loadClassifierFromPath(Properties props, String path) throws IOException
- Throws:
IOException
-
labels
public Set<String> labels()
- Overrides:
labelsin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>
-
classify
public List<IN> classify(List<IN> tokens)
Generates the AnswerAnnotation labels of the combined model for the given tokens, storing them in place in the tokens.- Specified by:
classifyin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>- Parameters:
tokens- A List of IN- Returns:
- The passed in parameters, which will have the AnswerAnnotation field added/overwritten
-
train
public void train(Collection<List<IN>> docs, DocumentReaderAndWriter<IN> readerAndWriter)
Description copied from class:AbstractSequenceClassifierTrains a classifier from a Collection of sequences. Note that the Collection can be (and usually is) an ObjectBank.- Specified by:
trainin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>- Parameters:
docs- An ObjectBank or a collection of sequences of INreaderAndWriter- A DocumentReaderAndWriter to use when loading test files
-
serializeClassifier
public void serializeClassifier(String serializePath)
Description copied from class:AbstractSequenceClassifierSerialize a sequence classifier to a file on the given path.- Specified by:
serializeClassifierin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>- Parameters:
serializePath- The path/filename to write the classifier to.
-
serializeClassifier
public void serializeClassifier(ObjectOutputStream oos)
Description copied from class:AbstractSequenceClassifierSerialize a sequence classifier to an object output stream- Specified by:
serializeClassifierin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>
-
loadClassifier
public void loadClassifier(ObjectInputStream in, Properties props) throws IOException, ClassCastException, ClassNotFoundException
Description copied from class:AbstractSequenceClassifierLoad a classifier from the specified input stream. The classifier is reinitialized from the flags serialized in the classifier.- Specified by:
loadClassifierin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>- Parameters:
in- The InputStream to load the serialized classifier fromprops- This Properties object will be used to update the SeqClassifierFlags which are read from the serialized classifier- Throws:
IOException- If there are problems accessing the input streamClassCastException- If there are problems interpreting the serialized dataClassNotFoundException- If there are problems interpreting the serialized data
-
classifyWithGlobalInformation
public List<IN> classifyWithGlobalInformation(List<IN> tokenSeq, CoreMap doc, CoreMap sent)
Description copied from class:AbstractSequenceClassifierClassify aListof something that extendsCoreMapusing as additional information whatever is stored in the document and sentence. This is needed for SUTime (NumberSequenceClassifier), which requires the document date to resolve relative dates.- Specified by:
classifyWithGlobalInformationin classAbstractSequenceClassifier<IN extends CoreMap & HasWord>- Parameters:
tokenSeq- AListof something that extendsCoreMap- Returns:
- Classified version of the input tokenSequence
-
getClassifier
public static ClassifierCombiner getClassifier(String loadPath, Properties props) throws IOException, ClassNotFoundException, ClassCastException
-
getClassifier
public static ClassifierCombiner getClassifier(ObjectInputStream ois, Properties props) throws IOException, ClassCastException, ClassNotFoundException
-
examineCRF
public static void examineCRF(ClassifierCombiner cc, String crfNameOrIndex, SeqClassifierFlags flags, String testFile, String testFiles, DocumentReaderAndWriter<CoreLabel> readerAndWriter) throws Exception
- Throws:
Exception
-
showCCInfo
public static void showCCInfo(ClassifierCombiner cc)
-
-