如何培养定制模型opennlp?

时间:2013-10-25 16:19:10

标签: nlp opennlp

我想训练自己的自定义模型。 我从哪里开始?

我正在使用此示例数据来训练模型:

<START:meaningless>Took connection and<END>  selected the Text in the Letter Template and cleared the Formatting of Text to Normal.

基本上我想从给定的输入中识别出一些无意义的文本。

我尝试使用opennlp开发文档中给出的示例代码 但是得到错误:模型与名字查找器不兼容!

    Charset charset = Charset.forName("UTF-8");
ObjectStream<String> lineStream =
        new PlainTextByLineStream(new FileInputStream("mynewmodel.train"), charset);
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream);

TokenNameFinderModel model;

try {
  model = NameFinderME.train("en", "meaningless", sampleStream,
      Collections.<String, Object>emptyMap(), 100, 5);
}
finally {
  sampleStream.close();
}

try {
  modelOut = new BufferedOutputStream(new FileOutputStream(modelFile));
  model.serialize(modelOut);
} finally {
  if (modelOut != null) 
     modelOut.close();      
}

1 个答案:

答案 0 :(得分:0)

可能的问题:你没有向教练提供清晰的标记化文字。如果我正确理解文档,则PlainTextByLineStream需要以空格分隔的标记。所以

<START:meaningless> Took connection and <END>

而不是

<START:meaningless>Took connection and<END>