温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

OpenNLP的Name Finder怎么使用

发布时间:2022-01-05 16:52:20 来源:亿速云 阅读:111 作者:iii 栏目:云计算

这篇文章主要介绍“OpenNLP的Name Finder怎么使用”,在日常操作中,相信很多人在OpenNLP的Name Finder怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”OpenNLP的Name Finder怎么使用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

 ##Named Entity Recognition 命令实体识别## Name Finder可以检测文本中的命名实体和数字。要检测实体,Name Finder需要一个模型。模型依赖于它训练的语言和实体类型。OpenNlP提供了许多预训练的name finder模型,他们使用各种各样可以免费得到的语料库训练。他们可以在我们的模型下载页面下载。在未经处理的(raw)文本中发现names,这个文本必须被分割成tokens和Sentences。在Sentence detector和tokenizer 入门中给出了详细的描述。确保用于训练的tokenization数据和输入文本是相同的。

###Name Finder Tool### ###Name Finder API### 在一个生产系统中使用Name Finder,强烈推荐直接嵌入它到应用程序中,而不是使用命令行接口。首先,必须从磁盘或者其他源加载name finder模型。下面的示例实在磁盘加载的.

InputStream modelIn = new FileInputStream("en-ner-person.bin");

try {
  TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
}
catch (IOException e) {
  e.printStackTrace();
}
finally {
  if (modelIn != null) {
    try {
      modelIn.close();
    }
    catch (IOException e) {
    }
  }
}

有许多原因会导致模型加载失败:

  • 基本的I/O问题

  • 模型的版本和OpenNLP版本不兼容

  • 模型加载到错误的组件,例如,一个tokenizer模型加载到TokenNameFinderModel类

  • 由于其他一些原因模型内容不可用

在模型加载后,NameFinderME可以实例化。

NameFinderME nameFinder = new NameFinderME(model);

初始化现在完成,Name Finder现在可以使用。NameFinderME不是线程安全的,他必须只在一个线程中调用。要使用多线程多NameFinderME实例共享可以创建相同的模型实例。输入本文必须切分成documents,sentences,和tokens。应用程序调用find方法在文档中的每一个sentence中执行实体检测。After every document clearAdaptiveData must be called to clear the adaptive data in the feature generators.Not calling clearAdaptiveData can lead to a sharp drop in the detection rate after a few documents. 下面的代码解释了这个:

for (String document[][] : documents) {

  for (String[] sentence : document) {
    Span nameSpans[] = nameFinder.find(sentence);
    // do something with the names
  }

  nameFinder.clearAdaptiveData()
}

下面的片段展示了find的一个调用:

String sentence[] = new String[]{
    "Pierre",
    "Vinken",
    "is",
    "61",
    "years"
    "old",
    "."
    };

Span nameSpans[] = nameFinder.find(sentence);

到此,关于“OpenNLP的Name Finder怎么使用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI