Skip to content

Commit dfa841c

Browse files
authored
renamed classes (#3634)
1 parent 5e39073 commit dfa841c

17 files changed

+67
-67
lines changed

src/mlnet/CodeGenerator/CSharp/CodeGenerator.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void GenerateOutput()
5454
var dataModelsDir = Path.Combine(modelprojectDir, "DataModels");
5555
var modelProjectName = $"{settings.OutputName}.Model.csproj";
5656

57-
Utils.WriteOutputToFiles(modelProjectContents.ObservationCSFileContent, "SampleObservation.cs", dataModelsDir);
58-
Utils.WriteOutputToFiles(modelProjectContents.PredictionCSFileContent, "SamplePrediction.cs", dataModelsDir);
57+
Utils.WriteOutputToFiles(modelProjectContents.ModelInputCSFileContent, "ModelInput.cs", dataModelsDir);
58+
Utils.WriteOutputToFiles(modelProjectContents.ModelOutputCSFileContent, "ModelOutput.cs", dataModelsDir);
5959
Utils.WriteOutputToFiles(modelProjectContents.ModelProjectFileContent, modelProjectName, modelprojectDir);
6060

6161
// Generate ConsoleApp Project
@@ -116,15 +116,15 @@ private void SetRequiredNugetPackages(IEnumerable<PipelineNode> trainerNodes, re
116116
return (predictProgramCSFileContent, predictProjectFileContent, modelBuilderCSFileContent);
117117
}
118118

119-
internal (string ObservationCSFileContent, string PredictionCSFileContent, string ModelProjectFileContent) GenerateModelProjectContents(string namespaceValue, Type labelTypeCsharp, bool includeLightGbmPackage, bool includeMklComponentsPackage, bool includeFastTreePackage)
119+
internal (string ModelInputCSFileContent, string ModelOutputCSFileContent, string ModelProjectFileContent) GenerateModelProjectContents(string namespaceValue, Type labelTypeCsharp, bool includeLightGbmPackage, bool includeMklComponentsPackage, bool includeFastTreePackage)
120120
{
121121
var classLabels = this.GenerateClassLabels();
122-
var observationCSFileContent = GenerateObservationCSFileContent(namespaceValue, classLabels);
123-
observationCSFileContent = Utils.FormatCode(observationCSFileContent);
124-
var predictionCSFileContent = GeneratePredictionCSFileContent(labelTypeCsharp.Name, namespaceValue);
125-
predictionCSFileContent = Utils.FormatCode(predictionCSFileContent);
122+
var modelInputCSFileContent = GenerateModelInputCSFileContent(namespaceValue, classLabels);
123+
modelInputCSFileContent = Utils.FormatCode(modelInputCSFileContent);
124+
var modelOutputCSFileContent = GenerateModelOutputCSFileContent(labelTypeCsharp.Name, namespaceValue);
125+
modelOutputCSFileContent = Utils.FormatCode(modelOutputCSFileContent);
126126
var modelProjectFileContent = GenerateModelProjectFileContent(includeLightGbmPackage, includeMklComponentsPackage, includeFastTreePackage);
127-
return (observationCSFileContent, predictionCSFileContent, modelProjectFileContent);
127+
return (modelInputCSFileContent, modelOutputCSFileContent, modelProjectFileContent);
128128
}
129129

130130
internal (string Usings, string TrainerMethod, List<string> PreTrainerTransforms, List<string> PostTrainerTransforms) GenerateTransformsAndTrainers()
@@ -261,16 +261,16 @@ private static string GenerateModelProjectFileContent(bool includeLightGbmPackag
261261
return modelProject.TransformText();
262262
}
263263

264-
private string GeneratePredictionCSFileContent(string predictionLabelType, string namespaceValue)
264+
private string GenerateModelOutputCSFileContent(string predictionLabelType, string namespaceValue)
265265
{
266-
PredictionClass predictionClass = new PredictionClass() { TaskType = settings.MlTask.ToString(), PredictionLabelType = predictionLabelType, Namespace = namespaceValue };
267-
return predictionClass.TransformText();
266+
ModelOutputClass modelOutputClass = new ModelOutputClass() { TaskType = settings.MlTask.ToString(), PredictionLabelType = predictionLabelType, Namespace = namespaceValue };
267+
return modelOutputClass.TransformText();
268268
}
269269

270-
private string GenerateObservationCSFileContent(string namespaceValue, IList<string> classLabels)
270+
private string GenerateModelInputCSFileContent(string namespaceValue, IList<string> classLabels)
271271
{
272-
ObservationClass observationClass = new ObservationClass() { Namespace = namespaceValue, ClassLabels = classLabels };
273-
return observationClass.TransformText();
272+
ModelInputClass modelInputClass = new ModelInputClass() { Namespace = namespaceValue, ClassLabels = classLabels };
273+
return modelInputClass.TransformText();
274274
}
275275
#endregion
276276

src/mlnet/Templates/Console/ModelBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public virtual string TransformText()
6565
public static void CreateModel()
6666
{
6767
// Load Data
68-
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<SampleObservation>(
68+
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
6969
path: TRAIN_DATA_FILEPATH,
7070
hasHeader : ");
7171
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
@@ -77,9 +77,9 @@ public static void CreateModel()
7777
this.Write(this.ToStringHelper.ToStringWithCulture(AllowSparse.ToString().ToLowerInvariant()));
7878
this.Write(");\r\n\r\n");
7979
if(!string.IsNullOrEmpty(TestPath)){
80-
this.Write(" IDataView testDataView = mlContext.Data.LoadFromTextFile<SampleObserv" +
81-
"ation>(\r\n path: TEST_DATA_FILEPATH,\r\n" +
82-
" hasHeader : ");
80+
this.Write(" IDataView testDataView = mlContext.Data.LoadFromTextFile<ModelInput>(" +
81+
"\r\n path: TEST_DATA_FILEPATH,\r\n " +
82+
" hasHeader : ");
8383
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
8484
this.Write(",\r\n separatorChar : \'");
8585
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));

src/mlnet/Templates/Console/ModelBuilder.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ namespace <#= Namespace #>.ConsoleApp
3636
public static void CreateModel()
3737
{
3838
// Load Data
39-
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<SampleObservation>(
39+
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
4040
path: TRAIN_DATA_FILEPATH,
4141
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
4242
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',
4343
allowQuoting : <#= AllowQuoting.ToString().ToLowerInvariant() #>,
4444
allowSparse: <#= AllowSparse.ToString().ToLowerInvariant() #>);
4545

4646
<# if(!string.IsNullOrEmpty(TestPath)){ #>
47-
IDataView testDataView = mlContext.Data.LoadFromTextFile<SampleObservation>(
47+
IDataView testDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
4848
path: TEST_DATA_FILEPATH,
4949
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
5050
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',

src/mlnet/Templates/Console/ObservationClass.cs renamed to src/mlnet/Templates/Console/ModelInputClass.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.ML.CLI.Templates.Console
1818
/// Class to produce the template output
1919
/// </summary>
2020
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
21-
public partial class ObservationClass : ObservationClassBase
21+
public partial class ModelInputClass : ModelInputClassBase
2222
{
2323
/// <summary>
2424
/// Create the template output
@@ -35,7 +35,7 @@ public virtual string TransformText()
3535
3636
namespace ");
3737
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
38-
this.Write(".Model.DataModels\r\n{\r\n public class SampleObservation\r\n {\r\n");
38+
this.Write(".Model.DataModels\r\n{\r\n public class ModelInput\r\n {\r\n");
3939
foreach(var label in ClassLabels){
4040
this.Write(" ");
4141
this.Write(this.ToStringHelper.ToStringWithCulture(label));
@@ -54,7 +54,7 @@ namespace ");
5454
/// Base class for this transformation
5555
/// </summary>
5656
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
57-
public class ObservationClassBase
57+
public class ModelInputClassBase
5858
{
5959
#region Fields
6060
private global::System.Text.StringBuilder generationEnvironmentField;

src/mlnet/Templates/Console/ObservationClass.tt renamed to src/mlnet/Templates/Console/ModelInputClass.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using Microsoft.ML.Data;
1313

1414
namespace <#= Namespace #>.Model.DataModels
1515
{
16-
public class SampleObservation
16+
public class ModelInput
1717
{
1818
<#foreach(var label in ClassLabels){#>
1919
<#=label#>

src/mlnet/Templates/Console/PredictionClass.cs renamed to src/mlnet/Templates/Console/ModelOutputClass.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.ML.CLI.Templates.Console
1818
/// Class to produce the template output
1919
/// </summary>
2020
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
21-
public partial class PredictionClass : PredictionClassBase
21+
public partial class ModelOutputClass : ModelOutputClassBase
2222
{
2323
/// <summary>
2424
/// Create the template output
@@ -36,7 +36,7 @@ public virtual string TransformText()
3636
3737
namespace ");
3838
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
39-
this.Write(".Model.DataModels\r\n{\r\n public class SamplePrediction\r\n {\r\n");
39+
this.Write(".Model.DataModels\r\n{\r\n public class ModelOutput\r\n {\r\n");
4040
if("BinaryClassification".Equals(TaskType)){
4141
this.Write(" // ColumnName attribute is used to change the column name from\r\n /" +
4242
"/ its default value, which is the name of the field.\r\n [ColumnName(\"Predi" +
@@ -67,7 +67,7 @@ namespace ");
6767
/// Base class for this transformation
6868
/// </summary>
6969
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")]
70-
public class PredictionClassBase
70+
public class ModelOutputClassBase
7171
{
7272
#region Fields
7373
private global::System.Text.StringBuilder generationEnvironmentField;

src/mlnet/Templates/Console/PredictionClass.tt renamed to src/mlnet/Templates/Console/ModelOutputClass.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using Microsoft.ML.Data;
1414

1515
namespace <#= Namespace #>.Model.DataModels
1616
{
17-
public class SamplePrediction
17+
public class ModelOutput
1818
{
1919
<#if("BinaryClassification".Equals(TaskType)){ #>
2020
// ColumnName attribute is used to change the column name from

src/mlnet/Templates/Console/PredictProgram.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ static void Main(string[] args)
6262
//ModelBuilder.CreateModel();
6363
6464
ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath(MODEL_FILEPATH), out DataViewSchema inputSchema);
65-
var predEngine = mlContext.Model.CreatePredictionEngine<SampleObservation, SamplePrediction>(mlModel);
65+
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
6666
6767
// Create sample data to do a single prediction with it
68-
SampleObservation sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);
68+
ModelInput sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);
6969
7070
// Try a single prediction
71-
SamplePrediction predictionResult = predEngine.Predict(sampleData);
71+
ModelOutput predictionResult = predEngine.Predict(sampleData);
7272
7373
");
7474
if("BinaryClassification".Equals(TaskType)){
@@ -92,10 +92,10 @@ static void Main(string[] args)
9292
9393
// Method to load single row of data to try a single prediction
9494
// You can change this code and create your own sample data here (Hardcoded or from any source)
95-
private static SampleObservation CreateSingleDataSample(MLContext mlContext, string dataFilePath)
95+
private static ModelInput CreateSingleDataSample(MLContext mlContext, string dataFilePath)
9696
{
9797
// Read dataset to get a single row for trying a prediction
98-
IDataView dataView = mlContext.Data.LoadFromTextFile<SampleObservation>(
98+
IDataView dataView = mlContext.Data.LoadFromTextFile<ModelInput>(
9999
path: dataFilePath,
100100
hasHeader : ");
101101
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
@@ -107,8 +107,8 @@ private static SampleObservation CreateSingleDataSample(MLContext mlContext, str
107107
this.Write(this.ToStringHelper.ToStringWithCulture(AllowSparse.ToString().ToLowerInvariant()));
108108
this.Write(@");
109109
110-
// Here (SampleObservation object) you could provide new test data, hardcoded or from the end-user application, instead of the row from the file.
111-
SampleObservation sampleForPrediction = mlContext.Data.CreateEnumerable<SampleObservation>(dataView, false)
110+
// Here (ModelInput object) you could provide new test data, hardcoded or from the end-user application, instead of the row from the file.
111+
ModelInput sampleForPrediction = mlContext.Data.CreateEnumerable<ModelInput>(dataView, false)
112112
.First();
113113
return sampleForPrediction;
114114
}

src/mlnet/Templates/Console/PredictProgram.tt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ namespace <#= Namespace #>.ConsoleApp
4040
//ModelBuilder.CreateModel();
4141

4242
ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath(MODEL_FILEPATH), out DataViewSchema inputSchema);
43-
var predEngine = mlContext.Model.CreatePredictionEngine<SampleObservation, SamplePrediction>(mlModel);
43+
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
4444

4545
// Create sample data to do a single prediction with it
46-
SampleObservation sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);
46+
ModelInput sampleData = CreateSingleDataSample(mlContext, DATA_FILEPATH);
4747

4848
// Try a single prediction
49-
SamplePrediction predictionResult = predEngine.Predict(sampleData);
49+
ModelOutput predictionResult = predEngine.Predict(sampleData);
5050

5151
<#if("BinaryClassification".Equals(TaskType)){ #>
5252
Console.WriteLine($"Single Prediction --> Actual value: {sampleData.<#= Utils.Normalize(LabelName) #>} | Predicted value: {predictionResult.Prediction}");
@@ -62,18 +62,18 @@ namespace <#= Namespace #>.ConsoleApp
6262

6363
// Method to load single row of data to try a single prediction
6464
// You can change this code and create your own sample data here (Hardcoded or from any source)
65-
private static SampleObservation CreateSingleDataSample(MLContext mlContext, string dataFilePath)
65+
private static ModelInput CreateSingleDataSample(MLContext mlContext, string dataFilePath)
6666
{
6767
// Read dataset to get a single row for trying a prediction
68-
IDataView dataView = mlContext.Data.LoadFromTextFile<SampleObservation>(
68+
IDataView dataView = mlContext.Data.LoadFromTextFile<ModelInput>(
6969
path: dataFilePath,
7070
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
7171
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',
7272
allowQuoting : <#= AllowQuoting.ToString().ToLowerInvariant() #>,
7373
allowSparse: <#= AllowSparse.ToString().ToLowerInvariant() #>);
7474

75-
// Here (SampleObservation object) you could provide new test data, hardcoded or from the end-user application, instead of the row from the file.
76-
SampleObservation sampleForPrediction = mlContext.Data.CreateEnumerable<SampleObservation>(dataView, false)
75+
// Here (ModelInput object) you could provide new test data, hardcoded or from the end-user application, instead of the row from the file.
76+
ModelInput sampleForPrediction = mlContext.Data.CreateEnumerable<ModelInput>(dataView, false)
7777
.First();
7878
return sampleForPrediction;
7979
}

src/mlnet/mlnet.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
<AutoGen>True</AutoGen>
4949
<DependentUpon>ModelProject.tt</DependentUpon>
5050
</Compile>
51-
<Compile Update="Templates\Console\ObservationClass.cs">
51+
<Compile Update="Templates\Console\ModelInputClass.cs">
5252
<DesignTime>True</DesignTime>
5353
<AutoGen>True</AutoGen>
54-
<DependentUpon>ObservationClass.tt</DependentUpon>
54+
<DependentUpon>ModelInputClass.tt</DependentUpon>
5555
</Compile>
56-
<Compile Update="Templates\Console\PredictionClass.cs">
56+
<Compile Update="Templates\Console\ModelOutputClass.cs">
5757
<DesignTime>True</DesignTime>
5858
<AutoGen>True</AutoGen>
59-
<DependentUpon>PredictionClass.tt</DependentUpon>
59+
<DependentUpon>ModelOutputClass.tt</DependentUpon>
6060
</Compile>
6161
<Compile Update="Templates\Console\PredictProgram.cs">
6262
<DesignTime>True</DesignTime>
@@ -90,13 +90,13 @@
9090
<Generator>TextTemplatingFilePreprocessor</Generator>
9191
<LastGenOutput>ModelProject.cs</LastGenOutput>
9292
</None>
93-
<None Update="Templates\Console\ObservationClass.tt">
93+
<None Update="Templates\Console\ModelInputClass.tt">
9494
<Generator>TextTemplatingFilePreprocessor</Generator>
95-
<LastGenOutput>ObservationClass.cs</LastGenOutput>
95+
<LastGenOutput>ModelInputClass.cs</LastGenOutput>
9696
</None>
97-
<None Update="Templates\Console\PredictionClass.tt">
97+
<None Update="Templates\Console\ModelOutputClass.tt">
9898
<Generator>TextTemplatingFilePreprocessor</Generator>
99-
<LastGenOutput>PredictionClass.cs</LastGenOutput>
99+
<LastGenOutput>ModelOutputClass.cs</LastGenOutput>
100100
</None>
101101
<None Update="Templates\Console\PredictProgram.tt">
102102
<Generator>TextTemplatingFilePreprocessor</Generator>

0 commit comments

Comments
 (0)