【问题标题】:How to train Open NLP without file如何在没有文件的情况下训练 Open NLP
【发布时间】:2017-04-03 18:25:51
【问题描述】:

我有以下代码用于训练 Open NLP POS Tagger

Trainer(String trainingData, String modelSavePath, String dictionary){

    try {
        dataIn = new MarkableFileInputStreamFactory(
                new File(trainingData));

        lineStream = new PlainTextByLineStream(dataIn, "UTF-8");
        ObjectStream<POSSample> sampleStream = new WordTagSampleStream(lineStream);

        POSTaggerFactory fac=new POSTaggerFactory();
        if(dictionary!=null && dictionary.length()>0)
        {
            fac.setDictionary(new Dictionary(new FileInputStream(dictionary)));
        }
        model = POSTaggerME.train("en", sampleStream, TrainingParameters.defaultParams(), fac);

    } catch (IOException e) {
        // Failed to read or parse training data, training failed
        e.printStackTrace();
    } finally {
        if (lineStream != null) {
            try {
                lineStream.close();
            } catch (IOException e) {
                // Not an issue, training already finished.
                // The exception should be logged and investigated
                // if part of a production system.
                e.printStackTrace();
            }
        }
    }
}

这很好用。现在,是否可以在不涉及文件的情况下做同样的事情?我想将训练数据存储在某个数据库中。然后我可以将其作为流或块读取并将其提供给培训师。我不想创建临时文件。这可能吗?

【问题讨论】:

  • 我很困惑,您的 sampleStream 不是以特定 OpenNLP 格式标记的 POS 训练数据吗?这样的数据通常很难获得,我认为 OpenNLP 提供了这些数据。您是否想从数据库中读取数据,因为您将用户注释的 POS 标记数据存储在关系数据库中?我只是想确保您没有做您不想做的事情,通常您只需使用提供的文件。
  • 谢谢,是的,我正在获取存储在数据库中的手动注释数据
  • 您的数据是如何存储在数据库中的?还是您尚未创建架构?
  • 每一行数据的格式为word1_tag1 word2_tag2 ...每一行代表一个句子
  • 所以我可以逐行阅读。我在想,从概念上讲,它类似于从文件中逐行读取

标签: machine-learning nlp opennlp pos-tagger


【解决方案1】:

是的,您可以创建自己的 InputStream 实现,例如 DatabaseSourceInputStream 并使用它,而不是将 FileInputStream 传递给字典。

【讨论】:

    猜你喜欢
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-17
    • 1970-01-01
    • 2019-04-11
    • 2018-12-12
    • 2021-10-15
    相关资源
    最近更新 更多