Search in sources :

Example 1 with TcShallowLearningAdapter

use of org.dkpro.tc.core.ml.TcShallowLearningAdapter in project dkpro-tc by dkpro.

the class DKProTcShallowTestTask method initialize.

@Override
public void initialize(TaskContext aContext) {
    super.initialize(aContext);
    TcShallowLearningAdapter adapter = (TcShallowLearningAdapter) classArgs.get(0);
    ExecutableTaskBase testTask = adapter.getTestTask();
    testTask.addReport(adapter.getOutcomeIdReportClass());
    Class<? extends ReportBase> baselineIdReportClass = adapter.getMajorityClassBaselineIdReportClass();
    if (baselineIdReportClass != null) {
        testTask.addReport(baselineIdReportClass);
    }
    Class<? extends ReportBase> randomBaselineIdReportClass = adapter.getRandomBaselineIdReportClass();
    if (randomBaselineIdReportClass != null) {
        testTask.addReport(randomBaselineIdReportClass);
    }
    if (reports != null) {
        for (ReportBase b : reports) {
            testTask.addReport(b);
        }
    }
    testTask.addImport(featuresTrainTask, ExtractFeaturesTask.OUTPUT_KEY, Constants.TEST_TASK_INPUT_KEY_TRAINING_DATA);
    testTask.addImport(featuresTestTask, ExtractFeaturesTask.OUTPUT_KEY, Constants.TEST_TASK_INPUT_KEY_TEST_DATA);
    testTask.addImport(collectionTask, OutcomeCollectionTask.OUTPUT_KEY, Constants.OUTCOMES_INPUT_KEY);
    testTask.setAttribute(TC_TASK_TYPE, TcTaskType.MACHINE_LEARNING_ADAPTER.toString());
    testTask.setType(testTask.getType() + "-" + experimentName);
    deleteOldTaskSetNewOne(testTask);
}
Also used : ReportBase(org.dkpro.lab.reporting.ReportBase) TcShallowLearningAdapter(org.dkpro.tc.core.ml.TcShallowLearningAdapter) ExecutableTaskBase(org.dkpro.lab.task.impl.ExecutableTaskBase)

Example 2 with TcShallowLearningAdapter

use of org.dkpro.tc.core.ml.TcShallowLearningAdapter in project dkpro-tc by dkpro.

the class DKProTcShallowSerializationTask method initialize.

@Override
public void initialize(TaskContext aContext) {
    super.initialize(aContext);
    TcShallowLearningAdapter adapter = (TcShallowLearningAdapter) classArgs.get(0);
    ModelSerializationTask serializationTask;
    try {
        serializationTask = adapter.getSaveModelTask().newInstance();
    } catch (Exception e) {
        throw new UnsupportedOperationException("Error when instantiating model serialization task");
    }
    serializationTask.addImport(metaInfoTask, MetaInfoTask.META_KEY);
    serializationTask.addImport(featuresTrainTask, ExtractFeaturesTask.OUTPUT_KEY, Constants.TEST_TASK_INPUT_KEY_TRAINING_DATA);
    serializationTask.addImport(collectionTask, OutcomeCollectionTask.OUTPUT_KEY, Constants.OUTCOMES_INPUT_KEY);
    serializationTask.setOutputFolder(outputFolder);
    serializationTask.setType(serializationTask.getType() + "-" + experimentName);
    this.tasks = new HashSet<>();
    addTask(serializationTask);
}
Also used : TcShallowLearningAdapter(org.dkpro.tc.core.ml.TcShallowLearningAdapter)

Example 3 with TcShallowLearningAdapter

use of org.dkpro.tc.core.ml.TcShallowLearningAdapter in project dkpro-tc by dkpro.

the class TcAnnotator method initMachineLearningAdapter.

private TcShallowLearningAdapter initMachineLearningAdapter(File tcModelLocation) throws Exception {
    File modelMeta = new File(tcModelLocation, MODEL_META);
    String fileContent = FileUtils.readFileToString(modelMeta, "utf-8");
    Class<?> classObj = Class.forName(fileContent);
    return (TcShallowLearningAdapter) classObj.newInstance();
}
Also used : TcShallowLearningAdapter(org.dkpro.tc.core.ml.TcShallowLearningAdapter) File(java.io.File)

Example 4 with TcShallowLearningAdapter

use of org.dkpro.tc.core.ml.TcShallowLearningAdapter in project dkpro-tc by dkpro.

the class WekaLoadModelConnector method initialize.

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    try {
        TcShallowLearningAdapter initMachineLearningAdapter = initMachineLearningAdapter(tcModelLocation);
        bipartitionThreshold = initBipartitionThreshold(tcModelLocation);
        useSparse = initMachineLearningAdapter.useSparseFeatures();
        loadClassifier();
        loadTrainingData();
        if (!learningMode.equals(Constants.LM_REGRESSION)) {
            loadClassLabels();
        }
        verifyTcVersion(tcModelLocation, getClass());
        writeFeatureMode(tcModelLocation, featureMode);
        writeLearningMode(tcModelLocation, learningMode);
    } catch (Exception e) {
        throw new ResourceInitializationException(e);
    }
}
Also used : ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) TcShallowLearningAdapter(org.dkpro.tc.core.ml.TcShallowLearningAdapter) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Aggregations

TcShallowLearningAdapter (org.dkpro.tc.core.ml.TcShallowLearningAdapter)4 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)1 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)1 ReportBase (org.dkpro.lab.reporting.ReportBase)1 ExecutableTaskBase (org.dkpro.lab.task.impl.ExecutableTaskBase)1