Loading...

easy access to Machine Learning with ML.Net

Published
25-03-2019

introduction

Machine Learning development generally involves many or all of the following steps:

  • creating an account in a cloud environment such as Paperspace;
  • learning a lot of unix commands;
  • coding in Python;
  • accessing a virtual machine to work with its folders and contents.

For most Microsoft developers, who are used to coding directly on their own PC using Visual Studio, in languages such as C# or VB, this is all just too painful. As a result, the bulk of Microsoft developers tend to ignore, or just read and dream about Machine Learning and Artificial Intelligence.   

With Machine Learning .Net however all this changes. Using Machine Learning and incorporating it into existing websites and applications is dead simple. In fact, it's as simple as just adding a Nuget package. From the command line that would be "dotnet add package Microsoft.ML --version 0.11.0" .

background

Microsoft has for several years made Azure Machine Learning Studios available as an Azure service. These provide highly advanced, off the shelf models, templates and pipelines that enable developers to get started quickly in familiar .Net languages (and other languages, such as R and Python). Whilst these are excellent, they do involve the use of Azure. For developers working in corporate environments, where the choice of cloud services is not up to them, using Azure may simply not be an option.

In addition, most development in Machine Learning and Artificial Intelligence is done in some way using publicly available Python libraries. Therefore, most C# or VB developers who wanted to get started in Machine Learning within their corporate environment would find themselves using Python, perhaps with an in-house cloud or grid computing environment.  

Therefore, making Machine Learning .Net available as a Nuget package to use in an existing project, should be very welcome news for .Net developers.

getting started

Getting started is extremely simple, and works as promised in a new DotNet Core project. Rather than repeat what are very simple instructions, here is the link I followed to get started.

ease of use

This approach offers huge potential for DotNet developers. Getting started with sophisticated techniques is possible, even for developers who know nothing about Machine Learning, except that it involves models and predictions. ML.Net also provides hooks to extend or change the workings of the models and tools that are provided out of the box, and the opportunity to configure the data processing pipeline.

Therefore, it's possible for DotNet shops with no experience of Machine Learning, to commence programming Machine Learning and, over time, improve their knowlege and skills in the area using familiar programming languages such as C#, and IDEs such as Visual Studio. 

The bar to using Machine Learning in DotNet environments is therefore now a lot lower. 

working example

It was easy enough to create a working example of a Machine Learning model using ML.Net and then incorporate it into this web site. This was done by:

  • putting the Machine Learning model into a class library;
  • calling the class library from a DotNet Core Web API;
  • calling the API from an Angular service;
  • calling the Angular service from an Angular component.

This worked perectly locally and I could copy and paste sentences from restaurant reviews and get accurate predictions from the Machine Learning model as to whether the review were positive or negative.

Unfortunately, this website runs as an App Service in Azure. Publishing the site to Azure was no problem; there were no build errors in the publish process. The component displayed perfectly well of course, but no results were returned from the API when the submit button was clicked.

When I debugged the App Service remotely it transpires that after the API calls the Machine Learning class library, the class library creates the Machine Learning model and a runtime error occurrs. 

Microsoft has been alerted, and I am awaiting their response as to what the problem is and how to fix it.  

next steps

The type of Machine Learning model I selected works well for single sentences. However, restaurant reviews are generally multi-sentence and when I copied and pasted multi-sentence reviews, the results were not accurate. This is probably due to the number of excess "noise" words and sentences in between the sentences that actually do add meaning. The next step therefore, is to add a step to the pipeline to strip out words that do not add additional meaning to the review. 

 


Latest posts