Skip to content

Missing initializer member in generated code #453

Open

Description

Problem encountered on https://dotnet.microsoft.com/learn/machinelearning-ai/ml-dotnet-get-started-tutorial/generate-code
Operating System: windows

Provide details about the problem you are experiencing. Include your operating system version, exact error message, code sample, and anything else that is relevant.

In ModelBuilder.cs the function

public static IEstimator BuildTrainingPipeline(MLContext mlContext)

the trining algorithm is missing a initializer member.
The code looks like this generated:

public static IEstimator<ITransformer> BuildTrainingPipeline(MLContext mlContext)
        {
            // Data process configuration with pipeline data transformations 
            var dataProcessPipeline = mlContext.Transforms.Text.FeaturizeText("SentimentText_tf", "SentimentText")
                                      .Append(mlContext.Transforms.CopyColumns("Features", "SentimentText_tf"))
                                      .Append(mlContext.Transforms.NormalizeMinMax("Features", "Features"))
                                      .AppendCacheCheckpoint(mlContext);

            // Set the training algorithm 
            var trainer = mlContext.BinaryClassification.Trainers.SgdCalibrated(new SgdCalibratedTrainer.Options() {
                L2Regularization = 5E-06f,
                ConvergenceTolerance = 0,
                0.01f, // < ----- LOOK HERE
                NumberOfIterations = 10,
                Shuffle = true,
                LabelColumnName = "Sentiment",
                FeatureColumnName = "Features" });
            var trainingPipeline = dataProcessPipeline.Append(trainer);

            return trainingPipeline;
        }

I had a look at the documentation and figured that what was missing was this

public static IEstimator<ITransformer> BuildTrainingPipeline(MLContext mlContext)
        {
            // Data process configuration with pipeline data transformations 
            var dataProcessPipeline = mlContext.Transforms.Text.FeaturizeText("SentimentText_tf", "SentimentText")
                                      .Append(mlContext.Transforms.CopyColumns("Features", "SentimentText_tf"))
                                      .Append(mlContext.Transforms.NormalizeMinMax("Features", "Features"))
                                      .AppendCacheCheckpoint(mlContext);

            // Set the training algorithm 
            var trainer = mlContext.BinaryClassification.Trainers.SgdCalibrated(new SgdCalibratedTrainer.Options() {
                L2Regularization = 5E-06f,
                ConvergenceTolerance = 0,
                PositiveInstanceWeight = 0.01f, // <--- SEEMED TO DO THE TRICK
                NumberOfIterations = 10,
                Shuffle = true,
                LabelColumnName = "Sentiment",
                FeatureColumnName = "Features" });
            var trainingPipeline = dataProcessPipeline.Append(trainer);

            return trainingPipeline;
        }

Also worth noting was that when the code was generated the value "0.01f" actually said "001f". I imagine it can have something to do with language setting on the computer perhaps.

EDIT: Similar problem as #444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    mlnet-cliCommand-line interface for ML.NET w/ AutoML capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions