Ejemplo n.º 1
0
        public static void PredictDocument()
        {
            // <SnippetLoadModel>
            ITransformer loadedModel = _mlContext.Model.Load(_modelPath, out var modelInputSchema);
            // </SnippetLoadModel>

            // <SnippetAddTestIssue>
            // Correct Type: 5
            CustomerMessage sample = new CustomerMessage()
            {
                Contents = "Favor realizar cambio de plan a los abonados:  989990999 / 999999090  Plan actual ZVB, favor cambiar plan y dejar activo plan ZVC de 8GB.  Agradecido. Saludos. SA"
            };

            // </SnippetAddTestIssue>

            //Predict label for single hard-coded issue
            // <SnippetCreatePredictionEngine>
            _predEngine = _mlContext.Model.CreatePredictionEngine <CustomerMessage, MessageTypePrediction>(loadedModel);
            // </SnippetCreatePredictionEngine>

            // <SnippetPredictIssue>
            var prediction = _predEngine.Predict(sample);

            // </SnippetPredictIssue>

            // <SnippetDisplayResults>
            Console.WriteLine($"=============== Single Prediction - Result: {prediction.TypeCode} ===============");
            // </SnippetDisplayResults>
        }
Ejemplo n.º 2
0
        public static IEstimator <ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator <ITransformer> pipeline)
        {
            // STEP 3: Create the training algorithm/trainer
            // Use the multi-class SDCA algorithm to predict the label using features.
            // Set the trainer/algorithm and map label to value (original readable state)
            // <SnippetAddTrainer>
            var trainingPipeline =
                pipeline.Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "ContentsFeaturized"))
                .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            // </SnippetAddTrainer>

            // STEP 4: Train the model fitting to the DataSet
            Console.WriteLine($"=============== Training the model  ===============");

            // <SnippetTrainModel>
            _trainedModel = trainingPipeline.Fit(trainingDataView);
            // </SnippetTrainModel>
            Console.WriteLine($"=============== Finished Training the model Ending time: {DateTime.Now.ToString()} ===============");

            // (OPTIONAL) Try/test a single prediction with the "just-trained model" (Before saving the model)

            // Create prediction engine related to the loaded trained model
            // <SnippetCreatePredictionEngine1>
            _predEngine = _mlContext.Model.CreatePredictionEngine <CustomerMessage, MessageTypePrediction>(_trainedModel);
            // </SnippetCreatePredictionEngine1>

            // Original type: 2 ALTA
            CustomerMessage sample = new CustomerMessage();

            sample.Contents = "Necesito que por favor habiliten el numero +99 9 8999 9009  para realizar llamadas internacionales, principalmente Brasil";
            var prediction = _predEngine.Predict(sample);

            Console.WriteLine($"Prediction just-trained-model - {sample.Contents}\nResult: {prediction.TypeCode} ===============");

            // Original type: 3 BAJA
            sample.Contents = "Estimados  Favor solicito bajar servicio , Roaming ,Larga distancia internacional y SMS ( Solo emisión ) a los celulares";
            prediction      = _predEngine.Predict(sample);
            Console.WriteLine($"Prediction just-trained-model - {sample.Contents}\nResult: {prediction.TypeCode} ===============");

            // Original type: 9 Reclamo
            sample.Contents = "esta mañana realicé req 999999, el cual ustedes lo finalizaron, adjuntando un pdf, el requerimiento fue otro, el cual indica que la plataforma no funciona, ¿cuando estará disponible?";
            prediction      = _predEngine.Predict(sample);
            Console.WriteLine($"Prediction just-trained-model - {sample.Contents}\nResult: {prediction.TypeCode} ===============");

            // Original type: 9 RECLAMO
            sample.Contents = "Buen día tengo problemas de comunicación no se puede realizar ni recibir llamados es urgente las lineas son";
            prediction      = _predEngine.Predict(sample);
            Console.WriteLine($"Prediction just-trained-model - {sample.Contents}\nResult: {prediction.TypeCode} ===============");

            // <SnippetReturnModel>
            return(trainingPipeline);
            // </SnippetReturnModel>
        }