训练OPenNLP错误

 白日做梦家_ 发布于 2023-02-12 12:16

我正在尝试使用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.(TokenNameFinderModel.java:81)
at opennlp.tools.namefind.TokenNameFinderModel.(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 lineStream = new PlainTextByLineStream(new    FileInputStream(fileTrainer), "UTF-8");
    ObjectStream sampleStream = new NameSampleDataStream(lineStream);
    System.out.println("lineStream = " + lineStream);
    TokenNameFinderModel model = NameFinderME.train("en", "location", sampleStream, Collections.emptyMap(), 1, 0);

    BufferedOutputStream modelOut = null;
    try {
        modelOut = new BufferedOutputStream(new FileOutputStream(output));
        model.serialize(modelOut);
    } finally {
        if (modelOut != null)
            modelOut.close();
    }

markgiaconia.. 17

这通常是由于训练数据中的标签后没有空格.例如,

bob 
will fail but 
 bob  
will succeed.

如果这不能解决问题,请发布一大块训练数据.另外,确保训练文件中的每个句子都在一行上.换句话说,所有句子都不应包含\n,并且必须以\n结尾

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有