Ejemplo n.º 1
0
        public ClassificationResult Test()
        {
            var result = new ClassificationResult("Test");

            foreach (var entry in dataSet.TestData)
            {
                var newX = SVMProblemBuilder.CreateNode(entry.stemmedClaim, dataSet.Vocabulary);
                var predictedSentiment = model.Predict(newX);
                var probability        = model.PredictProbabilities(newX);

                result.AddPrediction(entry.topicId, probability.Max(pair => pair.Value), entry.IsPredictionCorrect(predictedSentiment));
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static void Test(DataSet dataSet, IStemmer stemmer, string word2VecPath, bool cacheResults)
        {
            var progress = new ProgressReporting(dataSet.TestData.Count);

            var sentimentClassifier   = new ClaimSentimentIdentificator(stemmer);
            var targetIdentificator   = new TargetIdentificator(word2VecPath);
            var contrastClassifier    = new ContrastClassifier();
            var targetResult          = new ClassificationResult("Target Identification");
            var simpleSentimentResult = new ClassificationResult("Simple Sentiment");
            var simpleSentimentWithoutContrastResult = new ClassificationResult("Simple Sentiment without Contrast");
            var sentimentResult = new ClassificationResult("Sentiment");
            var sentimentWithoutContrastResult             = new ClassificationResult("Sentiment without Contrast");
            var sentimentAndConstrastResult                = new ClassificationResult("Sentiment and Contrast");
            var sentimentWithKnownTargetResult             = new ClassificationResult("Sentiment with known target");
            var sentimentAndConstrastWithKnownTargetResult = new ClassificationResult("Sentiment and Contrast with known Target");

            foreach (var entry in dataSet.TestData)
            {
                //target identificator
                var target = targetIdentificator.GetNounPhrase(entry.claim, entry.target);
                targetResult.AddPrediction(entry.topicId, 1, IsSignificantlyOverlapping(target.PhraseArray, entry.claimTarget));

                //simple sentiment analyzer
                double simpleSentiment = sentimentClassifier.GetUnweightedSentiment(entry);
                double confidence      = Math.Abs(simpleSentiment);
                bool   isCorrect       = entry.IsPredictionCorrect(simpleSentiment);
                simpleSentimentResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //simple sentiment (ignoring contrast)
                isCorrect = entry.IsPredictionCorrect(simpleSentiment * entry.targetsRelation);
                simpleSentimentWithoutContrastResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //targeted sentiment analyzer
                double sentiment = sentimentClassifier.GetTargetedSentiment(entry, target.PhraseArray);
                confidence = Math.Abs(sentiment);
                isCorrect  = entry.IsPredictionCorrect(sentiment);
                sentimentResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //targeted sentiment analzyer + known contrast
                confidence *= contrastClassifier.GetConsistency(entry);
                sentimentAndConstrastResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //targeted sentiment (ignoring contrast)
                isCorrect = entry.IsPredictionCorrect(sentiment * entry.targetsRelation);
                sentimentWithoutContrastResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //targeted sentiment analyzer but using known target
                sentiment  = sentimentClassifier.GetTargetedSentiment(entry, entry.claimTarget);
                confidence = Math.Abs(sentiment);
                isCorrect  = entry.IsPredictionCorrect(sentiment);
                sentimentWithKnownTargetResult.AddPrediction(entry.topicId, confidence, isCorrect);

                //targeted sentiment analyzer but using known target + known contrast
                confidence *= contrastClassifier.GetConsistency(entry);
                sentimentAndConstrastWithKnownTargetResult.AddPrediction(entry.topicId, confidence, isCorrect);

                progress.Increment();
            }

            if (cacheResults)
            {
                targetIdentificator.SaveCache();
            }

            //unigrams svm
            OutputBaselineResults(dataSet, 3);

            Console.WriteLine(targetResult);
            Console.WriteLine(simpleSentimentResult);
            Console.WriteLine(simpleSentimentWithoutContrastResult);
            Console.WriteLine(sentimentResult);
            Console.WriteLine(sentimentAndConstrastResult);
            Console.WriteLine(sentimentWithoutContrastResult);

            Console.WriteLine(sentimentWithKnownTargetResult);
            Console.WriteLine(sentimentAndConstrastWithKnownTargetResult);

            Console.ReadLine();
        }