【问题标题】:Training a categorizer model Opennlp训练分类器模型 Opennlp
【发布时间】:2017-10-06 07:02:12
【问题描述】:

我正在尝试使用以下代码训练模型,但我在 DocumentCategorizerME.train() 方法上不断收到错误消息,它告诉我将 factory 更改为 doccatfactory。为什么?

public void trainModel() 
{
    DoccatModel model = null;
    InputStream dataIn = null;

    try
    {
        InputStreamFactory factory = getInputStreamFactory(new File("D:/training.txt"));
        ObjectStream<String> lineStream = new PlainTextByLineStream(factory, Charset.defaultCharset());
        ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);
        TrainingParameters params = new TrainingParameters();
        params.put(TrainingParameters.ITERATIONS_PARAM, "100");
        params.put(TrainingParameters.CUTOFF_PARAM, "0");

        model = DocumentCategorizerME.train("en", sampleStream, params, factory);

    }



}

public static InputStreamFactory getInputStreamFactory(final File file) throws IOException{
    return new InputStreamFactory() {

        @Override
        public InputStream createInputStream() throws IOException {
            return new FileInputStream(file);
        }
    };
}

【问题讨论】:

    标签: java training-data opennlp


    【解决方案1】:

    当您使用 DocumentCategorizerME.train(...) 方法时,您需要传入 DoccatFactory 而不是 InputStreamFactory。试试:

      model = DocumentCategorizerME.train("en", sampleStream, params, new DoccatFactory());
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多