Search in sources :

Example 1 with Learner

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;
}
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)

Example 2 with Learner

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);
}
Also used : SLProblem(edu.illinois.cs.cogcomp.sl.core.SLProblem) Learner(edu.illinois.cs.cogcomp.sl.learner.Learner)

Aggregations

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