Skip to content

Consider providing a source generator to generate ModelInput/Output class? #6156

Open

Description

@LittleLittleCloud

schema should contain all required information to generate both input/output class

Usage

  • add model.zip as AdditionalFiles and set IsMLNetModel to true
    image

  • mlnet generate both input and output class for project

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ML;
using Microsoft.ML.Data;

namespace MLNetSourceGenerator.CodeGen
{

public class TitanicInput
{
[ColumnName(@"PassengerId")]
public float PassengerId {get; set;}

[ColumnName(@"Survived")]
public float Survived {get; set;}

[ColumnName(@"Pclass")]
public float Pclass {get; set;}

[ColumnName(@"Name")]
public string Name {get; set;}

[ColumnName(@"Sex")]
public string Sex {get; set;}

[ColumnName(@"Age")]
public float Age {get; set;}

[ColumnName(@"SibSp")]
public float SibSp {get; set;}

[ColumnName(@"Parch")]
public float Parch {get; set;}

[ColumnName(@"Ticket")]
public string Ticket {get; set;}

[ColumnName(@"Fare")]
public float Fare {get; set;}

[ColumnName(@"Cabin")]
public string Cabin {get; set;}

[ColumnName(@"Embarked")]
public string Embarked {get; set;}

}


public class TitanicOutput
{
[ColumnName(@"PassengerId")]
public float PassengerId {get; set;}

[ColumnName(@"Survived")]
public uint Survived {get; set;}

[ColumnName(@"Pclass")]
public float Pclass {get; set;}

[ColumnName(@"Name")]
public float[] Name {get; set;}

[ColumnName(@"Sex")]
public float[] Sex {get; set;}

[ColumnName(@"Age")]
public float Age {get; set;}

[ColumnName(@"SibSp")]
public float SibSp {get; set;}

[ColumnName(@"Parch")]
public float Parch {get; set;}

[ColumnName(@"Ticket")]
public float[] Ticket {get; set;}

[ColumnName(@"Fare")]
public float Fare {get; set;}

[ColumnName(@"Cabin")]
public float[] Cabin {get; set;}

[ColumnName(@"Embarked")]
public float[] Embarked {get; set;}

[ColumnName(@"Features")]
public float[] Features {get; set;}

[ColumnName(@"PredictedLabel")]
public float PredictedLabel {get; set;}

[ColumnName(@"Score")]
public float[] Score {get; set;}

}

}

Example

Activity

  1. ghost added
    untriagedNew issue has not been triaged
    on Apr 14, 2022
  2. changed the title [-]Consider generating ModelInput/Output class from mlnet model via source generator?[/-] [+]Consider providing a source generator to generate ModelInput/Output class?[/+] on Apr 15, 2022
  3. michaelgsharp commented on Apr 27, 2022

    @michaelgsharp
    Contributor

    I think this is something that would be good to do. Have you looked into this at all @LittleLittleCloud?

    @luisquintanilla I'm going to add this to the future milestone. We can move it around as desired.

  4. added this to the ML.NET Future milestone on Apr 27, 2022
  5. ghost removed
    untriagedNew issue has not been triaged
    on Apr 27, 2022
  6. luisquintanilla commented on Apr 27, 2022

    @luisquintanilla
    Contributor
  7. luisquintanilla commented on Apr 27, 2022

    @luisquintanilla
    Contributor

    Thanks @michaelgsharp I agree to put this in Future milestone. One concern I'd have with Source Generators would be they're not available in F#.

  8. added
    Priority:2Work that is important, but not critical for the release
    area-AutoMLAutomated machine learning, Model Builder, and ML.NET CLI
    and removed on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasearea-AutoMLAutomated machine learning, Model Builder, and ML.NET CLIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions