Wednesday, March 27, 2024

Trainers in ML.NET

Machine learning tasks like regression and classification contain various algorithm implementations. 

Some tasks may utilize the same algorithm, such as the SDCA algorithm in both Binary Classification and Regression tasks

 

In some cases, the problem you are trying to solve and the way your data is structured does not fit well into the current algorithm.

If so, consider using a different algorithm for your task to see if it learns better from your data.

 

A trainer identifies a single algorithm used for a single task (i.e. Trainer = Algorithm + Task).

Listed below is a summary of trainers available in ML.NET. For more info, see guidance on which algorithm to choose.

 

Trainer

Algorithm

Task

ONNX Exportable

SdcaLogisticRegressionBinaryTrainer

SDCA

Binary classification

Yes

SdcaNonCalibratedBinaryTrainer

SDCA

Binary classification

Yes

SdcaMaximumEntropyMulticlassTrainer

SDCA

Multiclass classification

Yes

SdcaNonCalibratedMulticlassTrainer

SDCA

Multiclass classification

Yes

SdcaRegressionTrainer

SDCA

Regression

Yes

AveragedPerceptronTrainer

Averaged Perceptron

Binary classification

Yes

LbfgsLogisticRegressionBinaryTrainer

L-BFGS

Binary classification

Yes

LbfgsMaximumEntropyMulticlassTrainer

L-BFGS

Multiclass classification

Yes

LbfgsPoissonRegressionTrainer

L-BFGS

Regression

Yes

SymbolicSgdLogisticRegressionBinaryTrainer

Symbolic stochastic gradient descent

Binary classification

Yes

OnlineGradientDescentTrainer

Online gradient descent

Regression

Yes

LightGbmBinaryTrainer

Light gradient boosted machine

Binary classification

Yes

LightGbmMulticlassTrainer

Light gradient boosted machine

Multiclass classification

Yes

LightGbmRegressionTrainer

Light gradient boosted machine

Regression

Yes

LightGbmRankingTrainer

Light gradient boosted machine

Ranking

No

FastTreeBinaryTrainer

Fast Tree

Binary classification

Yes

FastTreeRegressionTrainer

Fast Tree

Regression

Yes

FastTreeTweedieTrainer

Fast Tree

Regression

Yes

FastTreeRankingTrainer

Fast Tree

Ranking

No

FastForestBinaryTrainer

Fast Forest

Binary classification

Yes

FastForestRegressionTrainer

Fast Forest

Regression

Yes

GamBinaryTrainer

Generalized additive model

Binary classification

No

GamRegressionTrainer

Generalized Additive Model

Regression

No

MatrixFactorizationTrainer

Matrix Factorization

Recommendation

No

FieldAwareFactorizationMachineTrainer

Field Aware Factorization Machine

Binary classification

No

OneVersusAllTrainer

One Versus All

Multiclass classification

Yes

PairwiseCouplingTrainer

Pairwise Coupling

Multiclass classification

No

KMeansTrainer

KMeans

Clustering

Yes

RandomizedPcaTrainer

Randomized Pca

Anomaly detection

No

NaiveBayesMulticlassTrainer

Naive Bayes Multiclass

Multiclass classification

Yes

PriorTrainer

Prior

Binary classification

Yes

LinearSvmTrainer

Linear Svm

Binary classification

Yes

LdSvmTrainer

Ld Svm

Binary classification

Yes

OlsTrainer

Ols

Regression

Yes

 

 

Tuesday, March 12, 2024

What is Auto-GPT?

Auto-GPT is an experimental project developed by Significant Gravitas.  It’s an open-source Python application powered by GPT-4.

 

Unlike ChatGPT, Auto-GPT does not rely on human prompts to operate. It can self-prompt and tackle subsets of a problem without human intervention.  It works by pairing GPT with AI agents that can make decisions and take actions based on a set of rules and predefined goals.

Auto-GPT is important and relevant because it showcases the potential of language models like GPT-4 to autonomously complete different types of tasks. It has the ability to write and execute its own code using GPT-4, allowing it to debug, develop, and self-improve recursively. One of the advantages of Auto-GPT is its ability to continuously self-improve. It can debug, develop, and enhance its own capabilities recursively.

 

Accessing Auto-GPT requires specific installed software and familiarity with Python, and an API key from OpenAI.  It runs locally on a Mac, PC, or Docker image.

 

