所以,我正在尝试使用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();
}
}
}
}
}
答案 0 :(得分:0)
NLP模型通常不可能。你无法逐步调整它们。