Skip to content

Commit 7d99420

Browse files
srsaggamDmitry-A
authored andcommitted
Polishing the CLI UI part-1 (dotnet#338)
* formatting of pbar message * Polishing the UI * optimization * rename variable * Update src/mlnet/AutoML/AutoMLEngine.cs Co-Authored-By: srsaggam <[email protected]> * Update src/mlnet/CodeGenerator/CodeGenerationHelper.cs Co-Authored-By: srsaggam <[email protected]> * new message * changed hhtp to https * added iteration num + 1 * change string name and add color to artifacts * change the message * build errors * added null checks * added exception messsages to log file * added exception messsages to log file
1 parent 84a7a21 commit 7d99420

File tree

8 files changed

+155
-90
lines changed

8 files changed

+155
-90
lines changed

src/Microsoft.ML.Auto/Utils/BestResultUtil.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ public static CrossValidationRunDetails<TMetrics> GetBestRun<TMetrics>(IEnumerab
2929
return results.ElementAt(indexOfBestScore);
3030
}
3131

32-
public static IEnumerable<RunDetails<T>> GetTopNRunResults<T>(IEnumerable<RunDetails<T>> results,
32+
public static IEnumerable<(RunDetails<T>, int)> GetTopNRunResults<T>(IEnumerable<RunDetails<T>> results,
3333
IMetricsAgent<T> metricsAgent, int n, bool isMetricMaximizing)
3434
{
3535
results = results.Where(r => r.ValidationMetrics != null);
3636
if (!results.Any()) { return null; }
3737

38-
IEnumerable<RunDetails<T>> orderedResults;
38+
var indexedValues = results.Select((k, v) => (k, v));
39+
40+
IEnumerable<(RunDetails<T>, int)> orderedResults;
3941
if (isMetricMaximizing)
4042
{
41-
orderedResults = results.OrderByDescending(t => metricsAgent.GetScore(t.ValidationMetrics));
43+
orderedResults = indexedValues.OrderByDescending(t => metricsAgent.GetScore(t.Item1.ValidationMetrics));
44+
4245
}
4346
else
4447
{
45-
orderedResults = results.OrderBy(t => metricsAgent.GetScore(t.ValidationMetrics));
48+
orderedResults = indexedValues.OrderBy(t => metricsAgent.GetScore(t.Item1.ValidationMetrics));
4649
}
4750

4851
return orderedResults.Take(n);

src/mlnet/AutoML/AutoMLEngine.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public AutoMLEngine(NewCommandSettings settings)
2929

3030
public ColumnInferenceResults InferColumns(MLContext context, ColumnInformation columnInformation)
3131
{
32-
//Check what overload method of InferColumns needs to be called.
33-
logger.Log(LogLevel.Info, Strings.InferColumns);
32+
// Check what overload method of InferColumns needs to be called.
33+
logger.Log(LogLevel.Trace, Strings.InferColumns);
3434
ColumnInferenceResults columnInference = null;
3535
var dataset = settings.Dataset.FullName;
3636
if (columnInformation.LabelColumn != null)

src/mlnet/CodeGenerator/CodeGenerationHelper.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ public void GenerateCode()
7979
IEnumerable<RunDetails<RegressionMetrics>> regressionRunDetails = default;
8080

8181
Console.WriteLine($"{Strings.ExplorePipeline}: {settings.MlTask}");
82+
Console.WriteLine($"{Strings.FurtherLearning}: {Strings.LearningHttpLink}");
8283
try
8384
{
8485
var options = new ProgressBarOptions
8586
{
8687
ForegroundColor = ConsoleColor.Yellow,
87-
ForegroundColorDone = ConsoleColor.DarkGreen,
88+
ForegroundColorDone = ConsoleColor.Yellow,
8889
BackgroundColor = ConsoleColor.Gray,
8990
ProgressCharacter = '\u2593',
9091
BackgroundCharacter = '─',
@@ -169,19 +170,22 @@ public void GenerateCode()
169170
}
170171

171172
// Save the model
172-
logger.Log(LogLevel.Info, Strings.SavingBestModel);
173173
var modelprojectDir = Path.Combine(settings.OutputPath.FullName, $"{settings.Name}.Model");
174174
var modelPath = new FileInfo(Path.Combine(modelprojectDir, "MLModel.zip"));
175175
Utils.SaveModel(bestModel, modelPath, context, trainData.Schema);
176+
Console.ForegroundColor = ConsoleColor.Yellow;
177+
logger.Log(LogLevel.Info, $"{Strings.SavingBestModel}: {modelPath}");
176178

177179
// Generate the Project
178180
GenerateProject(columnInference, bestPipeline, columnInformation.LabelColumn, modelPath);
181+
logger.Log(LogLevel.Info, $"{Strings.GenerateModelConsumption} : { Path.Combine(settings.OutputPath.FullName, $"{settings.Name}.Predict")}");
182+
logger.Log(LogLevel.Info, $"{Strings.GenerateModelTraining} : { Path.Combine(settings.OutputPath.FullName, $"{settings.Name}.Train")}");
183+
Console.ResetColor();
179184
}
180185

181186
internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline pipeline, string labelName, FileInfo modelPath)
182187
{
183-
//Generate code
184-
logger.Log(LogLevel.Info, $"{Strings.GenerateProject} : {settings.OutputPath.FullName}");
188+
// Generate code
185189
var codeGenerator = new CodeGenerator.CSharp.CodeGenerator(
186190
pipeline,
187191
columnInference,
@@ -200,10 +204,10 @@ internal void GenerateProject(ColumnInferenceResults columnInference, Pipeline p
200204

201205
internal (IDataView, IDataView) LoadData(MLContext context, TextLoader.Options textLoaderOptions)
202206
{
203-
logger.Log(LogLevel.Info, Strings.CreateDataLoader);
207+
logger.Log(LogLevel.Trace, Strings.CreateDataLoader);
204208
var textLoader = context.Data.CreateTextLoader(textLoaderOptions);
205209

206-
logger.Log(LogLevel.Info, Strings.LoadData);
210+
logger.Log(LogLevel.Trace, Strings.LoadData);
207211
var trainData = textLoader.Load(settings.Dataset.FullName);
208212
var validationData = settings.ValidationDataset == null ? null : textLoader.Load(settings.ValidationDataset.FullName);
209213

src/mlnet/NLog.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</targets>
99

1010
<rules>
11-
<logger name="*" minlevel="Debug" writeTo="logfile" />
11+
<logger name="*" minlevel="Trace" writeTo="logfile" />
1212
</rules>
1313
</nlog>

src/mlnet/Strings.resx

+17-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
<value>Exiting ...</value>
128128
</data>
129129
<data name="ExplorePipeline" xml:space="preserve">
130-
<value>Exploring multiple combinations of ML algorithms and settings to find you the best model for ML task</value>
130+
<value>Exploring multiple ML algorithms and settings to find you the best model for ML task</value>
131131
</data>
132132
<data name="ExplorePipelineException" xml:space="preserve">
133133
<value>Exception occured while exploring pipelines</value>
@@ -157,9 +157,24 @@
157157
<value>Retrieving best pipeline ...</value>
158158
</data>
159159
<data name="SavingBestModel" xml:space="preserve">
160-
<value>Saving the best model ...</value>
160+
<value>Generated trained model for consumption</value>
161161
</data>
162162
<data name="UnsupportedMlTask" xml:space="preserve">
163163
<value>Unsupported ml-task</value>
164164
</data>
165+
<data name="GenerateLogFile" xml:space="preserve">
166+
<value>Generated log file </value>
167+
</data>
168+
<data name="GenerateModelConsumption" xml:space="preserve">
169+
<value>Generated C# code for model consumption</value>
170+
</data>
171+
<data name="GenerateModelTraining" xml:space="preserve">
172+
<value>Generated C# code for model training</value>
173+
</data>
174+
<data name="FurtherLearning" xml:space="preserve">
175+
<value>For further learning check</value>
176+
</data>
177+
<data name="LearningHttpLink" xml:space="preserve">
178+
<value>https://aka.ms/mlnet-cli</value>
179+
</data>
165180
</root>

0 commit comments

Comments
 (0)