Skip to content

Accessibility Problem of FastTree through Dynamic APIs #2319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wschin opened this issue Jan 30, 2019 · 1 comment
Closed

Accessibility Problem of FastTree through Dynamic APIs #2319

wschin opened this issue Jan 30, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@wschin
Copy link
Member

wschin commented Jan 30, 2019

The following examples shows a way to retrieved the underlying model learned by a trainer, but I failed compiling it. For static APIs, we are able to assign FastTreeRegressionModelParameters to pred but in the corresponding dynamic API, the type of p becomes

Microsoft.ML.Data.BinaryPredictionTransformer<Microsoft.ML.Internal.Internallearn.IPredictorWithFeatureWeights<float>>

, which doesn't publicly expose `FastTreeRegressionModelParameters as one of its field.

            var data = new TextLoader(Env,
                    new TextLoader.Arguments()
                    {
                        Separator = ";",
                        HasHeader = true,
                        Column = new[]
                        {
                            new TextLoader.Column("Features", DataKind.R4, 0, 10),
                            new TextLoader.Column("Label", DataKind.R4, 11)
                        }
                    }).Read(GetDataPath(TestDatasets.generatedRegressionDataset.trainFilename));


            var trainer = ML.BinaryClassification.Trainers.FastTree(
                new FastTreeBinaryClassificationTrainer.Options
                {
                    NumThreads = 1,
                    NumTrees = 10,
                    NumLeaves = 5,
                });

            FastTreeRegressionModelParameters pred = null;
            trainer.WithOnFitDelegate((p) => { pred = p; });

Any tricks I can use to make this code example compiled without using internal classes? Or we need to modify our dynamic APIs?

cc @TomFinley, @Ivanidzo4ka, @sfilipi, @zeahmed.

We also should add an example using public interfaces introduced in #2243 after fixing this issue.

@wschin wschin added the bug Something isn't working label Jan 30, 2019
@wschin wschin self-assigned this Jan 30, 2019
@wschin
Copy link
Member Author

wschin commented Jan 30, 2019

In addition to regression, I can also demonstrate a related bug using FastTree for binary classification.

            var ml = new MLContext(seed: 1, conc: 1);
            var data = ml.Data.ReadFromTextFile<SentimentData>(GetDataPath(TestDatasets.Sentiment.trainFilename), hasHeader: true);

            var trainer = ml.BinaryClassification.Trainers.FastTree(numLeaves: 5, numTrees: 3);

            BinaryPredictionTransformer<IPredictorWithFeatureWeights<float>> pred = null;
            var decoratedTrainer = trainer.WithOnFitDelegate((p) =>
                {
                    pred = p; // This line will never be executed.
                }
            );

            var pipeline = ml.Transforms.Text.FeaturizeText("SentimentText", "Features")
                .AppendCacheCheckpoint(ml)
                .Append(decoratedTrainer); // Replace "decoratedTrainer" with "trainer" will not trigger the assignment of pred, so pred will be bull.

            // Train.
            var model = pipeline.Fit(data);

Basically, the onFit is not implemented for at least FastTree and SDCA.
[Update] This is a false alarm. Please see the change made in the last edit.

@wschin wschin changed the title Accessibility Problem of FastTreeRegressionModelParameters through Dynamic APIs Accessibility Problem of FastTree and SDCA through Dynamic APIs Jan 30, 2019
@wschin wschin changed the title Accessibility Problem of FastTree and SDCA through Dynamic APIs Accessibility Problem of FastTree through Dynamic APIs Feb 1, 2019
@wschin wschin closed this as completed Feb 2, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant