Search in sources :

Example 1 with JochreSplitEventStream

use of com.joliciel.jochre.boundaries.JochreSplitEventStream in project jochre by urieli.

the class Jochre method doCommandTrainSplits.

/**
 * Train the letter splitting model.
 *
 * @param featureDescriptors
 *          the feature descriptors for training this model
 * @param criteria
 *          the criteria used to select the training corpus
 */
public void doCommandTrainSplits(List<String> featureDescriptors, CorpusSelectionCriteria criteria) {
    if (jochreSession.getSplitModelPath() == null)
        throw new RuntimeException("Missing argument: splitModel");
    if (featureDescriptors == null)
        throw new JochreException("features is required");
    File splitModelFile = new File(jochreSession.getSplitModelPath());
    splitModelFile.getParentFile().mkdirs();
    SplitFeatureParser splitFeatureParser = new SplitFeatureParser();
    Set<SplitFeature<?>> splitFeatures = splitFeatureParser.getSplitFeatureSet(featureDescriptors);
    ClassificationEventStream corpusEventStream = new JochreSplitEventStream(criteria, splitFeatures, jochreSession);
    ModelTrainerFactory modelTrainerFactory = new ModelTrainerFactory();
    ClassificationModelTrainer trainer = modelTrainerFactory.constructTrainer(jochreSession.getConfig());
    ClassificationModel splitModel = trainer.trainModel(corpusEventStream, featureDescriptors);
    splitModel.persist(splitModelFile);
}
Also used : ClassificationEventStream(com.joliciel.talismane.machineLearning.ClassificationEventStream) ModelTrainerFactory(com.joliciel.talismane.machineLearning.ModelTrainerFactory) JochreException(com.joliciel.jochre.utils.JochreException) ClassificationModelTrainer(com.joliciel.talismane.machineLearning.ClassificationModelTrainer) SplitFeatureParser(com.joliciel.jochre.boundaries.features.SplitFeatureParser) SplitFeature(com.joliciel.jochre.boundaries.features.SplitFeature) JochreSplitEventStream(com.joliciel.jochre.boundaries.JochreSplitEventStream) File(java.io.File) ClassificationModel(com.joliciel.talismane.machineLearning.ClassificationModel)

Aggregations

JochreSplitEventStream (com.joliciel.jochre.boundaries.JochreSplitEventStream)1 SplitFeature (com.joliciel.jochre.boundaries.features.SplitFeature)1 SplitFeatureParser (com.joliciel.jochre.boundaries.features.SplitFeatureParser)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 File (java.io.File)1