当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

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..

网友答案:

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!

分享给朋友:
您可能感兴趣的文章:
随机阅读: