Search in sources :

Example 1 with DKProTcShallowSerializationTask

use of org.dkpro.tc.core.task.DKProTcShallowSerializationTask in project dkpro-tc by dkpro.

the class ExperimentSaveModel method init.

/**
 * Initializes the experiment. This is called automatically before execution. It's not done
 * directly in the constructor, because we want to be able to use setters instead of the
 * three-argument constructor.
 *
 * @throws IllegalStateException
 *             if not all necessary arguments have been set.
 */
protected void init() {
    if (experimentName == null) {
        throw new IllegalStateException("You must set an experiment name");
    }
    // init the train part of the experiment
    initTask = new InitTask();
    initTask.setPreprocessing(getPreprocessing());
    initTask.setOperativeViews(operativeViews);
    initTask.setTesting(false);
    initTask.setType(initTask.getType() + "-Train-" + experimentName);
    initTask.setAttribute(TC_TASK_TYPE, TcTaskType.INIT_TRAIN.toString());
    collectionTask = new OutcomeCollectionTask();
    collectionTask.setType(collectionTask.getType() + "-" + experimentName);
    collectionTask.setAttribute(TC_TASK_TYPE, TcTaskType.COLLECTION.toString());
    collectionTask.addImport(initTask, InitTask.OUTPUT_KEY_TRAIN);
    metaTask = new MetaInfoTask();
    metaTask.setOperativeViews(operativeViews);
    metaTask.setType(metaTask.getType() + "-" + experimentName);
    metaTask.setAttribute(TC_TASK_TYPE, TcTaskType.META.toString());
    metaTask.addImport(initTask, InitTask.OUTPUT_KEY_TRAIN, MetaInfoTask.INPUT_KEY);
    // feature extraction on training data
    featuresTrainTask = new ExtractFeaturesTask();
    featuresTrainTask.setType(featuresTrainTask.getType() + "-Train-" + experimentName);
    featuresTrainTask.addImport(metaTask, MetaInfoTask.META_KEY);
    featuresTrainTask.addImport(initTask, InitTask.OUTPUT_KEY_TRAIN, ExtractFeaturesTask.INPUT_KEY);
    featuresTrainTask.setAttribute(TC_TASK_TYPE, TcTaskType.FEATURE_EXTRACTION_TRAIN.toString());
    featuresTrainTask.addImport(collectionTask, OutcomeCollectionTask.OUTPUT_KEY, ExtractFeaturesTask.COLLECTION_INPUT_KEY);
    // feature extraction and prediction on test data
    try {
        saveModelTask = new DKProTcShallowSerializationTask(metaTask, featuresTrainTask, collectionTask, outputFolder, experimentName);
        saveModelTask.setType(saveModelTask.getType() + "-" + experimentName);
        saveModelTask.addImport(metaTask, MetaInfoTask.META_KEY);
        saveModelTask.addImport(featuresTrainTask, ExtractFeaturesTask.OUTPUT_KEY, Constants.TEST_TASK_INPUT_KEY_TRAINING_DATA);
        saveModelTask.addImport(collectionTask, OutcomeCollectionTask.OUTPUT_KEY, Constants.OUTCOMES_INPUT_KEY);
        saveModelTask.setAttribute(TC_TASK_TYPE, TcTaskType.FACADE_TASK.toString());
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    // DKPro Lab issue 38: must be added as *first* task
    addTask(initTask);
    addTask(collectionTask);
    addTask(metaTask);
    addTask(featuresTrainTask);
    addTask(saveModelTask);
}
Also used : DKProTcShallowSerializationTask(org.dkpro.tc.core.task.DKProTcShallowSerializationTask) OutcomeCollectionTask(org.dkpro.tc.core.task.OutcomeCollectionTask) MetaInfoTask(org.dkpro.tc.core.task.MetaInfoTask) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) InitTask(org.dkpro.tc.core.task.InitTask) ExtractFeaturesTask(org.dkpro.tc.core.task.ExtractFeaturesTask)

Aggregations

TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)1 DKProTcShallowSerializationTask (org.dkpro.tc.core.task.DKProTcShallowSerializationTask)1 ExtractFeaturesTask (org.dkpro.tc.core.task.ExtractFeaturesTask)1 InitTask (org.dkpro.tc.core.task.InitTask)1 MetaInfoTask (org.dkpro.tc.core.task.MetaInfoTask)1 OutcomeCollectionTask (org.dkpro.tc.core.task.OutcomeCollectionTask)1