作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试测试 new Stanford Dependency parser它与神经网络一起使用。我正在尝试运行 zip 文件中包含的演示。文件 ParserDemo.java
和 ParserDemo2.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/
我是一名优秀的程序员,十分优秀!