dotnet / dotnet/machinelearning-samples

Convert Sentiment Analysis model to onnx

Aperta
#874 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PowerShell
Stelle
4.7k
Fork
2.7k
Merge medio
2g 22h
PR unite (30g)
1

Descrizione

Hi,

I have been following the tutorial on "Sentiment Analysis" (https://docs.microsoft.com/es-es/dotnet/machine-learning/tutorials/sentiment-analysis), which is really nice, interesting and useful. However, I have stumbled on the first step further. I am trying to export the generated model to onnx with the following code:

```
// Converts model to onnx
ConvertModel2ONNX(mlContext, model, splitDataView.TestSet);
```

mlContext, model and splitDataView come from the functions explainned in the tutorial.

```
public static void ConvertModel2ONNX(MLContext mlContext, ITransformer model, IDataView splitTestSet)
{
using (var stream = File.Create(_onnxPath))
{
mlContext.Model.ConvertToOnnx(model, splitTestSet, stream);
}
}
```

where _onnxPath is the output path for the onnx file.

However, I get the following error.

```
System.Collections.Generic.KeyNotFoundException
HResult=0x80131577
Message=The given key 'SentimentText_TextNormalizer' was not present in the dictionary.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowKeyNotFoundException[T](T key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.ML.Model.OnnxConverter.OnnxContextImpl.GetVariableName(String colName)
at Microsoft.ML.Transforms.Text.WordTokenizingTransformer.Mapper.SaveAsOnnx(OnnxContext ctx)
at Microsoft.ML.Data.RowToRowMapperTransform.Microsoft.ML.Model.OnnxConverter.ISaveAsOnnx.SaveAsOnnx(OnnxContext ctx)
at Microsoft.ML.Model.OnnxConverter.SaveOnnxCommand.ConvertTransformListToOnnxModel(OnnxContextImpl ctx, IChannel ch, IDataView inputData, IDataView outputData, LinkedList`1 transforms, HashSet`1 inputColumnNamesToDrop, HashSet`1 outputColumnNamesToDrop)
at Microsoft.ML.OnnxExportExtensions.ConvertToOnnxProtobufCore(IHostEnvironment env, OnnxContextImpl ctx, ITransformer transform, IDataView inputData, String[] outputColumnNamesToKeep)
at Microsoft.ML.OnnxExportExtensions.ConvertToOnnxProtobuf(ModelOperationsCatalog catalog, ITransformer transform, IDataView inputData, String[] outputColumns)
at Microsoft.ML.OnnxExportExtensions.ConvertToOnnx(ModelOperationsCatalog catalog, ITransformer transform, IDataView inputData, Stream stream)
at SentimentAnalysis.Program.ConvertModel2ONNX(MLContext mlContext, ITransformer model, IDataView splitTestSet) in C:\SentimentAnalysis\Program.cs:line 164
at SentimentAnalysis.Program.Main(String[] args) in C:\SentimentAnalysis\Program.cs:line 41
```

What could be the reason? I do not know if this question has a place here. If not, please forgive me for the inconvenience and ignore my question. Thank you very much.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il tutorial Sentiment Analysis e con il punto di ingresso ConvertModel2ONNX in Program.cs, prestando particolare attenzione alla chiamata alla riga 164 e allo stack trace che menziona WordTokenizingTransformer. Riproduci l’esportazione con il modello e i dati di test mostrati, quindi traccia come viene gestita la colonna SentimentText_TextNormalizer. Il lavoro è completo quando è stata identificata la causa della mappatura della colonna mancante e il comportamento dell’esportazione è stato confermato oppure la limitazione è stata documentata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
machine-learning
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.