@Test(expected = InsufficientTrainingDataException.class) public void testWithInsufficientData() throws Exception { InputStreamFactory in = new ResourceAsStreamFactory(getClass(), "/opennlp/tools/namefind/AnnotatedSentencesInsufficient.txt"); ObjectStream<NameSample> sampleStream = new NameSampleDataStream( new PlainTextByLineStream(in, StandardCharsets.ISO_8859_1)); TrainingParameters mlParams = new TrainingParameters(); mlParams.put(TrainingParameters.ITERATIONS_PARAM, 70); mlParams.put(TrainingParameters.CUTOFF_PARAM, 1); mlParams.put(TrainingParameters.ALGORITHM_PARAM, ModelType.MAXENT.toString()); TokenNameFinderCrossValidator cv = new TokenNameFinderCrossValidator("eng", TYPE, mlParams, null, (TokenNameFinderEvaluationMonitor)null); cv.evaluate(sampleStream, 2); }
public void evaluate(ObjectStream<NameSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner.next(); TokenNameFinderModel model; if (factory != null) { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, factory); } else { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, TokenNameFinderFactory.create(null, featureGeneratorBytes, resources, new BioCodec())); } TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( new NameFinderME(model), listeners); evaluator.evaluate(new DocumentToNameSampleStream(trainingSampleStream.getTestSampleStream())); fmeasure.mergeInto(evaluator.getFMeasure()); } }
TokenNameFinderCrossValidator { public void evaluate(ObjectStream<NameSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner.next(); TokenNameFinderModel model; if (factory != null) { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, factory); } else { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, TokenNameFinderFactory.create(null, featureGeneratorBytes, resources, new BioCodec())); } TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( new NameFinderME(model), listeners); evaluator.evaluate(new DocumentToNameSampleStream(trainingSampleStream.getTestSampleStream())); fmeasure.mergeInto(evaluator.getFMeasure()); } } }
TokenNameFinderCrossValidator { public void evaluate(ObjectStream<NameSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner.next(); TokenNameFinderModel model; if (factory != null) { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, factory); } else { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, TokenNameFinderFactory.create(null, featureGeneratorBytes, resources, new BioCodec())); } TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( new NameFinderME(model), listeners); evaluator.evaluate(new DocumentToNameSampleStream(trainingSampleStream.getTestSampleStream())); fmeasure.mergeInto(evaluator.getFMeasure()); } } TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources, SequenceCodec<String> codec,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, TokenNameFinderFactory factory,
      TokenNameFinderEvaluationMonitor... listeners); }
TokenNameFinderCrossValidator { public void evaluate(ObjectStream<NameSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner.next(); TokenNameFinderModel model; if (factory != null) { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, factory); } else { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, TokenNameFinderFactory.create(null, featureGeneratorBytes, resources, new BioCodec())); } TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( new NameFinderME(model), listeners); evaluator.evaluate(new DocumentToNameSampleStream(trainingSampleStream.getTestSampleStream())); fmeasure.mergeInto(evaluator.getFMeasure()); } } TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources, SequenceCodec<String> codec,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, TokenNameFinderFactory factory,
      TokenNameFinderEvaluationMonitor... listeners); void evaluate(ObjectStream<NameSample> samples, int nFolds); FMeasure getFMeasure(); }
TokenNameFinderCrossValidator { public void evaluate(ObjectStream<NameSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner.next(); TokenNameFinderModel model; if (factory != null) { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, factory); } else { model = NameFinderME.train(languageCode, type, new DocumentToNameSampleStream(trainingSampleStream), params, TokenNameFinderFactory.create(null, featureGeneratorBytes, resources, new BioCodec())); } TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( new NameFinderME(model), listeners); evaluator.evaluate(new DocumentToNameSampleStream(trainingSampleStream.getTestSampleStream())); fmeasure.mergeInto(evaluator.getFMeasure()); } } TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources, SequenceCodec<String> codec,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, byte[] featureGeneratorBytes,
      Map<String, Object> resources,
      TokenNameFinderEvaluationMonitor... listeners);  TokenNameFinderCrossValidator(String languageCode, String type,
      TrainingParameters trainParams, TokenNameFinderFactory factory,
      TokenNameFinderEvaluationMonitor... listeners); void evaluate(ObjectStream<NameSample> samples, int nFolds); FMeasure getFMeasure();  }