Skip to content

Exception when converting PredictedLabel from Key To Value #3090

@daholste

Description

@daholste

When trying to convert the output PredictedLabel from key back to value, the exception

System.InvalidOperationException
  HResult=0x80131509
  Message=Metadata KeyValues does not exist
  Source=Microsoft.ML.Core
  StackTrace:
   at Microsoft.ML.Runtime.Contracts.Check(IExceptionContext ctx, Boolean f, String msg) in C:\MLDotNet2\src\Microsoft.ML.Core\Utilities\Contracts.cs:line 497

is thrown.

Code to repro:

var mlContext = new MLContext();

var textLoaderOptions = new TextLoader.Options()
{
	Columns = new[]
	{
		new TextLoader.Column("Label", DataKind.Single, 0),
		new TextLoader.Column("Row", DataKind.Single, 1),
		new TextLoader.Column("Column", DataKind.Single, 2),
	},
	HasHeader = true,
	Separators = new[] { '\t' }
};
var textLoader = mlContext.Data.CreateTextLoader(textLoaderOptions);
var data = textLoader.Load(@"C:\MLDotNet2\test\data\trivial-train.tsv");

var ap = mlContext.BinaryClassification.Trainers.AveragedPerceptron();
var ova = mlContext.MulticlassClassification.Trainers.OneVersusAll(ap);

var pipeline = mlContext.Transforms.Conversion.MapValueToKey("Label")
	.Append(mlContext.Transforms.Concatenate("Features", "Row", "Column"))
	.Append(ova)
	.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

var model = pipeline.Fit(data);

Replace C:\MLDotNet2\ with path to ML.NET repo on your local machine

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions