Search in sources :

Example 1 with TestResult

use of zemberek.ner.PerceptronNerTrainer.TestResult in project zemberek-nlp by ahmetaa.

the class EvaluateNer method run.

@Override
public void run() throws Exception {
    initializeOutputDir();
    if (hypothesisPath == null) {
        IOUtil.checkDirectoryArgument(modelRoot, "Model Root");
    } else {
        IOUtil.checkFileArgument(referencePath, "Hypothesis File");
    }
    IOUtil.checkFileArgument(referencePath, "Reference File");
    NerDataSet hypothesis;
    NerDataSet reference = NerDataSet.load(referencePath, annotationStyle);
    Log.info("Reference :");
    Log.info(reference.info());
    if (hypothesisPath == null) {
        TurkishMorphology morphology = TurkishMorphology.createWithDefaults();
        PerceptronNer ner = PerceptronNer.loadModel(modelRoot, morphology);
        Stopwatch sw = Stopwatch.createStarted();
        hypothesis = ner.evaluate(reference);
        double secs = sw.elapsed(TimeUnit.MILLISECONDS) / 1000d;
        Log.info("NER is applied to reference data in %.4f seconds.", secs);
    } else {
        hypothesis = NerDataSet.load(hypothesisPath, annotationStyle);
    }
    Log.info("Hypothesis :");
    Log.info(hypothesis.info());
    Path reportPath = outDir.resolve("eval-report");
    PerceptronNerTrainer.evaluationReport(reference, hypothesis, reportPath);
    TestResult result = PerceptronNerTrainer.collectEvaluationData(reference, hypothesis);
    Log.info("Evaluation Result:");
    Log.info(result.dump());
    Log.info("Detailed evaluation report is written in %s", reportPath);
}
Also used : Path(java.nio.file.Path) Stopwatch(com.google.common.base.Stopwatch) NerDataSet(zemberek.ner.NerDataSet) PerceptronNer(zemberek.ner.PerceptronNer) TestResult(zemberek.ner.PerceptronNerTrainer.TestResult) TurkishMorphology(zemberek.morphology.TurkishMorphology)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Path (java.nio.file.Path)1 TurkishMorphology (zemberek.morphology.TurkishMorphology)1 NerDataSet (zemberek.ner.NerDataSet)1 PerceptronNer (zemberek.ner.PerceptronNer)1 TestResult (zemberek.ner.PerceptronNerTrainer.TestResult)1