dotnet / dotnet/machinelearning

VectorType attribute with dynamic dimension while dealing with csv files

Open
#6,151 4 comments 0 reactions 0 assignees View on GitHub
area-Core bug Priority:2
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

I am working on training and evaluation in ML.NET. The data comes from a .csv file. According to the requirements, there may be variable number of columns in the file. Until now, I have achieved this by providing a fixed vectorType dimension. But I am not aware of making this work dynamically.

Here is the a block of code working using the fixed dimension,

public class InputClass
{
public bool Lavel;

[VectorType(5)] // I want this to be dynamic
public string[] SpecVec;

public string PredictedTarget;
}

public static void Main(string[] args)
{
MLContext mlContext = new MLContext(seed:0);
TextLoader.Columns[] columns = new TextLoader.Columns[3];
columns[0] = new TextLoader.Column("Label", DataKind.Boolean, 0);
columns[2] = new TextLoader.Column("PredictedTarget", DataKind.String, 1);
columns[1] = new TextLoader.Column("SpecVec", DataKind.String, 2,6);

IDataView dataview = mlContext.Data.LoadFromTextFile(filepath, columns,
separatorChar:',', hasHeader:true, allowQuoting:false, trimWhitespace: true,
allowSparse:true);

//-- creating pipeline and training a model further

}
This code works without any issue. But I just need the VectorType to accept the dimension at runtime. Now it accepts only constant values. I am looking if there is any workaround to achieve this. I am a beginner into ML.Net, please do understand if I missed any steps or anything to be explained. I really appreciate any help to get this worked.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.