Exemplo n.º 1
0
        public static void PredictSentiment(MLContext mlContext, ITransformer model)
        {
            // <SnippetCreatePredictionEngine>
            var engine = mlContext.Model.CreatePredictionEngine <MovieReview, MovieReviewSentimentPrediction>(model);
            // </SnippetCreatePredictionEngine>

            // <SnippetCreateTestData>
            var review = new MovieReview()
            {
                ReviewText = "this film is really good"
            };
            // </SnippetCreateTestData>

            // Predict with TensorFlow pipeline.
            // <SnippetPredict>
            var sentimentPrediction = engine.Predict(review);

            // </SnippetPredict>

            // <SnippetDisplayPredictions>
            Console.WriteLine("Number of classes: {0}", sentimentPrediction.Prediction.Length);
            Console.WriteLine("Is sentiment/review positive? {0}", sentimentPrediction.Prediction[1] > 0.5 ? "Yes." : "No.");
            Console.WriteLine("Prediction Confidence: {0}", sentimentPrediction.Prediction[1] > 0.5 ? sentimentPrediction.Prediction[1]: sentimentPrediction.Prediction[0]);
            // </SnippetDisplayPredictions>

            /////////////////////////////////// Expected output ///////////////////////////////////
            //
            // Name: Features, Type: System.Int32, Size: 600
            // Name: Prediction/Softmax, Type: System.Single, Size: 2
            //
            // Number of classes: 2
            // Is sentiment/review positive ? Yes
            // Prediction Confidence: 0.65
        }
Exemplo n.º 2
0
        public static void PredictSentiment(MLContext mlContext, ITransformer model)
        {
            var engine = mlContext.Model.CreatePredictionEngine <MovieReview, MovieReviewSentimentPrediction>(model);
            var review = new MovieReview()
            {
                ReviewText = "really beautiful movie"
            };
            var sentimentPrediction = engine.Predict(review);

            Console.WriteLine("Number of classes: {0}", sentimentPrediction.Prediction.Length);
            Console.WriteLine("Is sentiment/review positive? {0}", sentimentPrediction.Prediction[1] > 0.5 ? "Yes." : "No.");
        }