Class BasicRelationExtractor
- java.lang.Object
-
- edu.stanford.nlp.ie.machinereading.BasicRelationExtractor
-
- All Implemented Interfaces:
Extractor,Serializable
public class BasicRelationExtractor extends Object implements Extractor
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LinearClassifier<String,String>classifierprotected booleancreateUnrelatedRelationsIf true, it creates automatically negative examples by generating all combinations between EntityMentions in a sentence This is the common behavior, but for some domain (i.e., KBP) it must disabled.intfeatureCountThresholdRelationFeatureFactoryfeatureFactoryStringrelationExtractorClassifierTypewhich classifier to use (can be 'linear' or 'svm')protected RelationMentionFactoryrelationMentionFactorydoublesigmastrength of the prior on the linear classifier (passed to LinearClassifierFactory) or the C constant if relationExtractorClassifierType=svm
-
Constructor Summary
Constructors Constructor Description BasicRelationExtractor(RelationFeatureFactory featureFac, Boolean createUnrelatedRelations, RelationMentionFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidannotate(Annotation dataset)Annotates the given dataset with the current model This works in place, i.e., it adds ExtractionObject objects to the sentences in the dataset To make sure you are not messing with gold annotation create a copy of the ExtractionDataSet first!List<String>annotateMulticlass(List<Datum<String,String>> testDatums)voidannotateSentence(CoreMap sentence)protected StringclassOf(Datum<String,String> datum, ExtractionObject rel)protected GeneralDataset<String,String>createDataset(Annotation corpus)protected Datum<String,String>createDatum(RelationMention rel)protected Datum<String,String>createDatum(RelationMention rel, String label)protected List<RelationMention>extractAllRelations(CoreMap sentence)Predict a relation for each pair of entities in the sentence; including relations of type unrelated.protected voidjustificationOf(Datum<String,String> testDatum, PrintWriter pw, String label)static BasicRelationExtractorload(String modelPath)protected Counter<String>probabilityOf(Datum<String,String> testDatum)protected static voidreportWeights(LinearClassifier<String,String> classifier, String classLabel)voidsave(String modelpath)Serializes this extractor to a filevoidsetCreateUnrelatedRelations(boolean b)voidsetFeatureCountThreshold(int i)voidsetLoggerLevel(Level level)voidsetRelationExtractorClassifierType(String s)voidsetSigma(double d)voidsetValidator(LabelValidator lv)voidtrain(Annotation sentences)Train on a list of ExtractionSentence containing labeled RelationMention objectsvoidtrainMulticlass(GeneralDataset<String,String> trainSet)
-
-
-
Field Detail
-
classifier
protected LinearClassifier<String,String> classifier
-
featureCountThreshold
@Option(name="featureCountThreshold", gloss="feature count threshold to apply to dataset") public int featureCountThreshold
-
featureFactory
@Option(name="featureFactory", gloss="Feature factory for the relation extractor") public RelationFeatureFactory featureFactory
-
sigma
@Option(name="sigma", gloss="strength of the prior on the linear classifier (passed to LinearClassifierFactory) or the C constant if relationExtractorClassifierType=svm") public double sigma
strength of the prior on the linear classifier (passed to LinearClassifierFactory) or the C constant if relationExtractorClassifierType=svm
-
relationExtractorClassifierType
public String relationExtractorClassifierType
which classifier to use (can be 'linear' or 'svm')
-
createUnrelatedRelations
protected boolean createUnrelatedRelations
If true, it creates automatically negative examples by generating all combinations between EntityMentions in a sentence This is the common behavior, but for some domain (i.e., KBP) it must disabled. In these domains, the negative relation examples are created in the reader
-
relationMentionFactory
protected RelationMentionFactory relationMentionFactory
-
-
Constructor Detail
-
BasicRelationExtractor
public BasicRelationExtractor(RelationFeatureFactory featureFac, Boolean createUnrelatedRelations, RelationMentionFactory factory)
-
-
Method Detail
-
setValidator
public void setValidator(LabelValidator lv)
-
setRelationExtractorClassifierType
public void setRelationExtractorClassifierType(String s)
-
setFeatureCountThreshold
public void setFeatureCountThreshold(int i)
-
setSigma
public void setSigma(double d)
-
setCreateUnrelatedRelations
public void setCreateUnrelatedRelations(boolean b)
-
load
public static BasicRelationExtractor load(String modelPath) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
save
public void save(String modelpath) throws IOException
Description copied from interface:ExtractorSerializes this extractor to a file- Specified by:
savein interfaceExtractor- Parameters:
modelpath- where to save the extractor- Throws:
IOException
-
train
public void train(Annotation sentences)
Train on a list of ExtractionSentence containing labeled RelationMention objects
-
trainMulticlass
public void trainMulticlass(GeneralDataset<String,String> trainSet)
-
reportWeights
protected static void reportWeights(LinearClassifier<String,String> classifier, String classLabel)
-
classOf
protected String classOf(Datum<String,String> datum, ExtractionObject rel)
-
justificationOf
protected void justificationOf(Datum<String,String> testDatum, PrintWriter pw, String label)
-
extractAllRelations
protected List<RelationMention> extractAllRelations(CoreMap sentence)
Predict a relation for each pair of entities in the sentence; including relations of type unrelated. This creates new RelationMention objects!
-
annotateSentence
public void annotateSentence(CoreMap sentence)
-
annotate
public void annotate(Annotation dataset)
Description copied from interface:ExtractorAnnotates the given dataset with the current model This works in place, i.e., it adds ExtractionObject objects to the sentences in the dataset To make sure you are not messing with gold annotation create a copy of the ExtractionDataSet first!
-
createDataset
protected GeneralDataset<String,String> createDataset(Annotation corpus)
-
createDatum
protected Datum<String,String> createDatum(RelationMention rel)
-
createDatum
protected Datum<String,String> createDatum(RelationMention rel, String label)
-
setLoggerLevel
public void setLoggerLevel(Level level)
- Specified by:
setLoggerLevelin interfaceExtractor
-
-