我正在尝试使用OpenNLP训练一个Name实体模型,但是得到这个错误不知道缺少什么。我是这个OPENNLP的新手,任何人请帮忙,如果需要可以提供Train.txt文件
lineStream = opennlp.tools.util.PlainTextByLineStream@b52598
Indexing events using cutoff of 0
Computing event counts... done. 514 events
Indexing... done.
Sorting and merging events... done. Reduced 514 events to 492.
Done indexing.
Incorporating indexed data for training...
done.
Number of Event Tokens: 492
Number of Outcomes: 1
Number of Predicates: 3741
...done.
Computing model parameters ...
Performing 1 iterations.
1: ... loglikelihood=0.0 1.0
Exception in thread "main" java.lang.IllegalArgumentException: Model not compatible with name finder!
at opennlp.tools.namefind.TokenNameFinderModel.<init>(TokenNameFinderModel.java:81)
at opennlp.tools.namefind.TokenNameFinderModel.<init>(TokenNameFinderModel.java:106)
at opennlp.tools.namefind.NameFinderME.train(NameFinderME.java:374)
at opennlp.tools.namefind.NameFinderME.train(NameFinderME.java:432)
at opennlp.tools.namefind.NameFinderME.train(NameFinderME.java:443)
at Train2.main(Train2.java:36)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
我的代码就是这个
File fileTrainer=new File("/home/ashfaq/Documents/Train.txt");
File output=new File("/home/ashfaq/Documents/trainedModel.bin");
ObjectStream<String> lineStream = new PlainTextByLineStream(new FileInputStream(fileTrainer), "UTF-8");
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream);
System.out.println("lineStream = " + lineStream);
TokenNameFinderModel model = NameFinderME.train("en", "location", sampleStream, Collections.<String, Object>emptyMap(), 1, 0);
BufferedOutputStream modelOut = null;
try {
modelOut = new BufferedOutputStream(new FileOutputStream(output));
model.serialize(modelOut);
} finally {
if (modelOut != null)
modelOut.close();
}
答案 0 :(得分:16)
这通常是因为训练数据中的标签后没有空格。例如,
<START:person>bob<END>
will fail but
<START:person> bob <END>
will succeed.
如果这不能解决问题,请发布一大块训练数据。另外,确保训练文件中的每个句子都在一行上。换句话说,所有句子都不应包含\ n,并且必须以\ n
结尾答案 1 :(得分:0)
我知道这是在很久以前被问到的,我遇到类似的问题,分类设置合适的截止点解决了我的问题。因此,如果您将截止值设为1,则可能有所帮助(免责声明: - 我尚未对其进行测试)
如果你想保留一个默认的截止值(即5),你必须训练它至少5次才能识别