【问题标题】:Error while loading a tagger model (probably missing model file)加载标注器模型时出错(可能缺少模型文件)
【发布时间】:2018-01-30 13:24:40
【问题描述】:

我正在尝试实现以下代码:

import java.util.Properties;
import edu.stanford.nlp.coref.CorefCoreAnnotations;
import edu.stanford.nlp.coref.CorefCoreAnnotations;
import edu.stanford.nlp.coref.data.CorefChain;
import edu.stanford.nlp.coref.data.Mention;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;

public class CorefResolver {
  public static void main(String[] args) throws Exception {
  Annotation document = new Annotation("Barack Obama was born in Hawaii.  He is the president. Obama was elected in 2008.");
  Properties props = new Properties();
  props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,mention,coref");
  StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
  pipeline.annotate(document);
  System.out.println("---");
  System.out.println("coref chains");
  for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) {
  System.out.println("\t" + cc);
  }
  for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
  System.out.println("---");
  System.out.println("mentions");
  for (Mention m : sentence.get(CorefCoreAnnotations.CorefMentionsAnnotation.class)) {
    System.out.println("\t" + m);
    }
  }
 }
}

这是来自 stanford corenlp 的代码。我使用 eclipse 作为框架。下图显示了 eclipse 中的视图。

在运行代码时,我收到以下错误。我已经尝试包含模型标记器等。仍然显示相同的错误。

Adding annotator tokenize
No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator pos
Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing model file)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:245)
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:152)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:451)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:154)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:150)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:137)
at CorefResolver.main(CorefResolver.java:16)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing model file)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:791)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:312)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:265)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:85)
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:73)
at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(AnnotatorImplementations.java:63)
at edu.stanford.nlp.pipeline.AnnotatorFactories$4.create(AnnotatorFactories.java:243)
... 6 more
Caused by: java.io.IOException: Unable to open "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:470)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:789)
... 12 more

谁能帮我解决这个问题?

【问题讨论】:

    标签: eclipse stanford-nlp pos-tagger


    【解决方案1】:

    包括 Stanford corenlp 3.8 jar 和 Stanford corenlp 3.8 模型。现在共指解析正在起作用

    jar

    【讨论】:

      【解决方案2】:

      我发现添加 models 分类器依赖项有效。

              <dependency>
                  <groupId>edu.stanford.nlp</groupId>
                  <artifactId>stanford-corenlp</artifactId>
                  <version>4.2.2</version>
              </dependency>
      
              <dependency>
                  <groupId>edu.stanford.nlp</groupId>
                  <artifactId>stanford-corenlp</artifactId>
                  <version>4.2.2</version>
                  <classifier>models</classifier>
              </dependency>
      

      【讨论】:

        【解决方案3】:

        使用 Kotlin Gradle dsl (build.gradle.kts) 这对我有用:

        val corenlp_version = "4.2.2"
        

        如果你不想使用前面的变量,你可以替换值:

        implementation("edu.stanford.nlp:stanford-corenlp:$corenlp_version")
        implementation("edu.stanford.nlp:stanford-corenlp:$corenlp_version:models")
        implementation("edu.stanford.nlp:stanford-corenlp:$corenlp_version:models-english")
        implementation("edu.stanford.nlp:stanford-corenlp:$corenlp_version:models-english-kbp")
        

        【讨论】:

          猜你喜欢
          • 2021-08-06
          • 2022-01-17
          • 1970-01-01
          • 2021-01-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多