use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class LiblinearDocumentPlain method main.
public static void main(String[] args) throws Exception {
DemoUtils.setDkproHome("target/");
ParameterSpace pSpace = getParameterSpace();
LiblinearDocumentPlain experiment = new LiblinearDocumentPlain();
experiment.runTrainTest(pSpace);
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class LibsvmDocumentPlain method main.
public static void main(String[] args) throws Exception {
DemoUtils.setDkproHome("target/");
ParameterSpace pSpace = getParameterSpace();
LibsvmDocumentPlain experiment = new LibsvmDocumentPlain();
experiment.runTrainTest(pSpace);
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class MultiRegressionWekaLibsvmLiblinear method getParameterSpace.
public static ParameterSpace getParameterSpace() throws ResourceInitializationException {
// configure training and test data reader dimension
// train/test will use both, while cross-validation will only use the train part
// The reader is also responsible for setting the labels/outcome on all
// documents/instances it creates.
Map<String, Object> dimReaders = new HashMap<String, Object>();
CollectionReaderDescription readerTrain = CollectionReaderFactory.createReaderDescription(LinewiseTextOutcomeReader.class, LinewiseTextOutcomeReader.PARAM_OUTCOME_INDEX, 0, LinewiseTextOutcomeReader.PARAM_TEXT_INDEX, 1, LinewiseTextOutcomeReader.PARAM_SOURCE_LOCATION, "src/main/resources/data/essays/train/essay_train.txt", LinewiseTextOutcomeReader.PARAM_LANGUAGE, "en");
dimReaders.put(DIM_READER_TRAIN, readerTrain);
CollectionReaderDescription readerTest = CollectionReaderFactory.createReaderDescription(LinewiseTextOutcomeReader.class, LinewiseTextOutcomeReader.PARAM_OUTCOME_INDEX, 0, LinewiseTextOutcomeReader.PARAM_TEXT_INDEX, 1, LinewiseTextOutcomeReader.PARAM_SOURCE_LOCATION, "src/main/resources/data/essays/test/essay_test.txt", LinewiseTextOutcomeReader.PARAM_LANGUAGE, "en");
dimReaders.put(DIM_READER_TEST, readerTest);
Map<String, Object> xgboostConfig = new HashMap<>();
xgboostConfig.put(DIM_CLASSIFICATION_ARGS, new Object[] { new XgboostAdapter(), "booster=gbtree", "reg:linear" });
xgboostConfig.put(DIM_DATA_WRITER, new XgboostAdapter().getDataWriterClass().getName());
xgboostConfig.put(DIM_FEATURE_USE_SPARSE, new XgboostAdapter().useSparseFeatures());
Map<String, Object> liblinearConfig = new HashMap<>();
liblinearConfig.put(DIM_CLASSIFICATION_ARGS, new Object[] { new LiblinearAdapter(), "-s", "6" });
liblinearConfig.put(DIM_DATA_WRITER, new LiblinearAdapter().getDataWriterClass().getName());
liblinearConfig.put(DIM_FEATURE_USE_SPARSE, new LiblinearAdapter().useSparseFeatures());
Map<String, Object> libsvmConfig = new HashMap<>();
libsvmConfig.put(DIM_CLASSIFICATION_ARGS, new Object[] { new LibsvmAdapter(), "-s", "3", "-c", "10" });
libsvmConfig.put(DIM_DATA_WRITER, new LibsvmAdapter().getDataWriterClass().getName());
libsvmConfig.put(DIM_FEATURE_USE_SPARSE, new LibsvmAdapter().useSparseFeatures());
Map<String, Object> wekaConfig = new HashMap<>();
wekaConfig.put(DIM_CLASSIFICATION_ARGS, new Object[] { new WekaAdapter(), LinearRegression.class.getName() });
wekaConfig.put(DIM_DATA_WRITER, new WekaAdapter().getDataWriterClass().getName());
wekaConfig.put(DIM_FEATURE_USE_SPARSE, new WekaAdapter().useSparseFeatures());
Dimension<Map<String, Object>> mlas = Dimension.createBundle("config", xgboostConfig, liblinearConfig, libsvmConfig, wekaConfig);
Dimension<TcFeatureSet> dimFeatureSets = Dimension.create(DIM_FEATURE_SET, new TcFeatureSet(TcFeatureFactory.create(SentenceRatioPerDocument.class), TcFeatureFactory.create(LengthFeatureNominal.class), TcFeatureFactory.create(TokenRatioPerDocument.class)));
ParameterSpace pSpace = new ParameterSpace(Dimension.createBundle("readers", dimReaders), Dimension.create(DIM_LEARNING_MODE, LM_REGRESSION), Dimension.create(DIM_FEATURE_MODE, FM_DOCUMENT), dimFeatureSets, mlas);
return pSpace;
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class MultiRegressionWekaLibsvmLiblinear method main.
public static void main(String[] args) throws Exception {
// This is used to ensure that the required DKPRO_HOME environment variable is
// set.
// Ensures that people can run the experiments even if they haven't read the
// setup
// instructions first :)
// Don't use this in real experiments! Read the documentation and set DKPRO_HOME
// as
// explained there.
DemoUtils.setDkproHome(MultiRegressionWekaLibsvmLiblinear.class.getSimpleName());
ParameterSpace pSpace = getParameterSpace();
MultiRegressionWekaLibsvmLiblinear experiment = new MultiRegressionWekaLibsvmLiblinear();
// experiment.runTrainTest(pSpace);
experiment.runCrossValidation(pSpace);
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class KerasRegressionWassaTest method runTest.
@Test
public void runTest() throws Exception {
DemoUtils.setDkproHome(KerasRegressionWassa.class.getSimpleName());
boolean testConditon = true;
String python3 = null;
try {
python3 = getEnvironment();
} catch (Exception e) {
System.err.println("Failed to locate Python with Keras - will skip this test case");
testConditon = false;
}
if (testConditon) {
ParameterSpace ps = KerasRegressionWassa.getParameterSpace(python3);
KerasRegressionWassa.runTrainTest(ps);
assertEquals(1, ContextMemoryReport.id2outcomeFiles.size());
List<String> lines = FileUtils.readLines(ContextMemoryReport.id2outcomeFiles.get(0), "utf-8");
assertEquals(87, lines.size());
// line-wise compare
assertEquals("#ID=PREDICTION;GOLDSTANDARD;THRESHOLD", lines.get(0));
assertEquals("#labels ", lines.get(1));
assertTrue(lines.get(3).matches("0=[0-9\\.]+;0.479;-1"));
assertTrue(lines.get(4).matches("1=[0-9\\.]+;0.458;-1"));
assertTrue(lines.get(5).matches("10=[0-9\\.]+;0.646;-1"));
assertTrue(lines.get(6).matches("11=[0-9\\.]+;0.726;-1"));
assertTrue(lines.get(7).matches("12=[0-9\\.]+;0.348;-1"));
assertTrue(lines.get(8).matches("13=[0-9\\.]+;0.417;-1"));
assertTrue(lines.get(9).matches("14=[0-9\\.]+;0.202;-1"));
assertTrue(lines.get(10).matches("15=[0-9\\.]+;0.557;-1"));
}
}
Aggregations