-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Move Scorers and Calibrators to use IComponentFactory. #671
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
Changes from all commits
c1bb9f4
92f5b7a
446c72c
c0f1c3b
f32af76
3688862
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,8 +28,8 @@ public sealed class Arguments : DataCommand.ArgumentsBase | |||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Trainer to use", ShortName = "tr")] | ||||||||||||||||||
| public SubComponent<ITrainer, SignatureTrainer> Trainer = new SubComponent<ITrainer, SignatureTrainer>("AveragedPerceptron"); | ||||||||||||||||||
|
|
||||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Scorer to use", NullName = "<Auto>", SortOrder = 101)] | ||||||||||||||||||
| public SubComponent<IDataScorerTransform, SignatureDataScorer> Scorer; | ||||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Scorer to use", NullName = "<Auto>", SortOrder = 101, SignatureType = typeof(SignatureDataScorer))] | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder if the information contained in SignatureType is identical to the information contained in typeof(Scorer) ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter information definitely overlaps, but this isn't duplicate information. For example, if there are two signature delegates: public delegate void SignatureSweeper();
public delegate void SignatureTrainer();We can't discern which one we are trying to load from the component catalog solely on signature (both these signature delegates don't take any more parameters other than the Environment). #Closed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see. So the signature is needed for subselecting a list. In reply to: 210097300 [](ancestors = 210097300)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signature is needed in order to find the component in the ComponentCatalog. We can have multiple components with the same name, but are different based on their "signature type". So the components are keyed off both a name and a signature type:
|
||||||||||||||||||
| public IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> Scorer; | ||||||||||||||||||
|
|
||||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Evaluator to use", ShortName = "eval", NullName = "<Auto>", SortOrder = 102)] | ||||||||||||||||||
| public SubComponent<IMamlEvaluator, SignatureMamlEvaluator> Evaluator; | ||||||||||||||||||
|
|
@@ -76,8 +76,8 @@ public sealed class Arguments : DataCommand.ArgumentsBase | |||||||||||||||||
| [Argument(ArgumentType.AtMostOnce, IsInputFileName = true, HelpText = "The validation data file", ShortName = "valid")] | ||||||||||||||||||
| public string ValidationFile; | ||||||||||||||||||
|
|
||||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Output calibrator", ShortName = "cali", NullName = "<None>")] | ||||||||||||||||||
| public SubComponent<ICalibratorTrainer, SignatureCalibrator> Calibrator = new SubComponent<ICalibratorTrainer, SignatureCalibrator>("PlattCalibration"); | ||||||||||||||||||
| [Argument(ArgumentType.Multiple, HelpText = "Output calibrator", ShortName = "cali", NullName = "<None>", SignatureType = typeof(SignatureCalibrator))] | ||||||||||||||||||
| public IComponentFactory<ICalibratorTrainer> Calibrator = new PlattCalibratorTrainerFactory(); | ||||||||||||||||||
|
|
||||||||||||||||||
| [Argument(ArgumentType.LastOccurenceWins, HelpText = "Number of instances to train the calibrator", ShortName = "numcali")] | ||||||||||||||||||
| public int MaxCalibrationExamples = 1000000000; | ||||||||||||||||||
|
|
@@ -383,9 +383,9 @@ public FoldResult(Dictionary<string, IDataView> metrics, ISchema scoreSchema, Ro | |||||||||||||||||
| private readonly string _splitColumn; | ||||||||||||||||||
| private readonly int _numFolds; | ||||||||||||||||||
| private readonly SubComponent<ITrainer, SignatureTrainer> _trainer; | ||||||||||||||||||
| private readonly SubComponent<IDataScorerTransform, SignatureDataScorer> _scorer; | ||||||||||||||||||
| private readonly IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> _scorer; | ||||||||||||||||||
| private readonly SubComponent<IMamlEvaluator, SignatureMamlEvaluator> _evaluator; | ||||||||||||||||||
| private readonly SubComponent<ICalibratorTrainer, SignatureCalibrator> _calibrator; | ||||||||||||||||||
| private readonly IComponentFactory<ICalibratorTrainer> _calibrator; | ||||||||||||||||||
| private readonly int _maxCalibrationExamples; | ||||||||||||||||||
| private readonly bool _useThreads; | ||||||||||||||||||
| private readonly bool? _cacheData; | ||||||||||||||||||
|
|
@@ -423,7 +423,7 @@ public FoldHelper( | |||||||||||||||||
| Arguments args, | ||||||||||||||||||
| Func<IHostEnvironment, IChannel, IDataView, ITrainer, RoleMappedData> createExamples, | ||||||||||||||||||
| Func<IHostEnvironment, IChannel, IDataView, RoleMappedData, IDataView, RoleMappedData> applyTransformsToTestData, | ||||||||||||||||||
| SubComponent<IDataScorerTransform, SignatureDataScorer> scorer, | ||||||||||||||||||
| IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> scorer, | ||||||||||||||||||
| SubComponent<IMamlEvaluator, SignatureMamlEvaluator> evaluator, | ||||||||||||||||||
| Func<IDataView> getValidationDataView = null, | ||||||||||||||||||
| Func<IHostEnvironment, IChannel, IDataView, RoleMappedData, IDataView, RoleMappedData> applyTransformsToValidationData = null, | ||||||||||||||||||
|
|
@@ -559,11 +559,12 @@ private FoldResult RunFold(int fold) | |||||||||||||||||
|
|
||||||||||||||||||
| // Score. | ||||||||||||||||||
| ch.Trace("Scoring and evaluating"); | ||||||||||||||||||
| var bindable = ScoreUtils.GetSchemaBindableMapper(host, predictor, _scorer); | ||||||||||||||||||
| ch.Assert(_scorer == null || _scorer is ICommandLineComponentFactory, "CrossValidationCommand should only be used from the command line."); | ||||||||||||||||||
| var bindable = ScoreUtils.GetSchemaBindableMapper(host, predictor, scorerFactorySettings: _scorer as ICommandLineComponentFactory); | ||||||||||||||||||
| ch.AssertValue(bindable); | ||||||||||||||||||
| var mapper = bindable.Bind(host, testData.Schema); | ||||||||||||||||||
| var scorerComp = _scorer.IsGood() ? _scorer : ScoreUtils.GetScorerComponent(mapper); | ||||||||||||||||||
| IDataScorerTransform scorePipe = scorerComp.CreateInstance(host, testData.Data, mapper, trainData.Schema); | ||||||||||||||||||
| var scorerComp = _scorer ?? ScoreUtils.GetScorerComponent(mapper); | ||||||||||||||||||
| IDataScorerTransform scorePipe = scorerComp.CreateComponent(host, testData.Data, mapper, trainData.Schema); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Save per-fold model. | ||||||||||||||||||
| string modelFileName = ConstructPerFoldName(_outputModelFile, fold); | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eerhardt. As we discussed in #681 perhaps we can hide these implementations of the interface, but we'll do that after we merge this I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will take care of all the
SimpleComponentFactoryclasses being hidden in #681.