For a complete tutorial on how to use AutoGPT, visit https://youtu.be/v-5AWQlTFw8

 

For more info, see What is Auto-GPT and What Is the Difference Between ChatGPT vs Auto-GPT?

 

Thursday, March 7, 2024

ML.NET Task Metrics

ML.Net has the capability of utilizing 7 different Machine Learning Tasks via the MLContext object:

  1. Binary Classification
  2. Multi-class/text Classification
  3. Regression and Recommendation
  4. Clustering
  5. Ranking
  6. Anomaly Detection
  7. sentence similarity

 

Each task offers various performance metrics for evaluating the model after training is completed

These metrics are properties accessible via the Evaluate() method within each task object (i.e. MLContext.MLTask.Evaluate()

 

Sample Code Snippet

    static void Main(string[] args)

    {

        MLContext mlContext = new MLContext();

 

        // 1a. Create training data

        HouseData[] houseData = {

               new HouseData() { Size = 1.1F, Price = 1.2F },

               new HouseData() { Size = 1.9F, Price = 2.3F },

               new HouseData() { Size = 2.8F, Price = 3.0F },

               new HouseData() { Size = 3.4F, Price = 3.7F } };

 

        // 1b. Import training data

        IDataView trainingData = mlContext.Data.LoadFromEnumerable(houseData);

 

        // 2. Specify data preparation and model training pipeline

        var pipeline = mlContext.Transforms.Concatenate("Features", new[] { "Size" })

            .Append(mlContext.Regression.Trainers.Sdca(labelColumnName: "Price", maximumNumberOfIterations: 100));

 

        // 3. Train model

        var model = pipeline.Fit(trainingData);

 

        //***** Model Evaluation

        HouseData[] testHouseData =

        {

            new HouseData() { Size = 1.1F, Price = 0.98F },

            new HouseData() { Size = 1.9F, Price = 2.1F },

            new HouseData() { Size = 2.8F, Price = 2.9F },

            new HouseData() { Size = 3.4F, Price = 3.6F }

        };

 

        var testHouseDataView = mlContext.Data.LoadFromEnumerable(testHouseData);

        var testPriceDataView = model.Transform(testHouseDataView);

 

        var metrics = mlContext.Regression.Evaluate(testPriceDataView, labelColumnName: "Price");

        double rs = metrics.RSquared;

        double rmse = metrics.RootMeanSquaredError;

    }

 

Metrics Summary

Listed below is a summary of 6 various ML.NET Tasks and their metrics:

 

BinaryClassification

MulticlassClassification

Regression

Accuracy

Micro Accuracy

R-Squared

AUC

Macro Accuracy

MAE (Mean Absolute Error)

AreaUnderPrecisionRecallCurve

Log-Loss

MSE (Mean Squared Error)

F1-score

Log Loss Reduction

RMSE (Root Mean Square Error)

 

 

Clustering

Ranking

AnomalyDetection

Avg Distance

DCG
(Discounted Cumulative Gains)

Area Under ROC Curve

Davies Boulding Index

Normalized DCG
(Discounted Cumulative Gains)

Detection Rate At False Positive Count

NMI
(Normalized Mutual Information)

 

 

 

 

Reference: https://learn.microsoft.com/en-us/dotnet/machine-learning/resources/metrics

Thursday, November 30, 2023

Azure AI Content Safety Service

Microsoft introduced a new AI service called “Azure AI Content Safety Service” at the Build conference in May 2023.  This new service will inspect for questionable content in any of the following categories.

  1. Violent content
  2. Hateful content
  3. Sexual content
  4. Self-harm content

 

The Content Safety service is intended to protect customers’ web sites and social media apps from receiving questionable comments or images.

Content maybe text, images, audio, video, or a combination of items (i.e. multi-modal). 

 

Users can utilize filters to tweak the severity levels.  For example, an outdoor equipment provider may allow images of knives or guns uploaded to their social media, but a school or church may like to prevent those images. Filters are set to Medium by default and can be increased.  Turning the filter settings to be less restricted or turned off requires a written application to Microsoft to ensure the customer is trusted and low risk.

 

The AI Content Safety Service is built into Open AI and most Microsoft AI products.  It’s used internally at Microsoft as well in public products like Bing Chat. The purpose is to uphold responsible AI principles provided by Microsoft.

 

 


 

Code Example

  1. Using the Azure AI Content Safety Service is accessible through the Azure portal. After logging into the portal, simply create a “Content Safety” Resource in an existing group or a new group.

 

  1. Once the resource is created, the Keys and Endpoints will be accessible in the Resource Management pane

 

 

  1. To access the Safety Content API, I created a console application with the following NuGet packages

 


 

  1. The code will utilize an API call, using the key and endpoint from step #2

 

using Azure;

using Azure.AI.ContentSafety;

using Microsoft.Extensions.Configuration;

using System.Reflection;

 

 

namespace AIContenSafety.ConsoleApp

{

    internal class Program

    {

        static void Main(string[] args)

        {

            var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

            string endpoint = config["AppSettings:endpoint"];

            string key = config["AppSettings:key"];

 

            string datapath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images", "TestImage1.jpg");

 

            ImageData image = new ImageData();

            image.Content = BinaryData.FromBytes(File.ReadAllBytes(datapath));

 

            var request = new AnalyzeImageOptions(image);

 

            Response<AnalyzeImageResult> response;

            try

            {

                ContentSafetyClient client = new ContentSafetyClient(new Uri(endpoint), new AzureKeyCredential(key));

                response = client.AnalyzeImage(request);

            }

            catch (RequestFailedException ex)

            {

                Console.WriteLine("Analyze image failed.\nStatus code: {0}, Error code: {1}, Error message: {2}", ex.Status, ex.ErrorCode, ex.Message);

                throw;

            }

 

            Console.WriteLine("Hate severity: {0}", response.Value.HateResult.Severity);

            Console.WriteLine("SelfHarm severity: {0}", response.Value.SelfHarmResult.Severity);

            Console.WriteLine("Sexual severity: {0}", response.Value.SexualResult.Severity);

            Console.WriteLine("Violence severity: {0}", response.Value.ViolenceResult.Severity);

        }

    }

}

 

 

Testing the Application

Provided in the solution is a folder containing a test image (shown below), called TestImage1.jpg.  Naturally this image should be classified as violent content.

 

Running the Application

Executing the console application will load the test image specified above.  All results are posted in the console window showing the type of content violating the safety guidelines.  In addition, it shows the severity level of the content.

 

Additional Resources

Get started in Studio https://aka.ms/contentsafetystudio

Visit product page to learn more https://aka.ms/contentsafety

Read the eBook https://aka.ms/contentsafetyebook

 

Wednesday, October 18, 2023

Free OPEN Passes to API World 2023

API World 2023 (Oct 24-26, Santa Clara, CA) + (Oct 31- Nov 2, Live Online) is the world’s largest API & microservices event where 4,500+ engineers, architects, IT leaders, integration partners, API & technical professionals and executives converge to discover the latest API developer & engineering innovations. Learn from leaders at Microsoft, Apple, Cisco, Netflix, IBM, Adobe, Volkswagen AG, Airbnb, Realtor.com, US Bank, and many more!

The API World team has offered our group 25 free OPEN Passes and discounted PRO Passes, so our members can attend for free.

Register now to get your free OPEN Pass or to SAVE $100 on your PRO Pass.

To register, go to: https://www.devnetwork.com/registration/?event=API%20World%202023&utm_source=meetup&utm_medium=email&utm_campaign=MU21543&discount=MU21543

 

 

Friday, October 13, 2023

Using LocalDB in 3 Steps

Problem: While doing a demo on a client’s PC that didn’t have SQL Server Developer Edition installed, I needed a quick way to demonstrate querying a SQL Server DB without installing SQL Server.

 

Solution: LocalDB to the rescue!  The client’s PC did have SQL Server Management Studio installed, along with SQL Server Express.  This gave me enough capability to create a sample DB and demonstrate how to query it.

 

To create a DB instance:

  1. Open a Command Prompt window
  2. Enter “sqllocaldb create “Ch1Demo” “, where Ch1Demo was the specific name of my DB instance.  This short command quickly created an instance using the default version of the SQL Server DB Engine installed (see below).  This process was nearly instant (see below).

 

 

Since my username is “Sam”, The DB was created in the path C:\Users\Sam\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\Ch1Demo

 

  1. To connect to the DB instance, simply use SQL Server Management Studio with the Server Name preceded with “(localdb)\”

 

 

For all intents and purposes, Ch1Demo will appear as any other DB instance, allowing DB creation, updates, and queries.

 

 

This was the perfect solution in a pinch, and it helps you as well.

 

To learn more about localDB, visit https://learn.microsoft.com/en-us/sql/tools/sqllocaldb-utility?view=sql-server-ver16

 

Wednesday, October 11, 2023

Oct '23 Regional Tech Events

ChatGPT for Business

Recently David Giard (Microsoft) delivered a presentation on using ChatGPT.  Aside from answering basic questions, he demonstrated some key business and professional cases:

  • Create a LinkedIn Profile
  • Write a Professional email
  • “How do I increase my followers on Twitter?”
  • “How do I increase customer base?”
  • “How to organize a conference or event?”
  • Get ideas for writing, to prevent writers block

 

The full presentation can be seen at https://www.youtube.com/watch?v=noXxynTEEhg

 

 

 

 

 

 

 

Wednesday, May 10, 2023

Microsoft Azure Fundamentals Q&A

While attending a Microsoft Azure Fundamentals Training session today, some interesting questions were posted.  Listed below is the Q&A from the forum:

 

1.      How does private cloud differ from on-prem?

A private cloud may be hosted from your onsite datacenter, which would be on-premises. It may also be hosted in a dedicated datacenter offsite, potentially even by a third party that has dedicated that datacenter to your company. You can find more information here: https://learn.microsoft.com/en-us/training/modules/describe-cloud-compute/5-define-cloud-models

 

2.      Which is cheaper, public or hybrid cloud?

This depends on how your organization is structured, the size, and the services you need. You can compare on-premises and cloud costs using the Total Cost of Ownership Calculator here: https://azure.microsoft.com/en-us/pricing/tco/

 

3.      When to use private cloud (on prem) without [public] cloud ?

In some cases, your organization may be legally required to store information in your own data center. There may be other compliance and cost considerations as well. The size of your company and the resources you need may be less expensive in one form or another. You can find more information here: https://learn.microsoft.com/en-us/training/modules/describe-cloud-compute/5-define-cloud-models

 

4.      Does Hybrid cloud incurs both capital and operational expenditure?

Yes, hybrid cloud incurs both capital and operational expenditure.

 

5.      Is there any difference in availability of private and public cloud ?

There may be a difference in availability depending on the circumstances. If you have older technology in your private cloud, you may have more latency. Or, if you have resources on the other side of the globe in the public cloud, you may also have latency. There are many variables.

 

6.      What’s the definition for public cloud?

A public cloud is built, controlled, and maintained by a third-party cloud provider. You can find more information here: https://learn.microsoft.com/en-us/training/modules/describe-cloud-compute/5-define-cloud-models

 

7.      Does "Private Cloud" mean some form on on-prem Azure or AWS, etc.?

Azure and AWS are examples of Public Cloud. This is the opposite of private cloud. with Private cloud, you are owning/operating your own resources. With public cloud, your provider owns and operates the hardware. You can find more information here: https://learn.microsoft.com/en-us/training/modules/describe-cloud-compute/5-define-cloud-models

 

8.      Would you explain the difference between elasticity and scalability?

Scalability means increasing or decreasing services as needed. Elasticity refers to enabling the increase or decrease of automatically: When a resource meets a limit, it will automatically increase as needed.

 

9.      If I create a VM in Cloud, will I be charged even if VM is shut down?

Yes, because your VM is still taking up storage space. You will not be charged for run time if it is not running, though.

 

10.   Does Azure provide private cloud capabilities if customer demands?

Yes, there are some options for organizations to have dedicated hardware. One example is with Azure dedicated host. More information about that is available here: https://learn.microsoft.com/en-us/azure/virtual-machines/dedicated-hosts  

 

11.   Please provide definition for CAPEX

CapEx refers to Capital Expenditure and is typically a one-time, up-front expenditure to purchase or secure tangible resources. A new building, repaving the parking lot, building a datacenter, or buying a company vehicle are examples of CapEx. You can find more information here: learn.microsoft.com/en-us/training/modules/describe-cloud-compute/6-describe-consumption-based-model

 

12.   Do Microsoft Azure has a data center in the continent of Antarctica?

Great question. I don't see one in Antarctica. You can find the list here: https://azure.microsoft.com/en-us/explore/global-infrastructure/geographies/#choose-your-region