Search in sources :

Example 16 with BatchTrainer

use of edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer in project cogcomp-nlp by CogComp.

the class BIOTester method train_pro_classifier.

/**
 * Trainer for the head pronoun classifier.
 * @param train_parser The parser containing all training examples
 * @param modelLoc The expected model file destination. Support null.
 */
public static bio_classifier_pro train_pro_classifier(Parser train_parser, String modelLoc) {
    bio_classifier_pro classifier = new bio_classifier_pro();
    train_parser.reset();
    BatchTrainer trainer = new BatchTrainer(classifier, train_parser);
    String modelFileName = "";
    if (modelLoc == null) {
        String parser_id = ((BIOReader) train_parser).id;
        modelFileName = "tmp/bio_classifier_" + parser_id;
    } else {
        modelFileName = modelLoc;
    }
    classifier.setLexiconLocation(modelFileName + ".lex");
    Learner preExtractLearner = trainer.preExtract(modelFileName + ".ex", true, Lexicon.CountPolicy.none);
    preExtractLearner.saveLexicon();
    Lexicon lexicon = preExtractLearner.getLexicon();
    classifier.setLexicon(lexicon);
    int examples = 0;
    for (Object example = train_parser.next(); example != null; example = train_parser.next()) {
        examples++;
    }
    train_parser.reset();
    classifier.initialize(examples, preExtractLearner.getLexicon().size());
    for (Object example = train_parser.next(); example != null; example = train_parser.next()) {
        classifier.learn(example);
    }
    train_parser.reset();
    classifier.doneWithRound();
    classifier.doneLearning();
    if (modelLoc != null) {
        classifier.setModelLocation(modelFileName + ".lc");
        classifier.saveModel();
    }
    return classifier;
}
Also used : BatchTrainer(edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer) Lexicon(edu.illinois.cs.cogcomp.lbjava.learn.Lexicon) LbjGen.bio_classifier_pro(org.cogcomp.md.LbjGen.bio_classifier_pro) Learner(edu.illinois.cs.cogcomp.lbjava.learn.Learner)

Example 17 with BatchTrainer

use of edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer in project cogcomp-nlp by CogComp.

the class BIOTester method train_nam_classifier.

/**
 * Trainer for the head named entity classifier.
 * @param train_parser The parser containing all training examples
 * @param modelLoc The expected model file destination. Support null.
 */
public static bio_classifier_nam train_nam_classifier(Parser train_parser, String modelLoc) {
    bio_classifier_nam classifier = new bio_classifier_nam();
    train_parser.reset();
    BatchTrainer trainer = new BatchTrainer(classifier, train_parser);
    String modelFileName = "";
    if (modelLoc == null) {
        String parser_id = ((BIOReader) train_parser).id;
        modelFileName = "tmp/bio_classifier_" + parser_id;
    } else {
        modelFileName = modelLoc;
    }
    classifier.setLexiconLocation(modelFileName + ".lex");
    Learner preExtractLearner = trainer.preExtract(modelFileName + ".ex", true, Lexicon.CountPolicy.none);
    preExtractLearner.saveLexicon();
    Lexicon lexicon = preExtractLearner.getLexicon();
    classifier.setLexicon(lexicon);
    int examples = 0;
    for (Object example = train_parser.next(); example != null; example = train_parser.next()) {
        examples++;
    }
    train_parser.reset();
    classifier.initialize(examples, preExtractLearner.getLexicon().size());
    for (int i = 0; i < 1; i++) {
        train_parser.reset();
        for (Object example = train_parser.next(); example != null; example = train_parser.next()) {
            classifier.learn(example);
        }
        classifier.doneWithRound();
    }
    classifier.doneLearning();
    if (modelLoc != null) {
        classifier.setModelLocation(modelFileName + ".lc");
        classifier.saveModel();
    }
    return classifier;
}
Also used : BatchTrainer(edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer) Lexicon(edu.illinois.cs.cogcomp.lbjava.learn.Lexicon) LbjGen.bio_classifier_nam(org.cogcomp.md.LbjGen.bio_classifier_nam) Learner(edu.illinois.cs.cogcomp.lbjava.learn.Learner)

Example 18 with BatchTrainer

use of edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer in project cogcomp-nlp by CogComp.

the class ExtentTester method train_extent_classifier.

public static extent_classifier train_extent_classifier(ExtentReader train_parser, String prefix) {
    extent_classifier classifier = new extent_classifier();
    String modelFileName = "";
    if (prefix == null) {
        String postfix = train_parser.getId();
        modelFileName = "tmp/extent_classifier_" + postfix;
    } else {
        modelFileName = prefix;
    }
    classifier.setLexiconLocation(modelFileName + ".lex");
    BatchTrainer trainer = new BatchTrainer(classifier, train_parser);
    Lexicon lexicon = trainer.preExtract(modelFileName + ".ex", true);
    classifier.setLexicon(lexicon);
    classifier.setModelLocation(modelFileName + ".lc");
    trainer.train(1);
    classifier.saveModel();
    return classifier;
}
Also used : BatchTrainer(edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer) Lexicon(edu.illinois.cs.cogcomp.lbjava.learn.Lexicon)

Aggregations

BatchTrainer (edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer)18 Lexicon (edu.illinois.cs.cogcomp.lbjava.learn.Lexicon)11 Learner (edu.illinois.cs.cogcomp.lbjava.learn.Learner)9 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)5 SparseAveragedPerceptron (edu.illinois.cs.cogcomp.lbjava.learn.SparseAveragedPerceptron)4 Parser (edu.illinois.cs.cogcomp.lbjava.parse.Parser)4 File (java.io.File)4 LbjGen.relation_classifier (org.cogcomp.re.LbjGen.relation_classifier)4 LocalCommaClassifier (edu.illinois.cs.cogcomp.comma.lbj.LocalCommaClassifier)2 EvaluateDiscrete (edu.illinois.cs.cogcomp.comma.utils.EvaluateDiscrete)2 TestDiscrete (edu.illinois.cs.cogcomp.lbjava.classify.TestDiscrete)2 FoldParser (edu.illinois.cs.cogcomp.lbjava.parse.FoldParser)2 NETaggerLevel1 (edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel1)2 NETaggerLevel2 (edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel2)2 IOException (java.io.IOException)2 ListCommasConstrainedCommaClassifier (edu.illinois.cs.cogcomp.comma.lbj.ListCommasConstrainedCommaClassifier)1 LocativePairConstrainedCommaClassifier (edu.illinois.cs.cogcomp.comma.lbj.LocativePairConstrainedCommaClassifier)1 OxfordCommaConstrainedCommaClassifier (edu.illinois.cs.cogcomp.comma.lbj.OxfordCommaConstrainedCommaClassifier)1 SubstitutePairConstrainedCommaClassifier (edu.illinois.cs.cogcomp.comma.lbj.SubstitutePairConstrainedCommaClassifier)1 StructuredCommaClassifier (edu.illinois.cs.cogcomp.comma.sl.StructuredCommaClassifier)1