Search in sources :

Example 1 with GISTrainer

use of com.joliciel.talismane.machineLearning.maxent.custom.GISTrainer in project talismane by joliciel-informatique.

the class MaxentModelTrainer method trainModel.

@Override
public ClassificationModel trainModel(ClassificationEventStream corpusEventStream, Map<String, List<String>> descriptors) throws IOException {
    MaxentModel maxentModel = null;
    EventStream eventStream = new OpenNLPEventStream(corpusEventStream);
    DataIndexer dataIndexer = new TwoPassRealValueDataIndexer(eventStream, cutoff);
    GISTrainer trainer = new GISTrainer(true);
    if (this.getSmoothing() > 0) {
        trainer.setSmoothing(true);
        trainer.setSmoothingObservation(this.getSmoothing());
    } else if (this.getSigma() > 0) {
        trainer.setGaussianSigma(this.getSigma());
    }
    maxentModel = trainer.trainModel(iterations, dataIndexer, cutoff);
    MaximumEntropyModel model = new MaximumEntropyModel(maxentModel, config, descriptors);
    model.addModelAttribute("cutoff", this.getCutoff());
    model.addModelAttribute("iterations", this.getIterations());
    model.addModelAttribute("sigma", this.getSigma());
    model.addModelAttribute("smoothing", this.getSmoothing());
    model.getModelAttributes().putAll(corpusEventStream.getAttributes());
    return model;
}
Also used : TwoPassRealValueDataIndexer(com.joliciel.talismane.machineLearning.maxent.custom.TwoPassRealValueDataIndexer) DataIndexer(opennlp.model.DataIndexer) ClassificationEventStream(com.joliciel.talismane.machineLearning.ClassificationEventStream) EventStream(opennlp.model.EventStream) MaxentModel(opennlp.model.MaxentModel) GISTrainer(com.joliciel.talismane.machineLearning.maxent.custom.GISTrainer) TwoPassRealValueDataIndexer(com.joliciel.talismane.machineLearning.maxent.custom.TwoPassRealValueDataIndexer)

Aggregations

ClassificationEventStream (com.joliciel.talismane.machineLearning.ClassificationEventStream)1 GISTrainer (com.joliciel.talismane.machineLearning.maxent.custom.GISTrainer)1 TwoPassRealValueDataIndexer (com.joliciel.talismane.machineLearning.maxent.custom.TwoPassRealValueDataIndexer)1 DataIndexer (opennlp.model.DataIndexer)1 EventStream (opennlp.model.EventStream)1 MaxentModel (opennlp.model.MaxentModel)1