Search in sources :

Example 1 with LabeledDepFeatureGenerator

use of edu.illinois.cs.cogcomp.depparse.features.LabeledDepFeatureGenerator 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;
}
Also used : Lexiconer(edu.illinois.cs.cogcomp.sl.util.Lexiconer) LabeledDepFeatureGenerator(edu.illinois.cs.cogcomp.depparse.features.LabeledDepFeatureGenerator) LabeledChuLiuEdmondsDecoder(edu.illinois.cs.cogcomp.depparse.core.LabeledChuLiuEdmondsDecoder) Learner(edu.illinois.cs.cogcomp.sl.learner.Learner)

Aggregations

LabeledChuLiuEdmondsDecoder (edu.illinois.cs.cogcomp.depparse.core.LabeledChuLiuEdmondsDecoder)1 LabeledDepFeatureGenerator (edu.illinois.cs.cogcomp.depparse.features.LabeledDepFeatureGenerator)1 Learner (edu.illinois.cs.cogcomp.sl.learner.Learner)1 Lexiconer (edu.illinois.cs.cogcomp.sl.util.Lexiconer)1