Display Stanford NER confidence score

↘锁芯ラ 提交于 2019-11-30 21:01:23

问题


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:


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);
}   


来源:https://stackoverflow.com/questions/26612999/display-stanford-ner-confidence-score

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!