Skip to content

Ap, LinearSVM, OGD as estimators #849

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

Merged
merged 8 commits into from
Sep 8, 2018
Merged

Conversation

sfilipi
Copy link
Member

@sfilipi sfilipi commented Sep 6, 2018

Converting AveragePerceptron, LinearSVM and ODG trainers to estimators.

@sfilipi sfilipi added the API Issues pertaining the friendly API label Sep 6, 2018
@sfilipi sfilipi added this to the 0918 milestone Sep 6, 2018
@@ -52,9 +53,10 @@ public abstract class AveragedLinearArguments : OnlineLinearArguments
public Float AveragedTolerance = (Float)1e-2;
}

public abstract class AveragedLinearTrainer<TArguments, TPredictor> : OnlineLinearTrainer<TArguments, TPredictor>
public abstract class AveragedLinearTrainer<TArguments, TTransformer, TModel> : OnlineLinearTrainer<TArguments, TTransformer, TModel>
Copy link
Member Author

@sfilipi sfilipi Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TArguments [](start = 48, length = 10)

I will remove this on the next iteration, together with updating the tests. #Closed

@Zruty0 Zruty0 mentioned this pull request Sep 6, 2018
@sfilipi sfilipi changed the title WIP: Ap estimator Ap, linearSVM, OGD as estimators Sep 6, 2018
@sfilipi sfilipi changed the title Ap, linearSVM, OGD as estimators Ap, LinearSVM, OGD as estimators Sep 6, 2018
@@ -237,7 +237,7 @@ public interface IEstimator<out TTransformer>
/// <summary>
/// Train and return a transformer.
/// </summary>
TTransformer Fit(IDataView input);
TTransformer Fit(IDataView input, IDataView validationData = null, IPredictor initialPredictor = null);
Copy link
Contributor

@TomFinley TomFinley Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDataView validationData = null, IPredictor initialPredictor = null) [](start = 41, length = 69)

I am not certain I welcome this move. It seems like it is repeating the mistake of IIncrementalValidatingTrainer, which would be bad enough if it was just for trainers alone but it seems to be for absolutely every estimator. #Resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree


In reply to: 215803874 [](ancestors = 215803874)

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sfilipi ! To change such a central interface as IEstimator with a signature like this is not something we should welcome. The argument I made in #509, which I believe is absolutely correct, is that what is fed to a trainer is not something fixed now and forever. We already have beliefs about more things that ought to be given to these things. This is by itself bad enough, but to putting them in an interface specifically is an especially hazardous venture since changes to interfaces between versions is somewhat disastrous. That we're encouraging this on IEstimator which is, frankly, arguably the most important interface in the entire ecosystem, makes me very nervous. So for this reason I am very, very alarmed.

var secondTrainer = new MyAveragedPerceptron(env, new AveragedPerceptronTrainer.Arguments(), "Features", "Label");
var finalModel = secondTrainer.Train(trainData, firstModel.Model);
var secondTrainer = new AveragedPerceptronTrainer(env, new AveragedPerceptronTrainer.Arguments());
var finalModel = secondTrainer.Fit(trainData, initialPredictor: firstModel.Model);
Copy link
Member Author

@sfilipi sfilipi Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fit [](start = 47, length = 3)

@[email protected] if Fit() should not take a validation set, and an initial model, for this example/case here, would we still call Train()?

// Train the second predictor on the same data.
var secondTrainer = new AveragedPerceptronTrainer(env, new AveragedPerceptronTrainer.Arguments());

            var trainRoles = new RoleMappedData(trainData, label: "Label", feature: "Features");
            var finalModel = secondTrainer.Train(new TrainContext(trainRoles, initialPredictor: firstModel.Model)); #Resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Pigsty land, I'm not sure how this can be accommodated (or rather should it?)

In Dynamic land, yes, we still call Train, just not with the TrainContext and RoleMappedData


In reply to: 215809082 [](ancestors = 215809082)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Pigsty land, I'm not sure how this can be accommodated (or rather should it?)

