显示Stanford NER置信度分数 [英] Display Stanford NER confidence score

查看:186
本文介绍了显示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.

显示示例:

位置(0.20)人(0.10)组织(0.60)其他(0.10)

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 ?

推荐答案

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

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

可以使用以下任一方法来查询CRF分配的概率: printProbsDocument()getCliqueTrees()方法.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