1

所以,我正在尝试使用 POSTagger 的培训 API。但我想将新的训练数据附加到旧模型中。或者,如果我想多次训练它,我会有很多模型文件。我如何将结果组合回现有模型。所以,我只有一个数据更大的模型。我认为模型文件是一个二进制文件,所以我不确定在这种情况下附加文件是否可以工作。

这是我的代码


public class POSTraining {
    private final String outputModel;
    private InputStream dataIn;

    public POSTraining() throws IOException {
        outputModel = this.getClass().getResource("/model/en-pos-maxent.bin").getPath();
        dataIn = this.getClass().getResourceAsStream("/model/en-pos.train");
    }

    public static void main(String args[]) throws IOException {

        POSTraining posTraining = new POSTraining();
        posTraining.train();
    }

    public void train() {
        try {
            ObjectStream lineStream = new PlainTextByLineStream(dataIn, "UTF-8");
            ObjectStream sampleStream = new WordTagSampleStream(lineStream);

            TrainingParameters trainParams = new TrainingParameters();
            trainParams.put("model", ModelType.MAXENT.name());
            POSModel trainedModel = POSTaggerME.train("en", sampleStream, trainParams, null, null);

            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(outputModel));
            trainedModel.serialize(bufferedOutputStream);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (dataIn != null) {
                try {
                    dataIn.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();
                }
            }
        }


    }
}


4

1 回答 1

0

NLP 模型通常无法做到这一点。您无法逐步调整它们。

于 2012-08-22T21:50:18.957 回答