Almost certainly, but unless I'm mistaken I don't think changes to IEstimator, or any of these core interfaces, will be necessary, or indeed even slightly helpful. Indeed, I might be missing something, but I'm a little confused about where we imagine the source of the problem is? We've posited the existence of some hypothetical ITransformer Train(IDataView trainData, ...) method, so why do we suppose a Transformer<TIn, TOut> Train<TIn, TOut>(DataView<TIn> trainData, ...) is impossible? Perhaps there's some subtlety I've missed.


In reply to: 215821268 [](ancestors = 215821268,215809082)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain whether that's in scope for this PR. Maybe it is, I just don't know.


In reply to: 215840658 [](ancestors = 215840658,215821268,215809082)

{
public const string LoadNameValue = "AveragedPerceptron";
internal const string UserNameValue = "Averaged Perceptron";
internal const string ShortName = "ap";
internal const string Summary = "Averaged Perceptron Binary Classifier.";

internal new readonly Arguments Args;
Copy link
Member Author

@sfilipi sfilipi Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal [](start = 8, length = 8)

this should truly be private, but our analyzer wants the private properties to be lowercased. This i should change or add a separate rule for 'private new'. Thoughts? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just private readonly Arguments _args ?


In reply to: 215814336 [](ancestors = 215814336)

var finalModel = secondTrainer.Train(trainData, firstModel.Model);
var secondTrainer = new AveragedPerceptronTrainer(env, new AveragedPerceptronTrainer.Arguments());

var trainRoles = new RoleMappedData(trainData, label: "Label", feature: "Features");
Copy link
Contributor

@Zruty0 Zruty0 Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoleMappedData [](start = 37, length = 14)

wait, wait, RoleMappedData should not survive :) #Pending

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I'm fine with keeping them internally for now, but Train call should take only IDataView for train data


In reply to: 215820969 [](ancestors = 215820969)

Copy link
Member Author

@sfilipi sfilipi Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the preferred way of passing the initialPredictor for online learners if neither Train or Fit should take them in as arguments?


In reply to: 215821958 [](ancestors = 215821958,215820969)

Copy link
Member Author

@sfilipi sfilipi Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zruty0 i added a second TrainContext that contains IDataView for the Training, Validation data, and another Train Method that takes this second TrainContext but that proliferates everywhere in an ugly way.

I think we should keep the RoleMappedData instead of this spawn, and once it goes away, TrainContext will get cleaned up and so will this example. Objections?


In reply to: 215848474 [](ancestors = 215848474,215821958,215820969)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's ok, let's create an issue for that though.


In reply to: 216079699 [](ancestors = 216079699,215848474,215821958,215820969)

@@ -25,10 +25,11 @@

namespace Microsoft.ML.Runtime.Learners
{
using Microsoft.ML.Core.Data;
Copy link
Contributor

@Zruty0 Zruty0 Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using [](start = 4, length = 5)

consolidate #Closed

@@ -25,10 +25,11 @@

namespace Microsoft.ML.Runtime.Learners
{
using Microsoft.ML.Core.Data;
using TPredictor = LinearRegressionPredictor;
Copy link
Contributor

@Zruty0 Zruty0 Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TPredictor [](start = 10, length = 10)

let's remove this #Closed

@Zruty0
Copy link
Contributor

Zruty0 commented Sep 7, 2018

using Float = System.Single;

Remove this please #Closed


Refers to: src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs:19 in 0c176aa. [](commit_id = 0c176aa, deletion_comment = False)

Copy link
Contributor

@Zruty0 Zruty0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

Copy link
Contributor

@Zruty0 Zruty0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sfilipi .

@@ -2,8 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Float = System.Single;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @Zruty0 meant remove it altogether, but that's all right, we can do a sweep for this later.

@TomFinley TomFinley merged commit df499aa into dotnet:master Sep 8, 2018
@sfilipi sfilipi deleted the apEstimator branch October 9, 2018 22:24
@ghost ghost locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Issues pertaining the friendly API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants