@@ -68,19 +68,22 @@ For more information, see the [.NET Foundation Code of Conduct](https://dotnetfo
68
68
Here's an example of code to train a model to predict sentiment from text samples.
69
69
70
70
``` C#
71
+ // Path to your training tsv file. You can use machinelearning/test/data/wikipedia-detox-250-line-data.tsv
72
+ var dataPath = " wikipedia-detox-250-line-data.tsv" ;
71
73
var mlContext = new MLContext ();
72
- var loader = mlContext .Data .CreateTextLoader (new []
73
- {
74
- new TextLoader .Column (" SentimentText" , DataKind .String , 1 ),
75
- new TextLoader .Column (" Label" , DataKind .Boolean , 0 ),
76
- },
77
- hasHeader : true ,
78
- separatorChar : ',' );
74
+ var loader = mlContext .Data .CreateTextLoader (new TextLoader .Options
75
+ {
76
+ Columns = new [] {
77
+ new TextLoader .Column (" SentimentText" , DataKind .String , 1 ),
78
+ new TextLoader .Column (" Label" , DataKind .Boolean , 0 ),
79
+ },
80
+ HasHeader = true ,
81
+ Separators = new [] { ',' }
82
+ });
79
83
var data = loader .Load (dataPath );
80
84
var learningPipeline = mlContext .Transforms .Text .FeaturizeText (" Features" , " SentimentText" )
81
- .Append (mlContext .BinaryClassification .Trainers .FastTree ());
85
+ .Append (mlContext .BinaryClassification .Trainers .FastTree ());
82
86
var model = learningPipeline .Fit (data );
83
-
84
87
```
85
88
86
89
Now from the model we can make inferences (predictions):
0 commit comments