Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

NimbusML trains model that ML.NET thinks is corrupted #13

Closed
@GalOshri

Description

@GalOshri
  1. Train a model with NimbusML 0.6 using code below
  2. Save model to disk
  3. Try and use the saved model in ML.NET 0.6

Expected: model can be used in ML.NET
Actual: I see the error shown below.

Unhandled Exception: System.FormatException: Corrupt model file
   at Microsoft.ML.Runtime.Model.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
   at Microsoft.ML.Runtime.Data.TransformerChain.LoadFrom(IHostEnvironment env, Stream stream)
   at nimbusmlnet.Program.Main(String[] args) in /Users/gal/Projects/NimbusML/nimbusmlnet/Program.cs:line 19

Python training code:

train_datapath = '/Users/gal/Projects/NimbusML/Sent_Train.tsv'
test_datapath = '/Users/gal/Projects/NimbusML/Sent_Test.tsv'
schema = DataSchema.read_schema(train_datapath, sep='\t', numeric_dtype=np.float32)
train_data = FileDataStream.read_csv(train_datapath, sep='\t', schema=schema)
test_data = FileDataStream.read_csv(test_datapath, sep='\t', schema=schema)
print(train_data.schema)

pipeline = Pipeline([
    TakeFilter(10000),
    NGramFeaturizer(word_feature_extractor=Ngram(weighting = 'TfIdf',
                                                             ngram_length=2),
                                char_feature_extractor=Ngram(weighting = 'Tf',
                                                             ngram_length=3),
                                columns = {"Features": "SentimentText"}),
    AveragedPerceptronBinaryClassifier(num_iterations = 10, feature="Features", label="Sentiment")
])
pipeline.fit(train_data)
pipeline.save_model("sent_model.zip")

ML.NET prediction code:

var env = new ConsoleEnvironment();
ITransformer loadedModel;
using (var file = File.OpenRead("../sent_model.zip"))
    loadedModel = TransformerChain.LoadFrom(env, file);

var predictor = loadedModel.MakePredictionFunction<SentimentData, SentimentPrediction>(env);

var prediction = predictor.Predict(new SentimentData
{
    SentimentText = "I am so happy!",
    Sentiment = 0
});
Console.WriteLine(prediction.Probability);
Console.ReadLine();

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions