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);
}
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);
}
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();
}
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);
}
}
Aggregations