-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Direct API: Auto-normalization #433
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
Comments
Incidentally, followup on #371. |
In the process of doing this, I notice that machinelearning/src/Microsoft.ML.Data/Commands/TrainCommand.cs Lines 538 to 546 in 2501049
(This itself is something that needs to change, though perhaps not as part of this PR -- this code is just so ugly and awful.) Also more broadly normalization is a very practically important part of ML -- it really ought to be in the more fundamental DLL. As part of this work I will have to move it. |
Thanks @TomFinley for looking into this. While writing a test for new API, I also faced this issue. The argument to linear learners contains public abstract class LearnerInputBase
{
[Argument(ArgumentType.Required, ShortName = "data", HelpText = "The data to be used for training", SortOrder = 1, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
public IDataView TrainingData;
[Argument(ArgumentType.AtMostOnce, HelpText = "Column to use for features", ShortName = "feat", SortOrder = 2, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
public string FeatureColumn = DefaultColumnNames.Features;
[Argument(ArgumentType.AtMostOnce, HelpText = "Normalize option for the feature column", ShortName = "norm", SortOrder = 5, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
public NormalizeOption NormalizeFeatures = NormalizeOption.Auto;
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Whether learner should cache input training data", ShortName = "cache", SortOrder = 6, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
public CachingOptions Caching = CachingOptions.Auto;
} |
One complication to consider is that some trainers expect specific kind of normalization. There should be a way to specialize from "NeedNormalization" to a "NeedMeanVarNormalization" |
Hi @zeahmed yup, I was sort of planning on tackling caching next... or possibly making Hi @glebuk while probably worth looking into, I'd rather not design fundamentally new features as part of this, for three reasons: First reason, I'm just trying to more or less recreate the convenience we already have. I'd just as soon not do anything fundamentally new. That is, I consider this out of scope for now. Second, the problem of how algorithms can "control" their input to undergo certain desirable preprocessing is not a problem limited to this alone. If we insist on solving it, I might prefer something broader than this: something like an Third, as you might tell I am very wary of doing so, for the reason I mentioned at the start of the issue about "implicit" behavior: every implicit convenience like this we write fundamentally renders the API less comprehensible, versus an explicit call. When it comes to tools and GUIs and whatnot providing conveniences like this, I agree the more the merrier. Something like an API, we should shift our thinking from "why not" to "why." Indeed our prior (non-entry-points based) API (not written by me) took the position, that since it was an API, a user was responsible for whether they wanted their own normalization or not. An API is not a GUI, and we shouldn't pretend it is. |
Closing as fixed #446 |
One of the details of training that happen after a loader/transform pipeline is created, but before the cache. We've typically automatically done this for users. While usage in the API is very distinct in that people tend to like implicit behavior in tools but dislike implicit behavior in APIs, at least offering a convenience for normalization is appropriate.
Existing Method
Some familiar with this codebase are aware of this existing method, in the
TrainUtils
utility class, that serves a similar function.machinelearning/src/Microsoft.ML.Data/Commands/TrainCommand.cs
Line 492 in 2501049
The goal of that method is not to provide a convenient API, so much as to factor out code common to the various commands that train models (e.g., train, traintest, cross-validation, some transforms like train-and-score). The same is true of many methods in that
TrainUtils
class. This as we see in the first few lines:machinelearning/src/Microsoft.ML.Data/Commands/TrainCommand.cs
Lines 499 to 506 in 2501049
While beneficial in providing consistent behavior across all of these things from a command-line perspective, the condition where it just exits would be inappropriate to have in an ML.NET API -- you might imagine someone designing a method with a parameter
bool doNothing
where the first thing is, if it's true, the method returns without doing anything. Again, appropriate from the point of view of factoring out common code, but not appropriate for an API. Also the method of communicating important information to the user is via the console, which again is not the most helpful option for an API.Proposed API Helpers
Nonetheless, this function has several things that are helpful to do: it detects if a trainer wants normalization, if data is normalized, and if appropriate and necessary applies normalization.
This would probably take the form of a static method on the
NormalizerTransform
class, perhaps following this signature:We could also have two additional methods to provide key information.
The text was updated successfully, but these errors were encountered: