为什么自训练的NER模型与OpenNLP版本不兼容? [英] Why is a self trained NER-Model incompatible with the version of OpenNLP?

查看:107
本文介绍了为什么自训练的NER模型与OpenNLP版本不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我训练过OpenNLP NER模型以检测新实体,但是当我使用此模型时,遇到以下异常:

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!

我正在使用OpenNLP 1.6.0版,我的源代码是这样:

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

推荐答案

我已经找到了问题所在. 实际上,我正在培训opennlp 1.6.0的名称查找器,并且正在同一版本中使用,而该版本在opennlp的当前版本(1.6.0)中是不可能的. 现在,我训练了opennlp 1.5.3的模型,并与opennlp 1.6.0一起使用,效果很好!

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!

这篇关于为什么自训练的NER模型与OpenNLP版本不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