use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class SVMHMMSaveAndLoadModelTest method loadModel.
@Test
public void loadModel() throws Exception {
// create a model
File modelFolder = folder.newFolder();
ParameterSpace pSpace = getParameterSpace();
executeSaveModelIntoTemporyFolder(pSpace, modelFolder);
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("This is an example text. It has 2 sentences.");
jcas.setDocumentLanguage("en");
AnalysisEngine tokenizer = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class);
AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath(), TcAnnotator.PARAM_NAME_SEQUENCE_ANNOTATION, Sentence.class.getName(), TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName());
tokenizer.process(jcas);
tcAnno.process(jcas);
List<TextClassificationOutcome> outcomes = new ArrayList<>(JCasUtil.select(jcas, TextClassificationOutcome.class));
Set<String> possibleOutcome = new HashSet<>();
possibleOutcome.add("NN");
possibleOutcome.add("AT");
possibleOutcome.add("DT");
possibleOutcome.add("JJ");
possibleOutcome.add("pct");
possibleOutcome.add("PPS");
possibleOutcome.add("VBG");
possibleOutcome.add("DOD");
possibleOutcome.add("IN");
possibleOutcome.add("VBD");
possibleOutcome.add("VB");
possibleOutcome.add("BEDZ");
possibleOutcome.add("VBN");
possibleOutcome.add("RB");
possibleOutcome.add("NNS");
// 9 token + 2 punctuation marks
assertEquals(11, outcomes.size());
for (TextClassificationOutcome o : outcomes) {
System.out.println(o.getOutcome());
assertTrue(possibleOutcome.contains(o.getOutcome()));
}
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class KerasDocumentTrainTest method getParameterSpace.
public static ParameterSpace getParameterSpace(String python3) throws ResourceInitializationException {
// configure training and test data reader dimension
// train/test will use both, while cross-validation will only use the train part
Map<String, Object> dimReaders = new HashMap<String, Object>();
CollectionReaderDescription readerTrain = CollectionReaderFactory.createReaderDescription(FolderwiseDataReader.class, FolderwiseDataReader.PARAM_SOURCE_LOCATION, corpusFilePathTrain, FolderwiseDataReader.PARAM_LANGUAGE, LANGUAGE_CODE, FolderwiseDataReader.PARAM_PATTERNS, "*/*.txt");
dimReaders.put(DIM_READER_TRAIN, readerTrain);
CollectionReaderDescription readerTest = CollectionReaderFactory.createReaderDescription(FolderwiseDataReader.class, FolderwiseDataReader.PARAM_SOURCE_LOCATION, corpusFilePathTest, FolderwiseDataReader.PARAM_LANGUAGE, LANGUAGE_CODE, FolderwiseDataReader.PARAM_PATTERNS, "*/*.txt");
dimReaders.put(DIM_READER_TEST, readerTest);
ParameterSpace pSpace = new ParameterSpace(Dimension.createBundle("readers", dimReaders), Dimension.create(DIM_FEATURE_MODE, Constants.FM_DOCUMENT), Dimension.create(DIM_LEARNING_MODE, Constants.LM_SINGLE_LABEL), Dimension.create(DeepLearningConstants.DIM_PYTHON_INSTALLATION, "/usr/local/bin/python3"), Dimension.create(DeepLearningConstants.DIM_USER_CODE, "src/main/resources/kerasCode/singleLabel/imdb_cnn_lstm.py"), Dimension.create(DeepLearningConstants.DIM_MAXIMUM_LENGTH, 100), Dimension.create(DeepLearningConstants.DIM_VECTORIZE_TO_INTEGER, true), Dimension.create(DeepLearningConstants.DIM_PRETRAINED_EMBEDDINGS, "src/test/resources/wordvector/glove.6B.50d_250.txt"));
return pSpace;
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class KerasDocumentTrainTest method main.
public static void main(String[] args) throws Exception {
// DemoUtils.setDkproHome(DeepLearningTestDummy.class.getSimpleName());
System.setProperty("DKPRO_HOME", System.getProperty("user.home") + "/Desktop");
ParameterSpace pSpace = getParameterSpace("/usr/local/bin/python3");
KerasDocumentTrainTest.runTrainTest(pSpace);
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class KerasRegression method getParameterSpace.
public static ParameterSpace getParameterSpace(String pythonPath) throws ResourceInitializationException {
// configure training and test data reader dimension
// train/test will use both, while cross-validation will only use the train part
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/train/essay_test.txt", LinewiseTextOutcomeReader.PARAM_LANGUAGE, "en");
dimReaders.put(DIM_READER_TEST, readerTest);
ParameterSpace pSpace = new ParameterSpace(Dimension.createBundle("readers", dimReaders), Dimension.create(DIM_FEATURE_MODE, Constants.FM_DOCUMENT), Dimension.create(DIM_LEARNING_MODE, Constants.LM_REGRESSION), Dimension.create(DeepLearningConstants.DIM_PYTHON_INSTALLATION, pythonPath), Dimension.create(DeepLearningConstants.DIM_USER_CODE, "src/main/resources/kerasCode/regression/essay.py"), Dimension.create(DeepLearningConstants.DIM_MAXIMUM_LENGTH, 100), Dimension.create(DeepLearningConstants.DIM_VECTORIZE_TO_INTEGER, true), Dimension.create(DeepLearningConstants.DIM_PRETRAINED_EMBEDDINGS, "src/test/resources/wordvector/glove.6B.50d_250.txt"));
return pSpace;
}
use of org.dkpro.lab.task.ParameterSpace in project dkpro-tc by dkpro.
the class KerasRegression method main.
public static void main(String[] args) throws Exception {
// DemoUtils.setDkproHome(DeepLearningTestDummy.class.getSimpleName());
System.setProperty("DKPRO_HOME", System.getProperty("user.home") + "/Desktop");
ParameterSpace pSpace = getParameterSpace("/usr/local/bin/python3");
KerasRegression.runCrossValidation(pSpace);
}
Aggregations