所以我终于将 OpenNLP 合并到我的项目中,并且我已经成功地在 15k 行训练数据上训练了我的模型,并将其存储起来,并且当我想用它来识别程序中的实体时可以加载它!
我用它来识别主题标签,所以我的训练数据看起来像这样:
...
Jim , I know you to be a fighter <START:HASHTAG> #usmarine <END> @ USMC Kira has your strength & amp ; ours @ t1r1u1t1h R love 2 U , Kira & amp ;
What has changed that people from your JAMAT are insulting Hindu GODS and GODDESSES . Calling our Religion names ... .
Ibtihaj represented the United States of America at the Olympics and brought home a medal , elevating the status of
A story point is a metric used in agile project management and development to determine ( or estimate ) the difficul
I 'm not shy or quiet , I just do n't find your mind appealing in any way shape or form and I 'm not gon na force a conv
<START:HASHTAG> #paradisepapers <END> , Canadian Taxpayers Federation ( CTF ) & amp ; tax reform `` CTF has not uttered even a single shocked-and-a
...
我发现如果模型传递的句子不是直接在我的训练集中,则该模型无法识别任何主题标签,例如:
String paragraph = "Take a shot for #harambe he took one for you!";
即使我检查过并且在我的训练数据中使用了一个 #harambe 实例,它也无法识别此示例中的主题标签。
但是,如果我直接从训练数据中传递一个句子:
String nameParagraph = "Idk whats funnier the #harambe or the fact that Im the only one who will see my page https : t.co/2eWjm6mOon ";
它将能够通过正确地将#harambe识别为HASHTAG来识别它。
我希望我的模型能够识别所有主题标签,因此我不只是想为其提供更多 #harambe 主题标签实例,以便它可以识别单个主题标签。
关于如何使我的模型正确识别不在训练集中的新实体,有什么建议吗?提前致谢!
最佳答案
我不确定您为什么要对确定性问题进行统计建模。 jbird7 提到使用正则表达式,您还可以:
使用 WhitespaceTokenizer 对文本进行标记
遍历字符串数组,查看字符串的第一个字符(是#)。
\\ create a Tokenizer
Tokenizer tokenizer=WhitespaceTokenizer.INSTANCE
String[] tokens = tokenizer.tokenize(text)
\\ use old-style loop for span creation
List<Span> spans = new ArrayList<Span>()
for (int i=0;i<tokens.length;i++){
if (token.charAt(0) == '#') spans.add(new Span(i,i+1,"HashTag"))
}
Span[] foundTags = spans.toArray(new Span[spans.size])
此时,您应该拥有与 HashTagNameFinder 完全相同的输出。抱歉,如果有语法错误。该代码应该让您了解您想要做什么。
关于java - 自定义 OpenNLP 名称查找器可识别训练集中的数据,但无法识别测试集中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47489992/