加载 NER .bin 文件作为 openNLP::Maxent_Entity_Annotator() 的模型参数时出错

error loading NER .bin file as model argument for openNLP::Maxent_Entity_Annotator()

我使用 Apache OpenNLP 的命令行工具创建了一个模型来识别命名实体。下面的代码使用文件 sentences4OpenNLP.txt 作为训练集创建了模型。

opennlp TokenNameFinderTrainer -type maxent -model C:\Users\Documents\en-ner-org.bin -lang en -data C:\Users\Documents\apache-opennlp-1.6.0\sentences4OpenNLP.txt -encoding UTF-8

我通过将句子传递给标记从命令行测试模型,模型似乎运行良好。但是,我无法成功使用 R 中的模型。我正在使用以下行来尝试创建组织注释函数。使用相同的代码加载从 OpenNLP 下载的模型工作正常。

modelNER <- "C:/Users/Documents/en-ner-org.bin"
oa <- openNLP::Maxent_Entity_Annotator(language = "en",
                                  kind = "organization",
                                  probs = TRUE,
                                  model = modelNER)

当上面的代码是 运行 时,我收到一条错误消息:

Could not instantiate the opennlp.tools.namefind.TokenNameFinderFactory. The initialization throw an exception.
opennlp.tools.util.ext.ExtensionNotLoadedException: Unable to find implementation for opennlp.tools.util.BaseToolFactory, the class or service opennlp.tools.namefind.TokenNameFinderFactory could not be located!
     at opennlp.tools.util.ext.ExtensionLoader.instantiateExtension(ExtensionLoader.java:97)
     at opennlp.tools.util.BaseToolFactory.create(BaseToolFactory.java:106)
     at opennlp.tools.util.model.BaseModel.initializeFactory(BaseModel.java:254)
Error in .jnew("opennlp.tools.namefind.TokenNameFinderModel", .jcast(.jnew("java.io.FileInputStream",  : 
java.lang.IllegalArgumentException: opennlp.tools.util.InvalidFormatException: Could not instantiate the opennlp.tools.namefind.TokenNameFinderFactory. The initialization throw an exception.
     at opennlp.tools.util.model.BaseModel.loadModel(BaseModel.java:237)
     at opennlp.tools.util.model.BaseModel.<init>(BaseModel.java:181)
     at opennlp.tools.namefind.TokenNameFinderModel.<init>(TokenNameFinderModel.java:110)

任何关于如何修复错误的建议都会有很大帮助。提前致谢。

已解决错误。 R 函数 openNLP::Maxent_Entity_Annotator 与 OpenNLP 1.6.0 生成的命名实体识别 (NER) 模型不兼容。使用 OpenNLP 1.5.3 构建 NER 模型导致 openNLP::Maxent_Entity_Annotator 运行 没有错误。