Display Stanford NER confidence score

2019-02-16 02:09发布

I'm extracting named-entities from news articles with the use of Stanford NER CRFClassifier and in order to implement active learning, I would like to know what are the confidence scores of the classes for each labelled entity.

Exemple of display :

LOCATION(0.20) PERSON(0.10) ORGANIZATION(0.60) MISC(0.10)

Here is my code for extracting named-entities from a text :

AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifierNoExceptions(classifier_path);
String annnotatedText = classifier.classifyWithInlineXML(text);

Is there a workaround to get thoses values along with the annotations ?

1条回答
贼婆χ
2楼-- · 2019-02-16 03:07

I've found it out by myself, in CRFClassifier's doc it is written :

Probabilities assigned by the CRF can be interrogated using either the printProbsDocument() or getCliqueTrees() methods.

The first method is not useful since it only prints what I want on the console, but I want to be able to access this data, so I have read how this method is coded and copied a bit its behaviour like this :

List<CoreLabel> classifiedLabels = classifier.classify(sentences);
CRFCliqueTree<String> cliqueTree = classifier.getCliqueTree(classifiedLabels);

for (int i = 0; i < cliqueTree.length(); i++) {
    CoreLabel wi = classifiedLabels.get(i);
    for (Iterator<String> iter = classifier.classIndex.iterator(); iter.hasNext();) {
        String label = iter.next();
        int index = classifier.classIndex.indexOf(label);
        double prob = cliqueTree.prob(i, index);
        System.out.println("\t" + label + "(" + prob + ")");
    }
    String tag = StringUtils.getNotNullString(wi.get(CoreAnnotations.AnswerAnnotation.class));
    System.out.println("Class : " + tag);
}   
查看更多
登录 后发表回答