Through our tools and frameworks..NET has been a great platform for building any kind of application ranging from desktop, web, Cloud. Mobile, gaming, IoT and now I’ll show you how easy it is to build machine learning applications with.NET. ML.NET is a machine learning framework for.NET developers. You can build your own models. It’s proven and extensible, it’s been used heavily inside of Microsoft across all groups. It’s open source and cross-platform, so it works on Windows Mac and Linux and it’s highly developer focused in terms of the scenarios that we’re enabling and how you can build with ML.NET. ML.NET is available at.NET/ML. Here are some of the machine learning scenarios we are targeting with ML.NET. You can do sentiment analysis, issue classification, ranking, image classification, forecasting, predictive maintenance, recommendation.
The idea behind these is all of the developers know scenarios versus knowing ML task, so we’re making ML.NET, very approachable for.NET developers. ML.NET is proven at scale. It’s enterprise ready. Microsoft has been using internally ML.NET for the last 10 years across various products. If you’ve seen Bing ads or you’ve done Chart Recommendations, Design Ideas in PowerPoint, Windows Defender, Anomaly Detection in Azure Stream Analytics, Key Influencers in Power BI and a lot more product groups using ML.NET at scale that over years, we’ve made the Machine Learning tech behind it perform much better by dog-fooding this ourselves. Beyond our internal customers, we have lots of external customers using ML.NET at scale in production as well.
SigParser is an example of a customer using ML.NET. SigParser is trying to make the CRM management much easier by automating various tasks around e-mail parsing, e-mail classification, entity extraction, and here’s an example use case of SigParser using ML.NET.
With ML.NET, they were able to train the model and immediately test inside of the code. This makes shipping new changes faster because all of the tooling was in one place. The great benefit of ML.NET is a developer focus framework, so it integrates to your existing tool sets across CLI, across Visual Studio, across DevOps, across CI/CD. So it is just another .NET library that you would use in your application. SigParser was able to take these advantages of ML.NET and improve their productivity for their own business.
So I’m going to show you ML.NET in action right now. We’ll look at an example of how can we do sentiment analysis using ML.NET. Let me explain you a few concepts before we see the demo. This is an example dataset for doing sentiment analysis.
It is the Wikipedia detox data and it has two columns. One is the common column and the other is the toxic column, whether this piece of comment is toxic or not. We’ll split this column data into two categories. One column becomes the features, which are the data that we’ll use to train the model, and the second column is going to become the label or the output or the column that we’re going to predict. So simply put, Sentiment Analysis is a problem where we’re trying to classify our text into two categories A or B.
In this case, is the comment tag toxic or not. So we’ll get a yes or no answer. At its very core, here is an example of a typical machine learning workflow process. The first step in this process is to prepare your data, where you load this data in our case, the Wikipedia detox dataset will extract features, in our case, we’ll extract the commons as a feature.
Then we’ll train the model and we’ll evaluate the model. Eventually we’ll test the model in production. So let us see how this sentiment analysis looks like in practice inside Visual Studio 2019. Here is a sample application showing you how you can do sentiment analysis using ML.NET. This is a console application and the dataset is the same dataset I showed you where I have two columns, Sentiment and SentimentText, and I’m going to debug through this application to show you how easy it is to build a Sentiment Analysis model in ML.NET.
The first step in this process is to [inaudible] Context, and then we load our training data. In our case, we are loading the Wikipedia detox dataset that we just saw. In the third step, we are building the pipeline. This is where we will extract the data, we can extract our features. In this case, we have the features column as a comment, and we’re going to predict the output which is going to be our Sentiment. Since it’s a type of binary classification problem, I’ve added this SDC alone to my pipeline. So after building this pipeline, I’m going to call a training on this dataset.
So I’m going to call pipeline. Fit, which is going to take the pipeline that we built earlier. It’s going to train and build a model against my training dataset, and then I’m going to test my data against my test data to see how the model performed. So if I go back to my console, we see that we got the model of accuracy 70 percent, which is not bad for this dataset.
Then after I’ve built the model, I’m going to try out this model with my own data. So in this case, I’m creating a new type called Sentiment Data, I’m giving this input to the model that I just built. So if I step over this, we’ll see what was the predicted Sentiment for this text. Ml.NET is fun, The Sentiment was positive.
The last step in our process is to save the model, so I can save the model as a binary artifact as a zip file. So I can take it and load it from any other application that.NET is running on, so it could be a web app, mobile app, it could be running on the Edge, it could be running on the Cloud.
It’s just an artifact of your document project that you can run. So let me run through this application. You’ll see I loaded my data in this application, I extracted the features, I built the model, then I trained the model, then I evaluated the model and then I use the model on my own dataset. So this was very easy for me to get started with ML.NET and build a sentiment analysis model. Let’s switch to Image Classification. ML.NET not only supports classical machine learning scenarios like text classification or price prediction or recommendation, it also supports deep learning scenarios. I’m going to show you how you can do image classification with a model built using TensorFlow.
Deep learning is a revolutionizing space which includes vision and speech recognition. It’s very useful when you have lots of data to train your neural network. In our example I’ll show you how to classify an image whether it’s a dog or not a dog. In this case, we’ll use a pretrained TensorFlow model called Inception to classify these images. So let’s go ahead and see this application in practice. This is my dataset that I’m going to use to predict whether an image is a broccoli or not, or a canoe or not, or a teddy or not. So I have these different images that I’ve captured. I’ve built this console application where I’m going to build a ML.NET pipeline to load a pretrained TensorFlow model and then use it inside a.NET application to classify these images.
So let’s go ahead and run this application. The first step in our application is to load the model and in this case, we are loading a model into the ML Context pipeline. This is the parts to the way that all the images are stored. I’m doing some basic transformations on the images in terms of resizing and extracting pixel, and I am then using the pretrained TensorFlow model to train this ML.NET pipeline. So let’s go ahead and run this function. So far we have loaded the model And in this section, we will use the loaded model to take each image and classify the type of this image. So in this code over here, I’m reading all the images and I’m predicting what’s the output classification for this image. So let’s go ahead and run this program.
It’ll iterate over all the images and it’ll give me what was the output prediction with a probability score. So you can see it predicted some of these images correctly, like the coffee pot was predicted incorrectly and the probability was 60 percent. So you get these metrics to figure out whether the predictions are happening correctly or not. So this was a quick and easy way to use retained TensorFlow models in ML.NET for image classification. So I hope you enjoyed this short video about ML.NET in Visual Studio 2019. ML.NET is the framework for.NET developers to use Machine Learning. It’s open source and it’s proven our scale since it’s being used internally at Microsoft. I showed you an example of how to do Sentiment Analysis and Image Classification.
Read More: Now create your own AI Assistant with few simple steps!