歡迎光臨
每天分享高質量文章

ML.NET 釋出0.11版本:.NET中的機器學習,為TensorFlow和ONNX添加了新功能

微軟釋出了其最新版本的機器學習框架:ML.NET 0.11帶來了新功能和突破性變化。

新版本的機器學習開源框架為TensorFlow和ONNX添加了新功能,但也包括一些重大變化, 這也是釋出RC版本之前的最後一個預覽版,這個月底將釋出0.12版本,也就是RC1。

ML.NET的創新0.11

0.11 版本的ML.NET現在還支援 TensorFlowTransformer元件中的文字輸入資料。TensorFlow模型不僅可用於影象,還可用於文字分析。這在.NET部落格的程式碼示例中進行了說明,該部落格使用TensorFlow模型進行情感分析:

public class TensorFlowSentiment

{

public string Sentiment_Text;

[VectorType(600)]

public int[] Features;

[VectorType(2)]

public float[] Prediction;

}

[TensorFlowFact]

public void TensorFlowSentimentClassificationTest()

{

var mlContext = new MLContext(seed: 1, conc: 1);

var data = new[] { new TensorFlowSentiment() { Sentiment_Text = "this film was just brilliant casting location scenery story direction everyone's really suited the part they played and you could just imagine being there robert  is an amazing actor and now the same being director  father came from the same scottish island as myself so i loved the fact there was a real connection with this film the witty remarks throughout the film were great it was just brilliant so much that i bought the film as soon as it was released for  and would recommend it to everyone to watch and the fly fishing was amazing really cried at the end it was so sad and you know what they say if you cry at a film it must have been good and this definitely was also  to the two little boy's that played the  of norman and paul they were just brilliant children are often left out of the  list i think because the stars that play them all grown up are such a big profile for the whole film but these children are amazing and should be praised for what they have done don't you think the whole story was so lovely because it was true and was someone's life after all that was shared with us all" } };

var dataView = mlContext.Data.ReadFromEnumerable(data);

var lookupMap = mlContext.Data.ReadFromTextFile(@"sentiment_model/imdb_word_index.csv",

columns: new[]

{

new TextLoader.Column("Words", DataKind.TX, 0),

new TextLoader.Column("Ids", DataKind.I4, 1),

},

separatorChar: ','

);

var estimator = mlContext.Transforms.Text.TokenizeWords("TokenizedWords", "Sentiment_Text")

.Append(mlContext.Transforms.Conversion.ValueMap(lookupMap, "Words", "Ids", new[] { ("Features", "TokenizedWords") }));

var dataPipe = estimator.Fit(dataView)

.CreatePredictionEngine(mlContext);

string modelLocation = @"sentiment_model";

var tfEnginePipe = mlContext.Transforms.ScoreTensorFlowModel(modelLocation, new[] { "Prediction/Softmax" }, new[] { "Features" })

.Append(mlContext.Transforms.CopyColumns(("Prediction", "Prediction/Softmax")))

.Fit(dataView)

.CreatePredictionEngine(mlContext);

//Predict the sentiment for the sample data

var processedData = dataPipe.Predict(data[0]);

Array.Resize(ref processedData.Features, 600);

var prediction = tfEnginePipe.Predict(processedData);

}

還為MLContext目錄添加了其他機器學習元件。這應該可以更容易地找到類和操作。該圖顯示了基於智慧提示的使用者體驗。

該ONNX元件還進行了重構:Microsoft.ML.ONNX  更改為 Microsoft.ML.ONNXConverter Microsoft.ML.ONNXTrans .FORM更改為Microsoft.ML.ONNXTransformer 。這更清晰的表達ONNX轉換和轉換之間的區別。ONNX是一種開放且可互操作的模型格式,允許您在框架中訓練模型,以及在另一個框架中使用。例如:Scikit-learn 或TensorFlow 訓練的模型放到 在ML.NET中使用。

與之前版本的ML.NET 0.10相比,ML.NET 0.11包含一些重大更改,包括刪除Microsoft.ML.Core名稱空間。破壞性性更改 串列已釋出在GitHub上。有關ML.NET 0.11中的新功能的更詳細資訊參見 .NET部落格文章:https://devblogs.microsoft.com/dotnet/announcing-ml-net-0-11-machine-learning-for-net/ 。

原文地址:https://www.cnblogs.com/shanyou/p/10516224.html

贊(0)

分享創造快樂