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