dotnet / dotnet/machinelearning-samples

Missing initializer member in generated code

Open
#453 8 comments 0 reactions 0 assignees View on GitHub
mlnet-cli
Dominant language
PowerShell
Stars
4.7k
Forks
2.7k
Avg merge
2d 22h
Merged PRs (30d)
1

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 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 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.