Search in sources :

Example 1 with OutcomeEqualiserEventStream

use of com.joliciel.talismane.machineLearning.OutcomeEqualiserEventStream in project jochre by urieli.

the class Jochre method doCommandTrainMerge.

/**
 * Train the letter merging model.
 *
 * @param featureDescriptors
 *          feature descriptors for training
 * @param multiplier
 *          if > 0, will be used to equalize the outcomes
 * @param criteria
 *          the criteria used to select the training corpus
 */
public void doCommandTrainMerge(List<String> featureDescriptors, int multiplier, CorpusSelectionCriteria criteria) {
    if (jochreSession.getMergeModelPath() == null)
        throw new RuntimeException("Missing argument: mergeModel");
    if (featureDescriptors == null)
        throw new JochreException("features is required");
    File mergeModelFile = new File(jochreSession.getMergeModelPath());
    mergeModelFile.getParentFile().mkdirs();
    MergeFeatureParser mergeFeatureParser = new MergeFeatureParser();
    Set<MergeFeature<?>> mergeFeatures = mergeFeatureParser.getMergeFeatureSet(featureDescriptors);
    ClassificationEventStream corpusEventStream = new JochreMergeEventStream(criteria, mergeFeatures, jochreSession);
    if (multiplier > 0) {
        corpusEventStream = new OutcomeEqualiserEventStream(corpusEventStream, multiplier);
    }
    ModelTrainerFactory modelTrainerFactory = new ModelTrainerFactory();
    ClassificationModelTrainer trainer = modelTrainerFactory.constructTrainer(jochreSession.getConfig());
    ClassificationModel mergeModel = trainer.trainModel(corpusEventStream, featureDescriptors);
    mergeModel.persist(mergeModelFile);
}
Also used : MergeFeatureParser(com.joliciel.jochre.boundaries.features.MergeFeatureParser) ClassificationEventStream(com.joliciel.talismane.machineLearning.ClassificationEventStream) ModelTrainerFactory(com.joliciel.talismane.machineLearning.ModelTrainerFactory) JochreException(com.joliciel.jochre.utils.JochreException) ClassificationModelTrainer(com.joliciel.talismane.machineLearning.ClassificationModelTrainer) MergeFeature(com.joliciel.jochre.boundaries.features.MergeFeature) File(java.io.File) JochreMergeEventStream(com.joliciel.jochre.boundaries.JochreMergeEventStream) OutcomeEqualiserEventStream(com.joliciel.talismane.machineLearning.OutcomeEqualiserEventStream) ClassificationModel(com.joliciel.talismane.machineLearning.ClassificationModel)

Aggregations

JochreMergeEventStream (com.joliciel.jochre.boundaries.JochreMergeEventStream)1 MergeFeature (com.joliciel.jochre.boundaries.features.MergeFeature)1 MergeFeatureParser (com.joliciel.jochre.boundaries.features.MergeFeatureParser)1 JochreException (com.joliciel.jochre.utils.JochreException)1 ClassificationEventStream (com.joliciel.talismane.machineLearning.ClassificationEventStream)1 ClassificationModel (com.joliciel.talismane.machineLearning.ClassificationModel)1 ClassificationModelTrainer (com.joliciel.talismane.machineLearning.ClassificationModelTrainer)1 ModelTrainerFactory (com.joliciel.talismane.machineLearning.ModelTrainerFactory)1 OutcomeEqualiserEventStream (com.joliciel.talismane.machineLearning.OutcomeEqualiserEventStream)1 File (java.io.File)1