【问题标题】:Why does OpenNLP's Document Categorizer train so fast?为什么 OpenNLP Document Categorizer 训练得这么快?
【发布时间】:2019-08-16 00:39:34
【问题描述】:

OpenNLP 的性能明显不如我测试过的其他文档分类器,所以在我放弃它之前,我决定确保我正在使用所有的刻度盘和旋钮。对我来说突出的一件事是 OpenNLP 非常快地训练我的模型(大约 1.2 秒)。我使用的其他 NLP 工具可能需要几分钟甚至几个小时来训练。我的训练文件中有大约 12k 条记录。

我尝试将迭代次数从 10 次增加到 10000 次,不幸的是,这似乎对训练时间或准确性没有任何影响。

奇怪的是,OpenNLP 的文档对训练持续时间进行了以下说明:“现在可能是浏览 Hulu 或其他什么的好时机,因为如果你有一个大型训练集,这可能需要一段时间”。这让我觉得我做错了什么。

            int TRAINING_ITERATIONS = 10000;

            InputStreamFactory dataIn = new MarkableFileInputStreamFactory(new File(dataSetFileName));
            ObjectStream<String> lineStream = new PlainTextByLineStream(dataIn, "UTF-8");
            ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);

            // define the training parameters
            TrainingParameters params = new TrainingParameters();
            params.put(TrainingParameters.ITERATIONS_PARAM, TRAINING_ITERATIONS+"");
            params.put(TrainingParameters.CUTOFF_PARAM, 0+"");
            params.put(AbstractTrainer.ALGORITHM_PARAM, NaiveBayesTrainer.NAIVE_BAYES_VALUE);

            FeatureGenerator[] featureGenerators = { new NGramFeatureGenerator(1,1),
                    new NGramFeatureGenerator(2,3) };
            DoccatFactory factory = new DoccatFactory(featureGenerators);


            // create a model from training data
            StopWatch stopWatch = new StopWatch();

            // Start the watch, do some task and stop the watch.
            stopWatch.start();


            model = DocumentCategorizerME.train("en", sampleStream, params, factory);
            stopWatch.stop();
            System.out.println("Training Time: " + stopWatch.getTime()+"ms"); // finishes in 1.2 second!!! 

这是我得到的输出

Indexing events with TwoPass using cutoff of 0

    Computing event counts...  done. 2407 events
    Indexing...  done.
Collecting events... Done indexing in 0.84 s.
Incorporating indexed data for training...  
done.
    Number of Event Tokens: 2407
        Number of Outcomes: 12
      Number of Predicates: 44219
Computing model parameters...
Stats: (455/2407) 0.18903199002908183
...done.
Training Time: 1241ms

迭代参数有什么作用吗?

【问题讨论】:

    标签: nlp opennlp


    【解决方案1】:

    好的,我想通了,朴素贝叶斯只是一种非常快速的算法,因为它没有优化步骤。迭代参数并没有真正做太多。如果您使用其中包含的任何其他训练算法,则训练确实需要很长时间。令人惊讶的是,对于我的数据集,即使我训练了几个小时,其他算法也会导致更差的准确性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      相关资源
      最近更新 更多