Skip to content

Commit cbf05ac

Browse files
authored
Update Readme to fix code sample (#2887)
* fix Readme to compile & run * fix comment
1 parent 037cc6d commit cbf05ac

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,22 @@ For more information, see the [.NET Foundation Code of Conduct](https://dotnetfo
6868
Here'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";
7173
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+
});
7983
var data = loader.Load(dataPath);
8084
var learningPipeline = mlContext.Transforms.Text.FeaturizeText("Features", "SentimentText")
81-
.Append(mlContext.BinaryClassification.Trainers.FastTree());
85+
.Append(mlContext.BinaryClassification.Trainers.FastTree());
8286
var model = learningPipeline.Fit(data);
83-
8487
```
8588

8689
Now from the model we can make inferences (predictions):

0 commit comments

Comments
 (0)