Search in sources :

Example 86 with ParameterSpace

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);
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace)

Example 87 with ParameterSpace

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);
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace)

Example 88 with ParameterSpace

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;
}
Also used : HashMap(java.util.HashMap) TcFeatureSet(org.dkpro.tc.api.features.TcFeatureSet) LiblinearAdapter(org.dkpro.tc.ml.liblinear.LiblinearAdapter) WekaAdapter(org.dkpro.tc.ml.weka.WekaAdapter) CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) ParameterSpace(org.dkpro.lab.task.ParameterSpace) LibsvmAdapter(org.dkpro.tc.ml.libsvm.LibsvmAdapter) XgboostAdapter(org.dkpro.tc.ml.xgboost.XgboostAdapter) LinearRegression(weka.classifiers.functions.LinearRegression) HashMap(java.util.HashMap) Map(java.util.Map)

Example 89 with ParameterSpace

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);
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace)

Example 90 with ParameterSpace

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"));
    }
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace) Test(org.junit.Test)

Aggregations

ParameterSpace (org.dkpro.lab.task.ParameterSpace)130 HashMap (java.util.HashMap)60 CollectionReaderDescription (org.apache.uima.collection.CollectionReaderDescription)51 Map (java.util.Map)45 Test (org.junit.Test)44 TcFeatureSet (org.dkpro.tc.api.features.TcFeatureSet)42 File (java.io.File)26 WekaAdapter (org.dkpro.tc.ml.weka.WekaAdapter)21 DefaultBatchTask (org.dkpro.lab.task.impl.DefaultBatchTask)12 ArrayList (java.util.ArrayList)10 LiblinearAdapter (org.dkpro.tc.ml.liblinear.LiblinearAdapter)9 NaiveBayes (weka.classifiers.bayes.NaiveBayes)9 TaskContext (org.dkpro.lab.engine.TaskContext)7 CrfSuiteAdapter (org.dkpro.tc.ml.crfsuite.CrfSuiteAdapter)7 LibsvmAdapter (org.dkpro.tc.ml.libsvm.LibsvmAdapter)7 List (java.util.List)6 XgboostAdapter (org.dkpro.tc.ml.xgboost.XgboostAdapter)6 FoldDimensionBundle (org.dkpro.lab.task.impl.FoldDimensionBundle)5 SMO (weka.classifiers.functions.SMO)5 Task (org.dkpro.lab.task.Task)4