问题
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