本文介绍了显示Stanford NER置信度分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Stanford NER CRFClassifier从新闻文章中提取命名实体,并且为了实现主动学习,我想知道每个标记实体的类的置信度得分是什么.

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.

显示示例:

这是我的代码,用于从文本中提取命名实体:

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 ?

推荐答案

我自己发现了它,在CRFClassifier的文档中是这样写的:

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

第一种方法没有用,因为它只打印我想要在控制台上显示的内容,但是我希望能够访问此数据,因此我已经阅读了该方法的编码方式并复制了如下所示的行为:

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

这篇关于显示Stanford NER置信度分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:06