traning OPenNLP error

浪尽此生 提交于 2019-12-23 11:46:42

问题


I am trying to train a Name entity model using OpenNLP, but getting this error dont know what is missing. i am new to to this OPENNLP, any one please help, can provide Train.txt file if needed

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)

My code is this

    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();
    }

回答1:


I know this was asked eons ago, I faced a similar problem with categorization setting an appropriate cutoff solved my problem. So if you give a cutoff as 1 it might help(disclaimer:- I have not tested it)

If you want to retain a default cutoff(which is 5) then you have to train it a minimum of 5 times for it to recognize




回答2:


This is typically due to not having spaces after the tags in your training data. For instance,

<START:person>bob<END> 
will fail but 
<START:person> bob <END> 
will succeed.

Post a chunk of your training data if this does not fix the problem. Also, make sure each sentence in the training file is on a single line.. in other words all sentences should not contain \n and must end with \n



来源:https://stackoverflow.com/questions/20440131/traning-opennlp-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!