edu.stanford.nlp.ie.crf
Class CRFBiasedClassifier<IN extends CoreMap>
java.lang.Object
edu.stanford.nlp.ie.AbstractSequenceClassifier<IN>
edu.stanford.nlp.ie.crf.CRFClassifier<IN>
edu.stanford.nlp.ie.crf.CRFBiasedClassifier<IN>
- All Implemented Interfaces:
- Function<java.lang.String,java.lang.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)
Method Summary |
void |
adjustBias(java.util.List<java.util.List<IN>> develData,
Function<java.lang.Double,java.lang.Double> evalFunction,
double low,
double high)
Adjust the bias parameter to optimize some objective function. |
java.util.List<IN> |
classify(java.util.List<IN> document)
Classify a List of something that extendsCoreMap . |
static void |
main(java.lang.String[] args)
The main method, which is essentially the same as in CRFClassifier. |
CRFDatum<java.util.List<java.lang.String>,CRFLabel> |
makeDatum(java.util.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(java.lang.String cname,
double weight)
|
Methods inherited from class edu.stanford.nlp.ie.crf.CRFClassifier |
addProcessedData, allLabels, classifyGibbs, classifyGibbs, classifyGibbsUsingPrior, classifyGibbsUsingPrior, classifyMaxEnt, classifyWithGlobalInformation, combine, createPartialDataForLOP, documentsToDataAndLabels, documentsToDataAndLabelsList, documentToDataAndLabels, documentToDataAndLabels, dropFeaturesBelowThreshold, extractDatumSequence, getClassifier, getClassifier, getClassifier, getClassifier, getClassifierNoExceptions, getCliqueTree, getCliqueTree, getCliqueTrees, getDefaultClassifier, getDefaultClassifier, getFeatureBoundaryIndices, getJarClassifier, getMinimizer, getMinimizer, getNumWeights, getSequenceModel, getSequenceModel, initWeightsUsingDoubleCRF, loadClassifier, loadDefaultClassifier, loadDefaultClassifier, loadProcessedData, loadTagIndex, loadTextClassifier, makeAnswerArraysAndTagIndex, printFeatures, printFirstOrderProbs, printFirstOrderProbsDocument, printFirstOrderProbsDocuments, printLabelInformation, printLabelValue, printProbsDocument, pruneNodeFeatureIndices, saveProcessedData, scaleWeights, serializeClassifier, serializeTextClassifier, topWeights, train, trainWeightsUsingDoubleCRF, trainWeightsUsingFloatCRF, trainWeightsUsingLopCRF, trainWeightsUsingNonLinearCRF, updateWeights, writeWeights |
Methods inherited from class edu.stanford.nlp.ie.AbstractSequenceClassifier |
apply, backgroundSymbol, classify, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswers, classifyAndWriteAnswersKBest, classifyAndWriteAnswersKBest, classifyAndWriteViterbiSearchGraph, classifyFile, classifyKBest, classifyRaw, classifySentence, classifySentenceWithGlobalInformation, classifyStdin, classifyStdin, classifyToCharacterOffsets, classifyToString, classifyToString, classifyWithInlineXML, countResults, countResults, countResultsIOB, countResultsIOB2, defaultReaderAndWriter, getSampler, getViterbiSearchGraph, labels, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifier, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadClassifierNoExceptions, loadJarClassifier, makeObjectBankFromFile, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromFiles, makeObjectBankFromReader, makeObjectBankFromString, makePlainTextReaderAndWriter, makeReaderAndWriter, plainTextReaderAndWriter, printFeatureLists, printFeatures, printProbs, printProbsDocuments, printResults, reinit, segmentString, segmentString, tallyOneEntityIOB, train, train, train, train, train, train, windowSize, writeAnswers |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CRFBiasedClassifier
public CRFBiasedClassifier(java.util.Properties props)
makeDatum
public CRFDatum<java.util.List<java.lang.String>,CRFLabel> makeDatum(java.util.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 dataloc
- The position to build a datum atfeatureFactory
- The FeatureFactory to use to extract features
- Returns:
- The constructed CRFDatum
setBiasWeight
public void setBiasWeight(java.lang.String cname,
double weight)
setBiasWeight
public void setBiasWeight(int cindex,
double weight)
classify
public java.util.List<IN> classify(java.util.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(java.util.List<java.util.List<IN>> develData,
Function<java.lang.Double,java.lang.Double> evalFunction,
double low,
double high)
- Adjust the bias parameter to optimize some objective function.
Note that this function only tunes the bias parameter of one class
(class of index 0), and is thus only useful for binary classification
problems.
main
public static void main(java.lang.String[] args)
throws java.lang.Exception
- The main method, which is essentially the same as in CRFClassifier. See the class documentation.
- Throws:
java.lang.Exception
Stanford NLP Group