SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), errorListener); evaluator.evaluate(sampleStream); System.out.println(evaluator.getFMeasure());
@Override protected SentenceSample processSample(SentenceSample sample) { Span[] predictions = trimSpans(sample.getDocument(), sentenceDetector.sentPosDetect(sample.getDocument())); Span[] references = trimSpans(sample.getDocument(), sample.getSentences()); fmeasure.updateScores(references, predictions); return new SentenceSample(sample.getDocument(), predictions); }
@Test public void testPositive() throws InvalidFormatException { OutputStream stream = new ByteArrayOutputStream(); SentenceDetectorEvaluationMonitor listener = new SentenceEvaluationErrorListener(stream); SentenceDetectorEvaluator eval = new SentenceDetectorEvaluator(new DummySD( SentenceSampleTest.createGoldSample()), listener); eval.evaluateSample(SentenceSampleTest.createGoldSample()); Assert.assertEquals(1.0, eval.getFMeasure().getFMeasure(), 0.0); Assert.assertEquals(0, stream.toString().length()); }
/** * Starts the evaluation. * * @param samples * the data to train and test * @param nFolds * number of folds * * @throws IOException */ public void evaluate(ObjectStream<SentenceSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<SentenceSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<SentenceSample> trainingSampleStream = partitioner.next(); SentenceModel model; model = SentenceDetectorME.train(languageCode, trainingSampleStream, sdFactory, params); // do testing SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }
@Test public void testNegative() throws InvalidFormatException { OutputStream stream = new ByteArrayOutputStream(); SentenceDetectorEvaluationMonitor listener = new SentenceEvaluationErrorListener(stream); SentenceDetectorEvaluator eval = new SentenceDetectorEvaluator(new DummySD( SentenceSampleTest.createGoldSample()), listener); eval.evaluateSample(SentenceSampleTest.createPredSample()); Assert.assertEquals(-1.0, eval.getFMeasure().getFMeasure(), .1d); Assert.assertNotSame(0, stream.toString().length()); }
@Override protected SentenceSample processSample(SentenceSample sample) { Span[] predictions = trimSpans(sample.getDocument(), sentenceDetector.sentPosDetect(sample.getDocument())); Span[] references = trimSpans(sample.getDocument(), sample.getSentences()); fmeasure.updateScores(references, predictions); return new SentenceSample(sample.getDocument(), predictions); }
SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), errorListener); evaluator.evaluate(sampleStream); System.out.println(evaluator.getFMeasure());
@Override protected SentenceSample processSample(SentenceSample sample) { Span[] predictions = trimSpans(sample.getDocument(), sentenceDetector.sentPosDetect(sample.getDocument())); Span[] references = trimSpans(sample.getDocument(), sample.getSentences()); fmeasure.updateScores(references, predictions); return new SentenceSample(sample.getDocument(), predictions); }
SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), errorListener); evaluator.evaluate(sampleStream); System.out.println(evaluator.getFMeasure());
/** * Starts the evaluation. * * @param samples * the data to train and test * @param nFolds * number of folds * * @throws IOException */ public void evaluate(ObjectStream<SentenceSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<SentenceSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<SentenceSample> trainingSampleStream = partitioner.next(); SentenceModel model; model = SentenceDetectorME.train(languageCode, trainingSampleStream, sdFactory, params); // do testing SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }
/** * Starts the evaluation. * * @param samples * the data to train and test * @param nFolds * number of folds * * @throws IOException */ public void evaluate(ObjectStream<SentenceSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<SentenceSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<SentenceSample> trainingSampleStream = partitioner.next(); SentenceModel model; model = SentenceDetectorME.train(languageCode, trainingSampleStream, sdFactory, params); // do testing SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator( new SentenceDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }