Evaluating the model using the SentenceDetectorEvaluator class

We reserved a part of the sample file for evaluation purposes so that we can use the SentenceDetectorEvaluator class to evaluate the model. We modified the sentence.train file by extracting the last 10 sentences and placing them in a file called evalSample. Then, we used this file to evaluate the model. In the following example, we've reused the lineStream and sampleStream variables to create a stream of SentenceSample objects based on the file's contents:

lineStream = new PlainTextByLineStream(
new FileReader("evalSample")); sampleStream = new SentenceSampleStream(lineStream);

An instance of the SentenceDetectorEvaluator class is created using the previously created SentenceDetectorME class variable, detector. The second argument of the constructor is a SentenceDetectorEvaluationMonitor object, which we will not use here. Then, the evaluate method is called:

SentenceDetectorEvaluator sentenceDetectorEvaluator 
    = new SentenceDetectorEvaluator(detector, null); 
sentenceDetectorEvaluator.evaluate(sampleStream); 

The getFMeasure method will return an instance of the FMeasure class, which provides measurements of the quality of the model:

System.out.println(sentenceDetectorEvaluator.getFMeasure()); 

The output follows. Precision is the fraction of correct instances that are included, and recall reflects the sensitivity of the model. F-measure is a score that combines recall and precision. In essence, it reflects how well the model works. It is best to keep the precision above 90% for tokenization and SBD tasks:

    Precision: 0.8181818181818182
    Recall: 0.9
    F-Measure: 0.8571428571428572

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset