Skip to content

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

Merged
merged 6 commits into from
Aug 16, 2018

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Aug 9, 2018

Also, PartitionedFileLoader is now SubComponent-free.

This is the next round of SubComponent removal from our public API. I've removed all Scorer and Calibrator usages of SubComponent.

@Ivanidzo4ka - I still need to update this so CmdParser doesn't throw an exception. I'll do that when I'm back in the office. I wanted to send this out now to get eyes on it while I'm out.

@@ -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))]
Copy link
Contributor

@Zruty0 Zruty0 Aug 9, 2018

Choose a reason for hiding this comment

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

SignatureDataScorer [](start = 134, length = 19)

I wonder if the information contained in SignatureType is identical to the information contained in typeof(Scorer) ?
As in, aren't these the type parameters you want to invoke with? #Closed

Copy link
Member Author

@eerhardt eerhardt Aug 14, 2018

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Member Author

Choose a reason for hiding this comment

The 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:

/// <summary>
/// Used for dictionary lookup based on signature and name.
/// </summary>
internal struct Key : IEquatable<Key>
{
public readonly string Name;
public readonly Type Signature;

private static LoadableClassInfo FindClassCore(LoadableClassInfo.Key key)

return new SimpleComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform>(
(env, data, innerMapper, trainSchema) =>
{
if (info == null)
Copy link
Contributor

@Zruty0 Zruty0 Aug 9, 2018

Choose a reason for hiding this comment

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

if [](start = 20, length = 2)

why don't we put the 'if' outside the delegate and construct specialized delegates? #Closed

Copy link
Member Author

@eerhardt eerhardt Aug 14, 2018

Choose a reason for hiding this comment

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

Done. #Closed

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.

🕐

IPredictor predictor, IDataView input, string featureColName, string groupColName,
IEnumerable<KeyValuePair<RoleMappedSchema.ColumnRole, string>> customColumns, IHostEnvironment env, RoleMappedSchema trainSchema)
public static IDataScorerTransform GetScorer(
IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> scorer,
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Aug 10, 2018

Choose a reason for hiding this comment

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

IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> [](start = 12, length = 88)

can you define something like using TScorerFactory = IComponentFactory<IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform> and use it across this file?
see line 17 in MetaMulticlassTrainer.
#Closed

Copy link
Member Author

@eerhardt eerhardt Aug 14, 2018

Choose a reason for hiding this comment

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

Done. #Closed

@eerhardt
Copy link
Member Author

@Ivanidzo4ka and @Zruty0 I've responded to all feedback. Please take another look.

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:

/// (and an <see cref="IHostEnvironment"/>) that simply wraps a delegate which
/// creates the component.
/// </summary>
public class SimpleComponentFactory<TArg1, TArg2, TArg3, TComponent> : IComponentFactory<TArg1, TArg2, TArg3, TComponent>
Copy link
Contributor

Choose a reason for hiding this comment

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

SimpleComponentFactory [](start = 17, length = 22)

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.

Copy link
Member Author

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 SimpleComponentFactory classes being hidden in #681.

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.

:shipit:

@eerhardt eerhardt merged commit 307b38f into dotnet:master Aug 16, 2018
@eerhardt eerhardt deleted the SubComponentContinued branch November 7, 2018 14:56
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants