@@ -68,19 +68,22 @@ For more information, see the [.NET Foundation Code of Conduct](https://dotnetfo
6868Here's an example of code to train a model to predict sentiment from text samples.
6969
7070``` 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" ;
7173var 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+ });
7983var data = loader .Load (dataPath );
8084var learningPipeline = mlContext .Transforms .Text .FeaturizeText (" Features" , " SentimentText" )
81- .Append (mlContext .BinaryClassification .Trainers .FastTree ());
85+ .Append (mlContext .BinaryClassification .Trainers .FastTree ());
8286var model = learningPipeline .Fit (data );
83-
8487```
8588
8689Now from the model we can make inferences (predictions):
0 commit comments