gpt4 book ai didi

java - 显示斯坦福 NER 置信度分数

转载 作者:行者123 更新时间:2023-11-29 07:00:43 26 4
gpt4 key购买 nike

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

显示示例:

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

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

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

是否有解决方法来获取这些值以及注释?

最佳答案

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

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

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

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

关于java - 显示斯坦福 NER 置信度分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26612999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com