Why is a self trained NER-Model incompatible with the version of OpenNLP?

*爱你&永不变心* 提交于 2020-01-03 05:48:28

问题


I trained OpenNLP NER-Model to detect a new Entity but when I am using this model I encountered the following Exception:

Exception in thread "main" java.lang.IllegalArgumentException: 
opennlp.tools.util.InvalidFormatException: 
   Model version 1.6.0 is not supported by this (1.5.3) version of OpenNLP!

I am using OpenNLP version 1.6.0 and my source code is this:

String [] sentences = Fragmentation.getSentences(Document);
InputStream modelIn = new FileInputStream("Models/en-ner-cvskill.bin");
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
NameFinderME nameFinder = new NameFinderME(model);
String[] tokens = null;
Span nameSpans[] = null;
int i=0; 
for (String sentence : sentences) {
    tokens = null;
    nameSpans = null;

    System.out.println("Sentences: "+(++i)+"\n" + sentence);
    tokens = Fragmentation.getTokens(sentence);
    for(String token: tokens){
          System.out.println("Token:-------------------: "+token);
    }
    nameSpans = nameFinder.find(tokens);
    String SkillName = Arrays.toString(Span.spansToStrings(nameSpans, tokens));
    for(Span name:nameSpans){
          System.out.println("Skills: "+ name.toString());
    }

    System.out.println("Names-------------------:"+SkillName);
}
nameFinder.clearAdaptiveData();                      

Anyone please help me solve this problem..


回答1:


I have finde out the problem.. Actually I was training namefinder of opennlp 1.6.0 and was using within the same version which is not possible with the current version(1.6.0) of the opennlp. Now I trained the model of opennlp 1.5.3 and is using with opennlp 1.6.0 which is working fine!



来源:https://stackoverflow.com/questions/33250241/why-is-a-self-trained-ner-model-incompatible-with-the-version-of-opennlp

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