dotnet / dotnet/machinelearning-samples

Porting samples to PowerShell

Offen
#407 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
follow-up
Vorherrschende Sprache
PowerShell
Sterne
4.7k
Forks
2.7k
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
1

Beschreibung

I'm experimenting with translating some samples from C# to PowerShell (Sentiment Analysis for now). PS doesn't support (work well) with some C# features (like extension methods, attributes, etc), but it doesn't feel impossible to port it. At this point I'm struggling with executing fit method after appending Trainer to Estimator. When I follow C# sample, I'm getting "Shuffle input cursor reader" error. If I change trainer option to disable shuffling I'm getting "Splitter/consolidator worker" error. Interestingly, if I apply fit directly on estimator I'm not getting errors, and run prediction/evaluation with some dummy results. Getting same error on PS 5.1 and core 6.2. C# sample works fine on the same machine (with dotnet run).
So at least I want to clarify if there is any blocker for PS to interact with ml.net I think it would be extremely useful to port it to PS, so even non-developers might use it. Below is my code (it will export data set and libraries if needed)
```powershell
<# Downloading assemblies and data set

# download nuget if needed
# iwr "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "nuget.exe"

nuget install Microsoft.ML -version 1.0.0-preview

mkdir bin

gci "*\lib\netstandard*\*.dll" | copy-item -Destination ".\bin"

$url = "https://raw.githubusercontent.com/lucasalexander/mlnet-samples/master/sentiment-analysis/data/yelp_labelled.txt"
Invoke-WebRequest -Uri $url -OutFile "yelp_labelled.txt"

#>

Add-Type -Path "$pwd\bin\*.dll"

$dataPath = "$pwd\yelp_labelled.txt"

$mlCOntext = [Microsoft.ML.MLContext]::new()

$columns = [System.Collections.Generic.List``1[Microsoft.ML.Data.TextLoader+Column]]::new()

$columns.Add([Microsoft.ML.Data.TextLoader+Column]::new("SentimentText", "String", 0))
$columns.Add([Microsoft.ML.Data.TextLoader+Column]::new("Label", "Boolean", 1))

$columns.Add([Microsoft.ML.Data.TextLoader+Column]::new("PredictedLabel", "Boolean", 2))
$columns.Add([Microsoft.ML.Data.TextLoader+Column]::new("Probability", "Single", 3))
$columns.Add([Microsoft.ML.Data.TextLoader+Column]::new("Score", "Single", 4))

$opt = [Microsoft.ML.Data.TextLoader+Options]::new()
$opt.Separators = "`t"
$opt.Columns = $columns
$opt.HasHeader = $false

$dataView = [Microsoft.ML.TextLoaderSaverCatalog]::LoadFromTextFile($mlCOntext.Data, $dataPath, $opt)

# preview data
# [Microsoft.ML.DebuggerExtensions]::Preview($dataView).rowview | foreach { $_.Values.Value -join " | " }

$splitDataView = $mlCOntext.Data.TrainTestSplit($dataView, 0.2)
$trainSet = $splitDataView.TrainSet
$testSet = $splitDataView.TestSet

$estimator = [Microsoft.ML.TextCatalog]::FeaturizeText($mlCOntext.Transforms.Text, "Features", "SentimentText")

$optTrain = [Microsoft.ML.Trainers.SdcaLogisticRegressionBinaryTrainer+Options]::new()
$optTrain.FeatureColumnName = "Features"
$optTrain.LabelColumnName = "Label"

# this will avoid 'Shuffle input cursor' error, but raise 'Splitter/consolidator' error
#$optTrain.Shuffle = $false

$trainer = [Microsoft.ML.StandardTrainersCatalog]::SdcaLogisticRegression($mlCOntext.BinaryClassification.Trainers, $optTrain)

$pipe = [Microsoft.ML.LearningPipelineExtensions]::Append($estimator, $trainer, "Everything")

$model = $pipe.Fit($trainSet) # GETTING ERROR HERE !

# if apply fit on estimator no error will occur and predict/evaluate block will work (with some dummy results)

# $model = $estimator.Fit($splitDataView.TrainSet)

$predict = $model.Transform($TestSet)

$mlCOntext.BinaryClassification.Evaluate($predict, "Label")
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginnen Sie damit, die bereitgestellte PowerShell-Reproduktion über $pipe.Fit($trainSet) auszuführen, und vergleichen Sie sie anschließend auf derselben Maschine mit dem funktionierenden C#-Beispiel zur Sentimentanalyse. Verfolgen Sie die gemeldeten Fehler „Shuffle input cursor reader“ und „Splitter/consolidator worker“ zurück; als erledigt gilt die Aufgabe, wenn dokumentiert ist, ob die Interaktion zwischen PowerShell und ML.NET blockiert ist, und eine bestätigte funktionierende oder minimal fehlschlagende Reproduktion bereitgestellt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, powershell
Bereich
machine-learning
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.