@@ -35,7 +35,6 @@ public virtual string TransformText()
35
35
using Microsoft.ML;
36
36
using Microsoft.ML.Core.Data;
37
37
using Microsoft.ML.Data;
38
- using static Microsoft.ML.Data.TextLoader;
39
38
using Microsoft.Data.DataView;
40
39
" ) ;
41
40
this . Write ( this . ToStringHelper . ToStringWithCulture ( GeneratedUsings ) ) ;
@@ -70,28 +69,49 @@ static void Main(string[] args)
70
69
71
70
private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)
72
71
{
73
- // Common data loading configuration
74
- TextLoader textLoader = GetTextLoader(mlContext);
75
-
76
- IDataView trainingDataView = textLoader.Read(TrainDataPath);
77
- " ) ;
72
+ // Data loading
73
+ IDataView trainingDataView = mlContext.Data.ReadFromTextFile<SampleObservation>(
74
+ path: TrainDataPath,
75
+ hasHeader : " ) ;
76
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( HasHeader . ToString ( ) . ToLowerInvariant ( ) ) ) ;
77
+ this . Write ( ",\r \n separatorChar : \' " ) ;
78
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( Separator ) ) ;
79
+ this . Write ( "\' ,\r \n allowQuotedStrings : " ) ;
80
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowQuoting . ToString ( ) . ToLowerInvariant ( ) ) ) ;
81
+ this . Write ( ",\r \n trimWhitespace : " ) ;
82
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( TrimWhiteSpace . ToString ( ) . ToLowerInvariant ( ) ) ) ;
83
+ this . Write ( " ,\r \n supportSparse : " ) ;
84
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowSparse . ToString ( ) . ToLowerInvariant ( ) ) ) ;
85
+ this . Write ( ");\r \n " ) ;
78
86
if ( ! string . IsNullOrEmpty ( TestPath ) ) {
79
- this . Write ( " IDataView testDataView = textLoader.Read(TestDataPath);\r \n " ) ;
87
+ this . Write ( " IDataView testDataView = mlContext.Data.ReadFromTextFile<SampleObserv" +
88
+ "ation>(\r \n path: TestDataPath,\r \n " +
89
+ " hasHeader : " ) ;
90
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( HasHeader . ToString ( ) . ToLowerInvariant ( ) ) ) ;
91
+ this . Write ( ",\r \n separatorChar : \' " ) ;
92
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( Separator ) ) ;
93
+ this . Write ( "\' ,\r \n allowQuotedStrings : " ) ;
94
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowQuoting . ToString ( ) . ToLowerInvariant ( ) ) ) ;
95
+ this . Write ( ",\r \n trimWhitespace : " ) ;
96
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( TrimWhiteSpace . ToString ( ) . ToLowerInvariant ( ) ) ) ;
97
+ this . Write ( " ,\r \n supportSparse : " ) ;
98
+ this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowSparse . ToString ( ) . ToLowerInvariant ( ) ) ) ;
99
+ this . Write ( ");\r \n " ) ;
80
100
}
81
101
this . Write ( "\r \n " ) ;
82
102
if ( Transforms . Count > 0 ) {
83
103
this . Write ( " // Common data process configuration with pipeline data transformatio" +
84
104
"ns \r \n \r \n var dataProcessPipeline = " ) ;
85
105
for ( int i = 0 ; i < Transforms . Count ; i ++ )
86
- {
87
- if ( i > 0 )
88
- { Write ( "\n .Append(" ) ;
89
- }
90
- Write ( "mlContext.Transforms." + Transforms [ i ] ) ;
91
- if ( i > 0 )
92
- { Write ( ")" ) ;
93
- }
94
- }
106
+ {
107
+ if ( i > 0 )
108
+ { Write ( "\n .Append(" ) ;
109
+ }
110
+ Write ( "mlContext.Transforms." + Transforms [ i ] ) ;
111
+ if ( i > 0 )
112
+ { Write ( ")" ) ;
113
+ }
114
+ }
95
115
this . Write ( ";\r \n " ) ;
96
116
}
97
117
this . Write ( "\r \n // Set the training algorithm, then create and config the modelBuil" +
@@ -157,30 +177,23 @@ private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)
157
177
return trainedModel;
158
178
}
159
179
160
- private static TextLoader GetTextLoader(MLContext mlContext)
180
+ // (OPTIONAL) Try/test a single prediction by loding the model from the file, first.
181
+ private static void TestSinglePrediction(MLContext mlContext)
161
182
{
162
- return mlContext.Data.CreateTextLoader<SampleObservation>(
163
- hasHeader : " ) ;
183
+ //Load data to test. Could be any test data. For demonstration purpose train data is used here.
184
+ IDataView trainingDataView = mlContext.Data.ReadFromTextFile<SampleObservation>(
185
+ path: TrainDataPath,
186
+ hasHeader : " ) ;
164
187
this . Write ( this . ToStringHelper . ToStringWithCulture ( HasHeader . ToString ( ) . ToLowerInvariant ( ) ) ) ;
165
- this . Write ( ",\r \n separatorChar : \' " ) ;
188
+ this . Write ( ",\r \n separatorChar : \' " ) ;
166
189
this . Write ( this . ToStringHelper . ToStringWithCulture ( Separator ) ) ;
167
- this . Write ( "\' ,\r \n allowQuotedStrings : " ) ;
190
+ this . Write ( "\' ,\r \n allowQuotedStrings : " ) ;
168
191
this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowQuoting . ToString ( ) . ToLowerInvariant ( ) ) ) ;
169
- this . Write ( ",\r \n trimWhitespace : " ) ;
192
+ this . Write ( ",\r \n trimWhitespace : " ) ;
170
193
this . Write ( this . ToStringHelper . ToStringWithCulture ( TrimWhiteSpace . ToString ( ) . ToLowerInvariant ( ) ) ) ;
171
- this . Write ( " ,\r \n supportSparse : " ) ;
194
+ this . Write ( " ,\r \n supportSparse : " ) ;
172
195
this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowSparse . ToString ( ) . ToLowerInvariant ( ) ) ) ;
173
- this . Write ( @"
174
- );
175
- }
176
-
177
- // (OPTIONAL) Try/test a single prediction by loding the model from the file, first.
178
- private static void TestSinglePrediction(MLContext mlContext)
179
- {
180
- TextLoader textLoader = GetTextLoader(mlContext);
181
-
182
- //Load data to test. Could be any test data. For demonstration purpose train data is used here.
183
- IDataView trainingDataView = textLoader.Read(TrainDataPath);
196
+ this . Write ( @");
184
197
185
198
var sample = mlContext.CreateEnumerable<SampleObservation>(trainingDataView, false).First();
186
199
0 commit comments