gpt4 book ai didi

java - CRFClassifier 无法识别句子分割器选项

转载 作者:行者123 更新时间:2023-12-02 04:17:21 29 4
gpt4 key购买 nike

我正在使用 CoreNLP 来注释多行英文文本中的 NE。执行以下操作时:

Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner");
props.put("ssplit.newlineIsSentenceBreak", "always");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String contentStr = "John speaks with Martin\n\nJeremy talks to him too.";
Annotation document
= new Annotation(contentStr);
pipeline.annotate(document);
List<CoreMap> sents = document.get(SentencesAnnotation.class);
for (int i = 0; i < sents.size(); i++) {
System.out.println("sentence " + i + " "+ sents.get(i));
}

句子分割效果很好,可以识别两个句子。但是,当我使用 NER 分类时,如下所示:

CRFClassifier classifier = CRFClassifier.getClassifier("edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz", props);
String classifiedStr = classifier.classifyWithInlineXML(contentStr);

我收到以下错误消息:

Unknown property: |ssplit.newlineIsSentenceBreak|  Unknown property: |annotators|

并且分类器似乎将所有文本视为一个句子,导致错误识别实体“Martin Jeremy”而不是两个不同的实体。

知道出了什么问题吗?

最佳答案

CRFClassifier.getClassifier 所采用的属性与 StanfordCoreNLP 构造函数所采用的属性不同,这就是您收到选项未知错误的原因。

它将被设置,但不会在运行时使用。

来自here ,你会发现需要设置SeqClassifierFlags的属性。您需要设置tokenizerOptions,并将选项设置为“tokenizeNLs = true”,这会将新行视为标记。

底线,在获取分类器之前按如下方式设置属性。它不应该给您未知属性的错误,并且它应该按预期工作。

Properties props = new Properties();
props.put("tokenizerOptions", "tokenizeNLs=true");

CRFClassifier classifier = CRFClassifier.getClassifier("edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz", props);
String classifiedStr = classifier.classifyWithInlineXML(contentStr);

关于java - CRFClassifier 无法识别句子分割器选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33178029/

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