List of usage examples for opennlp.tools.util TrainingParameters ITERATIONS_PARAM
String ITERATIONS_PARAM
To view the source code for opennlp.tools.util TrainingParameters ITERATIONS_PARAM.
Click Source Link
From source file:io.learningbox.controller.APIController.java
@RequestMapping(value = "/categorize/{area}", method = RequestMethod.POST) public SortedMap<Double, Set<String>> categorize(@PathVariable final String area, @RequestBody String input) throws IOException { List<LearningSet> l = repository.findByArea(area); final Iterator<LearningSet> sets = l.iterator(); ObjectStream<DocumentSample> stream = new ObjectStream<DocumentSample>() { @Override// w w w.j a va 2s . c o m public DocumentSample read() throws IOException { if (sets.hasNext()) { LearningSet s = sets.next(); return new DocumentSample(s.getCategory(), s.getText()); } return null; } @Override public void reset() throws IOException, UnsupportedOperationException { throw new UnsupportedOperationException(); } @Override public void close() throws IOException { //Do nothing } }; TrainingParameters trainingParameters = TrainingParameters.defaultParams(); trainingParameters.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(1000)); trainingParameters.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(1)); DoccatModel model = DocumentCategorizerME.train("en", stream, trainingParameters, new DoccatFactory()); DocumentCategorizerME myCategorizer = new DocumentCategorizerME(model); return myCategorizer.sortedScoreMap(input); }
From source file:de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpNamedEntityRecognizerTrainer.java
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); stream = new CasNameSampleStream(); TrainingParameters params = new TrainingParameters(); params.put(TrainingParameters.ALGORITHM_PARAM, algorithm); // params.put(TrainingParameters.TRAINER_TYPE_PARAM, // TrainerFactory.getTrainerType(params.getSettings()).name()); params.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations)); params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(cutoff)); params.put(BeamSearch.BEAM_SIZE_PARAMETER, Integer.toString(beamSize)); byte featureGenCfg[] = loadFeatureGen(featureGen); Callable<TokenNameFinderModel> trainTask = () -> { try {//from w w w .j a v a 2 s. c o m return NameFinderME.train(language, null, stream, params, new TokenNameFinderFactory(featureGenCfg, Collections.<String, Object>emptyMap(), sequenceEncoding.getCodec())); } catch (Throwable e) { stream.close(); throw e; } }; future = executor.submit(trainTask); }