gpt4 book ai didi

java - 斯坦福神经网络依赖解析器 : Unrecoverable error while loading a tagger model

转载 作者:行者123 更新时间:2023-12-01 11:11:21 25 4
gpt4 key购买 nike

我正在尝试测试 new Stanford Dependency parser它与神经网络一起使用。我正在尝试运行 zip 文件中包含的演示。文件 ParserDemo.javaParserDemo2.java 工作正常。然而文件DependencyParserDemo.java:

import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.parser.nndep.DependencyParser;
import edu.stanford.nlp.process.DocumentPreprocessor;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
import edu.stanford.nlp.trees.GrammaticalStructure;

import java.io.StringReader;
import java.util.List;

/**
* Demonstrates how to first use the tagger, then use the NN dependency
* parser. Note that the parser will not work on untagged text.
*
* @author Jon Gauthier
*/
public class DependencyParserDemo {
public static void main(String[] args) {
String modelPath = DependencyParser.DEFAULT_MODEL;
String taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";

for (int argIndex = 0; argIndex < args.length; ) {
switch (args[argIndex]) {
case "-tagger":
taggerPath = args[argIndex + 1];
argIndex += 2;
break;
case "-model":
modelPath = args[argIndex + 1];
argIndex += 2;
break;
default:
throw new RuntimeException("Unknown argument " + args[argIndex]);
}
}

String text = "I can almost always tell when movies use fake dinosaurs.";

MaxentTagger tagger = new MaxentTagger(taggerPath);
DependencyParser parser = DependencyParser.loadFromModelFile(modelPath);

DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));
for (List<HasWord> sentence : tokenizer) {
List<TaggedWord> tagged = tagger.tagSentence(sentence);
GrammaticalStructure gs = parser.predict(tagged);

// Print typed dependencies
System.err.println(gs);
}
}
}

抛出错误:

Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:769)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:297)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:262)
at DependencyParserDemo.main(DependencyParserDemo.java:40)
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:448)
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:764)
... 3 more

有人可以告诉我我做错了什么吗?

最佳答案

您的文件“english-left3words-distsim.tagger”的路径似乎不正确。检查您提供的路径是否正确。您也可以尝试使用绝对路径。

贝尔菲戈尔回复:

I solved it with absolute path. I first created the following folders in the src folders: edu/stanford/nlp/models/pos-tagger/english-left3words/ and inside I pasted the file english-left3words-distsim.tagger (which is in the POS-tagger file stanford-postagger-full-2015-04-20.zip). After this - it worked.

关于java - 斯坦福神经网络依赖解析器 : Unrecoverable error while loading a tagger model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326065/

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