- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 OpenNLP
的模型构建器插件
来创建更好的 NER 模型。据此post ,我使用了markg发布的代码:
public class ModelBuilderAddonUse {
private static List<String> getSentencesFromSomewhere() throws Exception
{
List<String> list = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader("D:\\Work\\workspaces\\default\\UpdateModel\\documentrequirements.docx"));
String line;
while ((line = reader.readLine()) != null)
{
list.add(line);
}
reader.close();
return list;
}
public static void main(String[] args) throws Exception {
/**
* establish a file to put sentences in
*/
File sentences = new File("D:\\Work\\workspaces\\default\\UpdateModel\\sentences.text");
/**
* establish a file to put your NER hits in (the ones you want to keep based
* on prob)
*/
File knownEntities = new File("D:\\Work\\workspaces\\default\\UpdateModel\\knownentities.txt");
/**
* establish a BLACKLIST file to put your bad NER hits in (also can be based
* on prob)
*/
File blacklistedentities = new File("D:\\Work\\workspaces\\default\\UpdateModel\\blentities.txt");
/**
* establish a file to write your annotated sentences to
*/
File annotatedSentences = new File("D:\\Work\\workspaces\\default\\UpdateModel\\annotatedSentences.txt");
/**
* establish a file to write your model to
*/
File theModel = new File("D:\\Work\\workspaces\\default\\UpdateModel\\nl-ner-person.bin");
//------------create a bunch of file writers to write your results and sentences to a file
FileWriter sentenceWriter = new FileWriter(sentences, true);
FileWriter blacklistWriter = new FileWriter(blacklistedentities, true);
FileWriter knownEntityWriter = new FileWriter(knownEntities, true);
//set some thresholds to decide where to write hits, you don't have to use these at all...
double keeperThresh = .95;
double blacklistThresh = .7;
/**
* Load your model as normal
*/
TokenNameFinderModel personModel = new TokenNameFinderModel(new File("D:\\Work\\workspaces\\default\\UpdateModel\\nl-ner-person.bin"));
NameFinderME personFinder = new NameFinderME(personModel);
/**
* do your normal NER on the sentences you have
*/
for (String s : getSentencesFromSomewhere()) {
sentenceWriter.write(s.trim() + "\n");
sentenceWriter.flush();
String[] tokens = s.split(" ");//better to use a tokenizer really
Span[] find = personFinder.find(tokens);
double[] probs = personFinder.probs();
String[] names = Span.spansToStrings(find, tokens);
for (int i = 0; i < names.length; i++) {
//YOU PROBABLY HAVE BETTER HEURISTICS THAN THIS TO MAKE SURE YOU GET GOOD HITS OUT OF THE DEFAULT MODEL
if (probs[i] > keeperThresh) {
knownEntityWriter.write(names[i].trim() + "\n");
}
if (probs[i] < blacklistThresh) {
blacklistWriter.write(names[i].trim() + "\n");
}
}
personFinder.clearAdaptiveData();
blacklistWriter.flush();
knownEntityWriter.flush();
}
//flush and close all the writers
knownEntityWriter.flush();
knownEntityWriter.close();
sentenceWriter.flush();
sentenceWriter.close();
blacklistWriter.flush();
blacklistWriter.close();
/**
* THIS IS WHERE THE ADDON IS GOING TO USE THE FILES (AS IS) TO CREATE A NEW MODEL. YOU SHOULD NOT HAVE TO RUN THE FIRST PART AGAIN AFTER THIS RUNS, JUST NOW PLAY WITH THE
* KNOWN ENTITIES AND BLACKLIST FILES AND RUN THE METHOD BELOW AGAIN UNTIL YOU GET SOME DECENT RESULTS (A DECENT MODEL OUT OF IT).
*/
DefaultModelBuilderUtil.generateModel(sentences, knownEntities, blacklistedentities, theModel, annotatedSentences, "person", 3);
}
}
它也运行,但我的输出在以下位置退出:
annotated sentences: 1862
knowns: 58
Building Model using 1862 annotations
reading training data...
但是在 post 中的示例中它应该像这样进一步发展:
Indexing events using cutoff of 5
Computing event counts... done. 561755 events
Indexing... done.
Sorting and merging events... done. Reduced 561755 events to 127362.
Done indexing.
Incorporating indexed data for training...
done.
Number of Event Tokens: 127362
Number of Outcomes: 3
Number of Predicates: 106490
...done.
任何人都可以帮我解决这个问题,以便我可以生成模型吗?我确实进行了很多搜索,但找不到任何关于它的好的文档。真的很感激,谢谢。
最佳答案
更正训练数据文件的路径,如下所示:
File sentences = new File("D:/Work/workspaces/default/UpdateModel/sentences.text");
而不是
File sentences = new File("D:\\Work\\workspaces\\default\\UpdateModel\\sentences.text");
更新
这是通过将文件添加到项目文件夹中来使用的。尝试这样 -
File sentences = new File("src/training/resources/CreateModel/sentences.txt");
Check my respository for reference on Github
这应该有帮助。
关于java - OpenNLP 模型构建器插件无法继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46950036/
我是 opennlp 的新手,需要帮助来自定义解析器 我使用了带有预训练模型 en-pos-maxtent.bin 的 opennlp 解析器,用相应的语音部分标记新的原始英语句子,现在我想自定义标签
谁能指出 openNLP NameFinder 模块使用的算法? 代码很复杂,而且文档很少,并且作为一个黑盒(提供默认模型)使用它给我的印象是它主要是启发式的。 以下是输入和输出的一些示例: 输入:
我收到无效格式异常。我看到有人建议从 en-pos-maxent.bin 文件中删除 tags.tagdict 文件,但我不知道该怎么做。谁能给我解释一下 ava.io.FileInputSt
我收到无效格式异常。我看到有人建议从 en-pos-maxent.bin 文件中删除 tags.tagdict 文件,但我不知道该怎么做。谁能给我解释一下吗 ava.io.FileInputS
我正在尝试使用 Apache OpenNLP 1.7 构建自定义 NER。来自可用文档 Here ,我开发了如下代码 import java.io.BufferedOutputStream; impo
我们有组织名称同义词的数据库(例如 BT 是 British Telecom。我们使用 OpenNLP 从文本块中提取实体和关键字。有没有办法告诉 OpenNLP 使用我们的数据库数据(例如,如果它找
我刚开始使用 openNLP 来识别名称。我正在使用开放 NLP 附带的模型 (en-ner-person.bin)。我注意到虽然它可以识别我们、英国和欧洲的名字,但它无法识别印度或日本的名字。我的问
有谁知道我在哪里可以找到如何在 OpenNLP 库中使用 SimpleLemmatizer() 类的示例,以及在哪里可以找到示例英语词典?文档中似乎缺少它。 最佳答案 您可以从这里下载字典 - en-
有没有关于 OpenNLP 中解析器标签含义的文档?我知道 POS 标签类型遵循 TreeBank 约定,但不幸的是我没有找到有关解析器标签的任何信息,例如“SBAR”等。 该文档是否存在于某处还是我
我以前用过Stanford CoreNLP,这次想研究一下OpenNLP。是否可以创建自己的注释器?例如,我想分析文本并仅挑选颜色或飞机名称。 斯坦福 NER 让我创建自己的 NER 模型来实现此目的
您好,已经引用过 this , this , this和 this但仍然发现构建自定义名称查找器模型很困难..这是代码: public class CustomClassifierTrainer {
我目前正在浏览 opennlp 源代码,试图找到/理解它们用于分块的语法。这不是最简单的任务之一。我开始研究 chunkermodel 和相关的类,但还没有走得太远...... 有人搜过这个吗?如果有
我正在尝试使用 OpenNLP 标记器对文本文件进行标记。我所做的,我读取 .txt 文件并将其存储在列表中,想要迭代每一行,标记该行并将标记化的行写入新文件。 行中: tokens[i] = tok
嘿,我正在尝试为 opennlp 制作训练数据来检测句子中的位置名称。我陷入了这样的困境: North Manchester Hospital 我确实需要检测这两个对象,医院名称和城市名称。我
我正在尝试使用官方 OpenNLP 网站手册示例来训练新模型,示例如下: Charset charset = Charset.forName("UTF-8"); ObjectStrea
我一直在尝试使用命令行界面来训练我的模型,如下所示: opennlp TokenNameFinderTrainer -model en-ner-pincode.bin -iterations 500
我正在使用 OpenNLP 的模型构建器插件来创建更好的 NER 模型。据此post ,我使用了markg发布的代码: public class ModelBuilderAddonUse { pr
我正在做一个项目,我正在使用 OpenNLP 的一些功能。我需要的一个功能是词干分析器。我用谷歌搜索了一下,发现据说它在 opennlp.tools.stemmer 包中有一个 Porter 词干分析
我有两个模型文件:1)en-politicians-ner.bin 2)en-engineers-ner.bin 现在,有没有办法将这两个模型添加到一个单个 NameFinderME 对象中。使用这两
我正在使用 Java OpenNLP 进行 NER,但我不确定如何使用我训练过的自定义模型来检测多个单词(例如 New York、Bruno Mars、Hong Kong)。 我的训练数据确实涵盖了多
我是一名优秀的程序员,十分优秀!