private static List <ConversationInput> LoadFromXml() { var result = new List <ConversationInput>(); var document = new XmlDocument(); document.Load("questions.xml"); var posts = document.LastChild.LastChild.ChildNodes; int i = 0; foreach (XmlNode post in posts) { try { i++; var inputRow = new ConversationInput(); inputRow.Description = post.FirstChild.Value; inputRow.Area = post.Attributes["class"].Value; //inputRow.Title = post.FirstChild.Value; //inputRow.ClassificationOutput = (uint) (post.Attributes["class"].Value.Contains("Question") ? 1 : 0); result.Add(inputRow); } catch (Exception) { } if (i == 1000) { break; } } return(result); }
public static void PredictIssue() { // <SnippetLoadModel> ITransformer loadedModel = _mlContext.Model.Load(_modelPath, out var modelInputSchema); // </SnippetLoadModel> // <SnippetAddTestIssue> ConversationInput singleIssue = new ConversationInput() { Description = "When connecting to the database, EF is crashing" }; //ConversationInput singleIssue = new ConversationInput() { Description = "What is your name"}; // </SnippetAddTestIssue> //Predict label for single hard-coded issue // <SnippetCreatePredictionEngine> _predEngine = _mlContext.Model.CreatePredictionEngine <ConversationInput, SentenceClassifiedOutput>(loadedModel); // </SnippetCreatePredictionEngine> // <SnippetPredictIssue> var prediction = _predEngine.Predict(singleIssue); // </SnippetPredictIssue> // <SnippetDisplayResults> //Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ==============="); // </SnippetDisplayResults> }
private void btnTestSentence_Click(object sender, EventArgs e) { var _mlContext = new MLContext(seed: 0); ITransformer _trainedModel = _mlContext.Model.Load("model.zip", out DataViewSchema inputSchema); PredictionEngine <ConversationInput, SentenceClassifiedOutput> _predEngine = _mlContext.Model.CreatePredictionEngine <ConversationInput, SentenceClassifiedOutput>(_trainedModel); ConversationInput issue = new ConversationInput() { Description = txtInput.Text }; var prediction = _predEngine.Predict(issue); txtOutPut.Text = prediction.Area; }
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", "Features")) .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) //Console.WriteLine($"=============== Single Prediction just-trained-model ==============="); // Create prediction engine related to the loaded trained model // <SnippetCreatePredictionEngine1> _predEngine = _mlContext.Model.CreatePredictionEngine <ConversationInput, SentenceClassifiedOutput>(_trainedModel); // </SnippetCreatePredictionEngine1> // <SnippetCreateTestIssue1> ConversationInput issue = new ConversationInput() { //Title = "WebSockets communication is slow in my machine", Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.." }; // </SnippetCreateTestIssue1> // <SnippetPredict> var prediction = _predEngine.Predict(issue); // </SnippetPredict> // <SnippetOutputPrediction> //Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ==============="); // </SnippetOutputPrediction> // <SnippetReturnModel> return(trainingPipeline); // </SnippetReturnModel> }