Skip to content

Commit e18b52b

Browse files
Bumped version and added updates
1 parent 548492b commit e18b52b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

machine-learning/E2E-Text-Classification-API-with-Yelp-Dataset.ipynb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
"\n",
5454
"- [`Microsoft.ML`](https://www.nuget.org/packages/Microsoft.ML/)\n",
5555
"- [`Microsoft.ML.TorchSharp`](https://www.nuget.org/packages/Microsoft.ML.TorchSharp/)\n",
56-
"- [`TorchSharp-cpu`](https://www.nuget.org/packages/TorchSharp-cpu/) if you're using a CPU or [`TorchSharp-cuda-windows`](https://www.nuget.org/packages/TorchSharp-cuda-windows/) / [`TorchSharp-cuda-linux`](https://www.nuget.org/packages/TorchSharp-cuda-linux/) if you're using a GPU."
56+
"- [`TorchSharp-cpu`](https://www.nuget.org/packages/TorchSharp-cpu/) if you're using a CPU or [`TorchSharp-cuda-windows`](https://www.nuget.org/packages/TorchSharp-cuda-windows/) / [`TorchSharp-cuda-linux`](https://www.nuget.org/packages/TorchSharp-cuda-linux/) if you're using a GPU.\n",
57+
"\n",
58+
"To enable GPU support, you'll also have to install the CUDA dependencies. For more information, see the [GPU support guide](https://docs.microsoft.com/dotnet/machine-learning/how-to-guides/install-gpu-model-builder#install-dependencies)."
5759
]
5860
},
5961
{
@@ -65,16 +67,18 @@
6567
}
6668
},
6769
"source": [
68-
"#r \"nuget:Microsoft.ML,2.0.0-preview.22313.1\"\n",
69-
"#r \"nuget:Microsoft.ML.TorchSharp,0.20.0-preview.22313.1\"\n",
70+
"#i \"nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json\"\n",
71+
"\n",
72+
"#r \"nuget:Microsoft.ML,2.0.0-preview.22324.1\"\n",
73+
"#r \"nuget:Microsoft.ML.TorchSharp,0.20.0-preview.22324.1\"\n",
7074
"#r \"nuget:TorchSharp-cpu,0.96.7\"\n",
71-
"#r \"nuget:Microsoft.Data.Analysis,0.20.0-preview.22313.1\""
75+
"#r \"nuget:Microsoft.Data.Analysis,0.20.0-preview.22324.1\""
7276
],
7377
"outputs": [
7478
{
7579
"output_type": "execute_result",
7680
"data": {
77-
"text/html": "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Data.Analysis, 0.20.0-preview.22313.1</span></li><li><span>Microsoft.ML, 2.0.0-preview.22313.1</span></li><li><span>Microsoft.ML.TorchSharp, 0.20.0-preview.22313.1</span></li><li><span>TorchSharp-cpu, 0.96.7</span></li></ul></div></div>"
81+
"text/html": "<div><div><strong>Restore sources</strong><ul><li><span>https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json</span></li></ul></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Data.Analysis, 0.20.0-preview.22324.1</span></li><li><span>Microsoft.ML, 2.0.0-preview.22324.1</span></li><li><span>Microsoft.ML.TorchSharp, 0.20.0-preview.22324.1</span></li><li><span>TorchSharp-cpu, 0.96.7</span></li></ul></div></div>"
7882
},
7983
"execution_count": 1,
8084
"metadata": {}
@@ -205,7 +209,7 @@
205209
{
206210
"output_type": "execute_result",
207211
"data": {
208-
"text/html": "<table id=\"table_637907545650178735\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Wow... Loved this place.</td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>Crust is not good.</td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>Not tasty and the texture was just nasty.</td><td><div class=\"dni-plaintext\">0</div></td></tr></tbody></table>"
212+
"text/html": "<table id=\"table_637919371773035870\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Wow... Loved this place.</td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>Crust is not good.</td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>Not tasty and the texture was just nasty.</td><td><div class=\"dni-plaintext\">0</div></td></tr></tbody></table>"
209213
},
210214
"execution_count": 1,
211215
"metadata": {}
@@ -268,7 +272,7 @@
268272
"source": [
269273
"var pipeline =\n",
270274
"\t\tmlContext.Transforms.Conversion.MapValueToKey(\"Label\",\"Sentiment\")\n",
271-
"\t\t\t.Append(mlContext.MulticlassClassification.Trainers.TextClassification(numberOfClasses: 2, sentence1ColumnName: \"Text\"))\n",
275+
"\t\t\t.Append(mlContext.MulticlassClassification.Trainers.TextClassification(sentence1ColumnName: \"Text\"))\n",
272276
"\t\t\t.Append(mlContext.Transforms.Conversion.MapKeyToValue(\"PredictedLabel\"));"
273277
],
274278
"outputs": []
@@ -361,7 +365,7 @@
361365
{
362366
"output_type": "execute_result",
363367
"data": {
364-
"text/html": "<table id=\"table_637907582471037219\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th><th>PredictedLabel</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Oh this is such a thing of beauty, this restaurant.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>A greasy, unhealthy meal.</td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>The best place in Vegas for breakfast (just check out a Sat, or Sun.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr></tbody></table>"
368+
"text/html": "<table id=\"table_637919373979111360\"><thead><tr><th><i>index</i></th><th>Text</th><th>Sentiment</th><th>PredictedLabel</th></tr></thead><tbody><tr><td><i><div class=\"dni-plaintext\">0</div></i></td><td>Oh this is such a thing of beauty, this restaurant.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">0</div></td></tr><tr><td><i><div class=\"dni-plaintext\">1</div></i></td><td>A greasy, unhealthy meal.</td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">1</div></td></tr><tr><td><i><div class=\"dni-plaintext\">2</div></i></td><td>The best place in Vegas for breakfast (just check out a Sat, or Sun.</td><td><div class=\"dni-plaintext\">1</div></td><td><div class=\"dni-plaintext\">1</div></td></tr></tbody></table>"
365369
},
366370
"execution_count": 1,
367371
"metadata": {}
@@ -379,9 +383,7 @@
379383
"cell_type": "markdown",
380384
"metadata": {},
381385
"source": [
382-
"There's a variety of metrics you can use to evaluate how well your model performs. In this case, you'll calculate the model's accuracy. \n",
383-
"\n",
384-
"Start by taking the instances where the actual value matches the predicted value, also known as the true positives (TP) and true negatives (TN)."
386+
"There's a variety of metrics you can use to evaluate how well your model performs. Use the [Evaluate](https://docs.microsoft.com/dotnet/api/microsoft.ml.multiclassclassificationcatalog.evaluate?view=ml-dotnet) method to calculate the evaluation metrics for your model using the predictions `IDataView`."
385387
]
386388
},
387389
{
@@ -393,17 +395,18 @@
393395
}
394396
},
395397
"source": [
396-
"var tptn = \n",
397-
"\tpredictions.Filter(\n",
398-
"\t\tpredictions[\"Sentiment\"].ElementwiseEquals(predictions[\"PredictedLabel\"]));"
398+
"var evaluationMetrics = \n",
399+
"\tmlContext\n",
400+
"\t\t.MulticlassClassification\n",
401+
"\t\t.Evaluate(predictionIDV);"
399402
],
400403
"outputs": []
401404
},
402405
{
403406
"cell_type": "markdown",
404407
"metadata": {},
405408
"source": [
406-
"Then, divide the number of instances where the actual value matches the predicted value by the total number of predictions. "
409+
"Then, display the evaluation metrics. For more information on multiclass classification evaluation metrics, see the [ML.NET evaluation metrics guide](https://docs.microsoft.com/dotnet/machine-learning/resources/metrics#evaluation-metrics-for-multi-class-classification)."
407410
]
408411
},
409412
{
@@ -415,15 +418,13 @@
415418
}
416419
},
417420
"source": [
418-
"var accuracy = ((float) tptn.Rows.Count / (float) predictions.Rows.Count);\n",
419-
"\n",
420-
"$\"Accuracy: {accuracy:0.####}\""
421+
"evaluationMetrics"
421422
],
422423
"outputs": [
423424
{
424425
"output_type": "execute_result",
425426
"data": {
426-
"text/plain": "Accuracy: 0.56"
427+
"text/html": "<table><thead><tr><th>LogLoss</th><th>LogLossReduction</th><th>MacroAccuracy</th><th>MicroAccuracy</th><th>TopKAccuracy</th><th>TopKPredictionCount</th><th>TopKAccuracyForAllK</th><th>PerClassLogLoss</th><th>ConfusionMatrix</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">10.53512863047496</div></td><td><div class=\"dni-plaintext\">-14.199291365827746</div></td><td><div class=\"dni-plaintext\">0.6737016700983757</div></td><td><div class=\"dni-plaintext\">0.6737967914438503</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">&lt;null&gt;</div></td><td><div class=\"dni-plaintext\">[ 10.940300196581468, 10.134267400178105 ]</div></td><td><div class=\"dni-plaintext\">{ Microsoft.ML.Data.ConfusionMatrix: PerClassPrecision: [ 0.6777777777777778, 0.6701030927835051 ], PerClassRecall: [ 0.6559139784946236, 0.6914893617021277 ], Counts: [ [ 61, 32 ], [ 29, 65 ] ], NumberOfClasses: 2 }</div></td></tr></tbody></table>"
427428
},
428429
"execution_count": 1,
429430
"metadata": {}

0 commit comments

Comments
 (0)