Skip to content

Latest commit

 

History

History

Bet.Extensions.ML

Bet.Extensions.ML

GitHub license Build status NuGet Nuget feedz.io

The second letter in the Hebrew alphabet is the ב bet/beit. Its meaning is "house". In the ancient pictographic Hebrew it was a symbol resembling a tent on a landscape.

Note: Pre-release packages are distributed via feedz.io.

Summary

The goal of this repo is to provide with production ready extensions to ML.NET library.

It contains two major functionality:

  1. ML.NET ModelBuilder Pipeline with ability to load from different sources i.e. Azure Blob Storage.

  2. ML.NET Web Api hosting with caching of ML models to improve performance. This library utilizes ObjectPool similar to Extensions.ML

buymeacoffee

Give a Star! ⭐

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

Install

    dotnet add package Bet.Extensions.ML

Usage

For complete examples please refer to sample projects:

  1. Bet.AspNetCore.Sample - AspNetCore Web App with spam prediction models.
  2. Bet.Hosting.Sample - DotNetCore Worker based scheduled job for generating ML.NET Models.

To include Machine Learning prediction the following can be added:

    services.AddModelPredictionEngine<SpamInput, SpamPrediction>(mlOptions =>
    {
        mlOptions.MLContext = () =>
        {
            var mlContext = new MLContext();
            mlContext.ComponentCatalog.RegisterAssembly(typeof(LabelTransfomer).Assembly);
            mlContext.Transforms.CustomMapping<LabelInput, LabelOutput>(LabelTransfomer.Transform, nameof(LabelTransfomer.Transform));

            return mlContext;
        };

        mlOptions.CreateModel = (mlContext) =>
        {
            using (var fileStream = File.OpenRead("MLContent/SpamModel.zip"))
            {
                return mlContext.Model.Load(fileStream);
            }
        };
    },"SpamModel");

Then in the API Controller:

[Route("api/[controller]")]
    [ApiController]
    public class PredictionController : ControllerBase
    {
        private readonly IModelPredictionEngine<SentimentObservation, SentimentPrediction> _sentimentModel;
        private readonly IModelPredictionEngine<SpamInput, SpamPrediction> _spamModel;

        public PredictionController(
            IModelPredictionEngine<SentimentObservation, SentimentPrediction> sentimentModel,
            IModelPredictionEngine<SpamInput, SpamPrediction> spamModel)
        {
            _sentimentModel = sentimentModel ?? throw new ArgumentNullException(nameof(sentimentModel));
            _spamModel = spamModel ?? throw new ArgumentNullException(nameof(spamModel));
        }

        [HttpPost()]
        public ActionResult<SentimentPrediction> GetSentiment(SentimentObservation input)
        {
            return _sentimentModel.Predict(input);
        }

        // GET /api/prediction/spam?text=Hello World
        [HttpGet]
        [Route("spam")]
        public ActionResult<SpamPrediction> PredictSpam([FromQuery]string text)
        {
            return _spamModel.Predict(new SpamInput { Message = text});
        }
    }

Basics of ML.NET Presentation

1. ML.NET Preparing Data Apis

ML.NET Preparing Data Apis

2. ML.NET Preparing and Filtering Data Apis

ML.NET Preparing and Filtering Data Apis

3. ML.NET Regression Basics

ML.NET Regression Basics

4. ML.NET Regression Trainers

ML.NET Regression Trainers

5. ML.NET OSL Regression

ML.NET OSL Regression

6. ML.NET Basics of Decision Trees and Random Forests

ML.NET Basics of Decision Trees and Random Forests

7. ML.NET Regression with Random Forests

ML.NET Regression with Random Forests

8. ML.NET Trainer Options

ML.NET Trainer Options

9. ML.NET Scoring Regression Models

ML.NET Scoring Regression Models

10. ML.NET Cross Validating Regression Models

ML.NET Cross Validating Regression Models

11. ML.NET Basics of One-Hot-Encoding

ML.NET Basics of One-Hot-Encoding

12. ML.NET Binary Classifications

ML.NET Binary Classifications

13. Binary Classification Trainers

ML.NET Binary Classification Trainers

14. 1ML.NET Scoring Binary Classification Models

ML.NET Scoring Binary Classification Models

15. ML.NET Cross Validating Binary Classification Models

ML.NET Cross Validating Binary Classification Models

16. ML.NET Vectorizing Text Functionality

ML.NET Vectorizing Text Functionality

17. ML.NET Specifying Text Vectorization Options

ML.NET Specifying Text Vectorization Options

18. ML.NET Multi Classification Trainers

ML.NET Multi Classification Trainers

19. ML.NET Scoring Multi Classification Models

ML.NET Scoring Multi Classification Models

20. ML.NET Classifying Images

ML.NET Classifying Images

21.ML.NET Convolutional Neutral Networks

ML.NET Convolutional Neutral Networks

22. ML.NET Transfer Learning

ML.NET Transfer Learning

23. ML.NET Pre-trained Convolutional Neutral Networks

ML.NET Pre-trained Convolutional Neutral Networks

24. ML.NET AutoML

ML.NET AutoML

25. ML.NET AutoML Regression Model Training

ML.NET AutoML Regression Model Training

References