use of edu.illinois.cs.cogcomp.sl.util.Lexiconer in project cogcomp-nlp by CogComp.
the class MainClass method train.
private static SLModel train(String trainFile, String configFilePath, String modelFile) throws Exception {
SLModel model = new SLModel();
SLParameters para = new SLParameters();
para.loadConfigFile(configFilePath);
model.lm = new Lexiconer(true);
if (model.lm.isAllowNewFeatures())
model.lm.addFeature("W:unknownword");
model.featureGenerator = new LabeledDepFeatureGenerator(model.lm);
model.infSolver = new LabeledChuLiuEdmondsDecoder(model.featureGenerator);
SLProblem problem = getStructuredData(trainFile, (LabeledChuLiuEdmondsDecoder) model.infSolver);
((LabeledChuLiuEdmondsDecoder) model.infSolver).saveDepRelDict();
Learner learner = LearnerFactory.getLearner(model.infSolver, model.featureGenerator, para);
learner.runWhenReportingProgress((w, inference) -> printMemoryUsage());
model.wv = learner.train(problem);
printMemoryUsage();
model.lm.setAllowNewFeatures(false);
model.saveModel(modelFile);
return model;
}
Aggregations