edu.stanford.nlp.ie.crf
Class CRFBiasedClassifier<IN extends CoreMap>

java.lang.Object
  extended by edu.stanford.nlp.ie.AbstractSequenceClassifier<IN>
      extended by edu.stanford.nlp.ie.crf.CRFClassifier<IN>
          extended by edu.stanford.nlp.ie.crf.CRFBiasedClassifier<IN>
All Implemented Interfaces:
Function<String,String>

public class CRFBiasedClassifier<IN extends CoreMap>
extends CRFClassifier<IN>

CRFBiasedClassifier is used to adjust the precision-recall tradeoff of any CRF model implemented using CRFClassifier. This adjustment is performed after CRF training. The method is described in (Minkov, Wang, Tomasic, and Cohen, 2006): "NER Systems that Suit User's Preferences: Adjusting the Recall-Precision Trade-off for Entity Extraction". CRFBiasedClassifier can import any model serialized with CRFClassifier and supports most command-line parameters available in CRFClassifier. In addition to this, CRFBiasedClassifier also interprets the parameter -classBias, as in:

java -server -mx500m edu.stanford.nlp.ie.crf.CRFBiasedClassifier -loadClassifier model.gz -testFile test.txt -classBias A:0.5,B:1.5

The command above sets a bias of 0.5 towards class A and a bias of 1.5 towards class B. These biases (which internally are treated as feature weights in the log-linear model underpinning the CRF classifier) can take any real value. As the weight of A tends to plus infinity, the classifier will only predict A labels, and as it tends towards minus infinity, it will never predict A labels.

Author:
Michel Galley, Sonal Gupta (made the class generic)

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.stanford.nlp.ie.crf.CRFClassifier
CRFClassifier.TestSequenceModel
 
Field Summary
 
Fields inherited from class edu.stanford.nlp.ie.crf.CRFClassifier
DEFAULT_CLASSIFIER
 
Fields inherited from class edu.stanford.nlp.ie.AbstractSequenceClassifier
classIndex, featureFactory, flags, knownLCWords, pad, windowSize
 
Constructor Summary
CRFBiasedClassifier(Properties props)
           
 
Method Summary
 void adjustBias(List<List<IN>> develData, Function<Double,Double> evalFunction, double low, double high)
           
 List<IN> classify(List<IN> document)
          Classify a List of something that extendsCoreMap.
static void main(String[] args)
          The main method, which is essentially the same as in CRFClassifier.
 CRFDatum<List<String>,CRFLabel> makeDatum(List<IN> info, int loc, FeatureFactory<IN> featureFactory)
          Makes a CRFDatum by producing features and a label from input data at a specific position, using the provided factory.
 void setBiasWeight(int cindex, double weight)
           
 void setBiasWeight(String cname, double weight)
           
 
Methods inherited from class edu.stanford.nlp.ie.crf.CRFClassifier
addProcessedData, allLabels, classifyAndWriteAnswers, classifyGibbs, classifyGibbs, classifyGibbsUsingPrior, classifyGibbsUsingPrior, classifyMaxEnt, classifyWithGlobalInformation, combine, documentsToDataAndLabels, documentsToDataAndLabelsList, documentToDataAndLabels, dropFeaturesBelowThreshold, extractDatumSequence, getClassifier, getClassifier, getClassifier, getClassifier, getClassifierNoExceptions, getCliqueTrees, getDefaultClassifier, getDefaultClassifier, getJarClassifier, getMinimizer, getMinimizer, getNumWeights, getSequenceModel, getSequenceModel, loadClassifier, loadDefaultClassifier, loadDefaultClassifier, loadProcessedData, loadTextClassifier, makeAnswerArraysAndTagIndex, printFirstOrderProbs, printFirstOrderProbsDocument, printFirstOrderProbsDocuments, printLabelInformation, printLabelValue, printProbsDocument, saveProcessedData, scaleWeights, serializeClassifier, serializeTextClassifier, train
 
Methods inherited from class edu.stanford.nlp.ie.AbstractSequenceClassifier
apply, backgroundSymbol, classify, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswersKBest, classifyAndWriteViterbiSearchGraph, classifyFile, classifyKBest, classifyRaw, classifySentence, classifySentenceWithGlobalInformation, classifyToCharacterOffsets, classifyToString, classifyToString, classifyWithInlineXML, countResults, getSampler, getViterbiSearchGraph, labels, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadJarClassifier, makeObjectBankFromFile, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromReader, makeObjectBankFromString, makeReaderAndWriter, printFeatureLists, printFeatures, printProbs, printProbsDocuments, printResults, reinit, segmentString, segmentString, train, train, train, train, train, train, writeAnswers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CRFBiasedClassifier

public CRFBiasedClassifier(Properties props)
Method Detail

makeDatum

public CRFDatum<List<String>,CRFLabel> makeDatum(List<IN> info,
                                                 int loc,
                                                 FeatureFactory<IN> featureFactory)
Description copied from class: CRFClassifier
Makes a CRFDatum by producing features and a label from input data at a specific position, using the provided factory.

Overrides:
makeDatum in class CRFClassifier<IN extends CoreMap>
Parameters:
info - The input data
loc - The position to build a datum at
featureFactory - The FeatureFactory to use to extract features
Returns:
The constructed CRFDatum

setBiasWeight

public void setBiasWeight(String cname,
                          double weight)

setBiasWeight

public void setBiasWeight(int cindex,
                          double weight)

classify

public List<IN> classify(List<IN> document)
Description copied from class: AbstractSequenceClassifier
Classify a List of something that extendsCoreMap. The classifications are added in place to the items of the document, which is also returned by this method

Overrides:
classify in class CRFClassifier<IN extends CoreMap>
Parameters:
document - A List of something that extends CoreMap.
Returns:
The same List, but with the elements annotated with their answers (stored under the CoreAnnotations.AnswerAnnotation key).

adjustBias

public void adjustBias(List<List<IN>> develData,
                       Function<Double,Double> evalFunction,
                       double low,
                       double high)

main

public static void main(String[] args)
                 throws Exception
The main method, which is essentially the same as in CRFClassifier. See the class documentation.

Throws:
Exception


Stanford NLP Group