-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make array argument names plural #2124
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
Conversation
For the 3 places you mention, where we used In particular |
src/Microsoft.ML.Data/Transforms/ValueToKeyMappingTransformer.cs
Outdated
Show resolved
Hide resolved
@@ -95,7 +95,7 @@ public sealed class Output | |||
{ | |||
[TlcModule.Output(Desc = "The final model including the trained predictor model and the model from the transforms, " + | |||
"provided as the Input.TransformModel.", SortOrder = 1)] | |||
public PredictorModel[] PredictorModel; | |||
public PredictorModel[] PredictorModels; |
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.
PredictorModels [](start = 36, length = 15)
i think this might have side-effects in the entry points; but that is probably ok.
@yaeldekel might have an opinion too.
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.
You're right, it did break some entry point tests. I realize this one is not an ArgumentAttribute
to begin with, so I'm reverting it in my next change (I haven't pushed yet).
Many other entry point tests also broke because of renaming Column
to Columns
and setting Name = "Column"
. Basically, the graph runner ctor checks for validity of node names, but it only checks against ArgumentAttribute.Name
and the ArgumentAttribute.Aliases
, and since Name
was set to "Column" and Aliases were the ShortName
list, all of those checks failed.
It wouldn't have been correct to change ShortName
to "col,Columnsas that is visible on the command line, and "Columns" doesn't make sense on the command line. I ended up modifying the check in
InputBuilder`.
@@ -75,21 +75,21 @@ public static EvaluateInputBase GetEvaluatorArgs(TrainerKinds kind, out string e | |||
public sealed class ArrayIPredictorModelInput | |||
{ | |||
[Argument(ArgumentType.Required, HelpText = "The models", SortOrder = 1)] | |||
public PredictorModel[] Model; | |||
public PredictorModel[] Models; |
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.
Models [](start = 36, length = 6)
Same note on tis file, about entry points.
Also, the EntryPoint project is not directly user facing.. idk if we still want to do it for consistency.
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.
This one does't break the tests, but I do agree we might want to rethink touching entry point arguments right now. The effects might propagate to NimbusML for instance.
@TomFinley what do you think?
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Terms; | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", Name = "Terms", Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Term; |
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.
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", SortOrder = 105, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Terms; | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", Name = "Terms", SortOrder = 105, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Term; |
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.
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", SortOrder = 1, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Terms; | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of terms", Name = "Terms", SortOrder = 1, Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Term; |
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.
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of stopwords", Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Stopwords; | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Comma separated list of stopwords", Name = "Stopwords", Visibility = ArgumentAttribute.VisibilityType.CmdLineOnly)] | ||
public string Stopword; |
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.
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.
Hi Najeeb -- Name is an override and not an alias right?
In reply to: 248488901 [](ancestors = 248488901)
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.
Name is an alias (with my changes to the cmd line runner). I'm adding the Name attribute so that behavior of existing command lines doesn't get affected with renaming of the field name.
@@ -477,6 +477,11 @@ private static ArgumentInfo GetArgumentInfo(Type type, object defaults) | |||
throw Contracts.Except("Duplicate default argument '{0}' vs '{1}'", def.LongName, field.Name); | |||
|
|||
string name = ArgCase(field.Name); | |||
|
|||
string attrName = null; | |||
if (attr.Name != null && attr.Name.ToLowerInvariant() != name.ToLowerInvariant()) |
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.
Do you care about empty strings too? If so, I would use String.IsEmptyOrNull.
Also you can do a case insensitive compare with String.Equals(a,b,StringComparison.OrginalIgnoreCase) #Closed
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.
(!string.IsNullorEmpty(attr.Name) &&
attr.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
In reply to: 248905796 [](ancestors = 248905796)
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.
Done
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.
See the impleemntation of ArgumentAttribute.Name
; it already guards against this. If you tried to set something to be empty, or even all whitespace, the property value would be null.
@@ -495,6 +500,11 @@ private static ArgumentInfo GetArgumentInfo(Type type, object defaults) | |||
|
|||
if (map.ContainsKey(name.ToLowerInvariant())) | |||
throw Contracts.Except("Duplicate name '{0}' in argument type '{1}'", name, type.Name); | |||
if (attrName != null) |
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.
attrName [](start = 24, length = 8)
Same comment here about empty string
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.
Not applicable here, since this is attrName, not attr.Name. It's going to be either null or non-empty.
@@ -495,6 +500,11 @@ private static ArgumentInfo GetArgumentInfo(Type type, object defaults) | |||
|
|||
if (map.ContainsKey(name.ToLowerInvariant())) | |||
throw Contracts.Except("Duplicate name '{0}' in argument type '{1}'", name, type.Name); | |||
if (attrName != null) | |||
{ | |||
if (map.ContainsKey(attrName.ToLowerInvariant())) |
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.
You may also construct the map with a case insensitive string compare, that way you dont have to do a lower variant.
@@ -508,6 +518,8 @@ private static ArgumentInfo GetArgumentInfo(Type type, object defaults) | |||
|
|||
// Note that we put the default arg in the map to ensure that no other args use the same name. | |||
map.Add(name.ToLowerInvariant(), arg); | |||
if (attrName != null) | |||
map.Add(attrName.ToLowerInvariant(), arg); |
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.
ToLowerInvariant [](start = 41, length = 16)
If you can do a case insensitive comparer for the map the toLowerInvariant is not needed. However if you want to convert to lower invariant for other reasons, I would suggest doing the conversion at the top of the function and using that through the rest of the code. That way you do the conversion once.
src/Microsoft.ML.StandardLearners/Standard/Online/AveragedLinear.cs
Outdated
Show resolved
Hide resolved
indices? #Closed Refers to: src/Microsoft.ML.Data/EntryPoints/ScoreColumnSelector.cs:22 in df10cb7. [](commit_id = df10cb7, deletion_comment = False) |
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.
🕐
|
||
string attrName = null; | ||
if (attr.Name != null && attr.Name.ToLowerInvariant() != name.ToLowerInvariant()) | ||
attrName = attr.Name; |
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.
My expectation is that the logic should be the same as for entry-points... if Name
is set, then we would not use the field name from the user's perspective at all.
Hi @najeeb-kazmi or others, is this being worked on? |
@TomFinley Yes, I have modified to CmdParser to override field name with with attribute name if it is present. The comamnd line tests that were failing are passing now. Currently, I'm looking into the EntryPoints tests that fail when I override the field name with the attribute name. |
…with attribute name if attribute name is present
Codecov Report
@@ Coverage Diff @@
## master #2124 +/- ##
==========================================
+ Coverage 71.17% 71.17% +<.01%
==========================================
Files 780 780
Lines 140404 140404
Branches 16042 16053 +11
==========================================
+ Hits 99931 99935 +4
+ Misses 36023 36021 -2
+ Partials 4450 4448 -2
|
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.
Thank you for doing this @najeeb-kazmi . Now in both cases both command line and entry-points have the same desired behavior that the name serves as an override to the field name. I see @glebuk is still blocking, perhaps he can take another look.
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.
Hey @najeeb-kazmi are you still looking into this PR? Would be great to have this in :) |
@artidoro yes - currently it's building on my laptop but failing in the CI. Can't figure out why. |
Would suggest to remove bin folder, sync with master, and rebuild from command line. |
Thanks @artidoro for your help in getting the conflicts merged! |
Fixes #2040
Makes array argument names plural where they were singular.
Fixes
CmdParser
to check for Attribute name in addition to field Name.Fixes Entry Points
InputBuilder
to check for both Attribute and Field names.