예제 #1
0
        public override void run(string format, string[] args)
        {
            base.run(format, args);

            TokenNameFinderModel model = (new TokenNameFinderModelLoader()).load(@params.Model);

            IList <EvaluationMonitor <NameSample> > listeners = new LinkedList <EvaluationMonitor <NameSample> >();

            if (@params.Misclassified.Value)
            {
                listeners.Add(new NameEvaluationErrorListener());
            }
            TokenNameFinderDetailedFMeasureListener detailedFListener = null;

            if (@params.DetailedF.Value)
            {
                detailedFListener = new TokenNameFinderDetailedFMeasureListener();
                listeners.Add(detailedFListener);
            }

            TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator(new NameFinderME(model), listeners.ToArray());

            PerformanceMonitor monitor = new PerformanceMonitor("sent");

            ObjectStream <NameSample> measuredSampleStream = new ObjectStreamAnonymousInnerClassHelper(this, monitor);

            monitor.startAndPrintThroughput();

            try
            {
                evaluator.evaluate(measuredSampleStream);
            }
            catch (IOException e)
            {
                Console.Error.WriteLine("failed");
                throw new TerminateToolException(-1, "IO error while reading test data: " + e.Message, e);
            }
            finally
            {
                try
                {
                    measuredSampleStream.close();
                }
                catch (IOException)
                {
                    // sorry that this can fail
                }
            }

            monitor.stopAndPrintFinalResult();

            Console.WriteLine();

            if (detailedFListener == null)
            {
                Console.WriteLine(evaluator.FMeasure);
            }
            else
            {
                Console.WriteLine(detailedFListener.ToString());
            }
        }
예제 #2
0
        public override void run(string format, string[] args)
        {
            base.run(format, args);

            mlParams = CmdLineUtil.loadTrainingParameters(@params.Params, false);
            if (mlParams == null)
            {
                mlParams = ModelUtil.createTrainingParameters(@params.Iterations.Value, @params.Cutoff.Value);
            }

            sbyte[] featureGeneratorBytes = TokenNameFinderTrainerTool.openFeatureGeneratorBytes(@params.Featuregen);

            IDictionary <string, object> resources = TokenNameFinderTrainerTool.loadResources(@params.Resources);

            IList <EvaluationMonitor <NameSample> > listeners = new LinkedList <EvaluationMonitor <NameSample> >();

            if (@params.Misclassified.Value)
            {
                listeners.Add(new NameEvaluationErrorListener());
            }
            TokenNameFinderDetailedFMeasureListener detailedFListener = null;

            if (@params.DetailedF.Value)
            {
                detailedFListener = new TokenNameFinderDetailedFMeasureListener();
                listeners.Add(detailedFListener);
            }

            TokenNameFinderCrossValidator validator;

            try
            {
                validator = new TokenNameFinderCrossValidator(@params.Lang, @params.Type, mlParams, featureGeneratorBytes, resources, listeners.ToArray());
                validator.evaluate(sampleStream, @params.Folds.Value);
            }
            catch (IOException e)
            {
                throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.Message, e);
            }
            finally
            {
                try
                {
                    sampleStream.close();
                }
                catch (IOException)
                {
                    // sorry that this can fail
                }
            }

            Console.WriteLine("done");

            Console.WriteLine();

            if (detailedFListener == null)
            {
                Console.WriteLine(validator.FMeasure);
            }
            else
            {
                Console.WriteLine(detailedFListener.ToString());
            }
        }