use of edu.illinois.cs.cogcomp.sl.learner.Learner 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;
}
use of edu.illinois.cs.cogcomp.sl.learner.Learner in project cogcomp-nlp by CogComp.
the class StructuredCommaClassifier method train.
/**
*
* @param sentences the training set
* @param modelPath the location to save the learnt model. If it is null, it is not saved
* @throws Exception
*/
public void train(List<CommaSRLSentence> sentences, String modelPath) throws Exception {
lm.setAllowNewFeatures(true);
SLProblem sp = CommaIOManager.readProblem(sentences, lm, lbjExtractors, lbjLabeler);
// numLabels*numLabels for transition features
// numWordsInVocab*numLabels for emission features
// numLabels for prior on labels
int numFeatures = lm.getNumOfFeature();
int numLabels = lm.getNumOfLabels();
para.TOTAL_NUMBER_FEATURE = numFeatures * numLabels + numLabels + numLabels * numLabels;
Learner learner = LearnerFactory.getLearner(infSolver, featureGenerator, para);
wv = learner.train(sp);
// save the model
if (modelPath != null)
saveModel(modelPath);
}
Aggregations