Skip to content

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

Merged
merged 18 commits into from
Feb 1, 2019
Merged

Conversation

najeeb-kazmi
Copy link
Member

@najeeb-kazmi najeeb-kazmi commented Jan 11, 2019

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.

@najeeb-kazmi najeeb-kazmi changed the title Make array argument names plural [WIP] Make array argument names plural Jan 11, 2019
@abgoswam
Copy link
Member

abgoswam commented Jan 11, 2019

For the 3 places you mention, where we used string Terms the convention proposed in the PR seems confusing to me.

In particular public string TermsList looks odd. Isn't it ?

@@ -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;
Copy link
Member

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.

Copy link
Member Author

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 inInputBuilder`.

@@ -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;
Copy link
Member

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.

Copy link
Member Author

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?

@najeeb-kazmi najeeb-kazmi changed the title [WIP] Make array argument names plural Make array argument names plural Jan 16, 2019
[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;
Copy link
Member Author

@najeeb-kazmi najeeb-kazmi Jan 16, 2019

Choose a reason for hiding this comment

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

public [](start = 12, length = 6)

To be made internal in #2133, after #2059 gets merged

[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;
Copy link
Member Author

Choose a reason for hiding this comment

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

public [](start = 12, length = 6)

To be made internal in #2133, after #2059 gets merged

[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;
Copy link
Member Author

Choose a reason for hiding this comment

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

public [](start = 8, length = 6)

To be made internal in #2133, after #2059 gets merged

[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;
Copy link
Member Author

Choose a reason for hiding this comment

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

public [](start = 12, length = 6)

To be made internal in #2133, after #2059 gets merged

Copy link
Member

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)

Copy link
Member Author

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())
Copy link
Member

@singlis singlis Jan 18, 2019

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

Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

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)
Copy link
Member

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

Copy link
Member Author

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()))
Copy link
Member

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.

See here: https://stackoverflow.com/questions/13988643/case-insensitive-dictionary-with-string-key-type-in-c-sharp

@@ -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);
Copy link
Member

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.

@glebuk
Copy link
Contributor

glebuk commented Jan 18, 2019

                // Drop columns indexed by args.Index

indices? #Closed


Refers to: src/Microsoft.ML.Data/Dirty/ChooseColumnsByIndexTransform.cs:86 in df10cb7. [](commit_id = df10cb7, deletion_comment = False)

@glebuk
Copy link
Contributor

glebuk commented Jan 18, 2019

    [TlcModule.EntryPoint(Name = "Transforms.ScoreColumnSelector", Desc = "Selects only the last score columns and the extra columns specified in the arguments.", UserName = "Choose Columns By Index")]

indices? #Closed


Refers to: src/Microsoft.ML.Data/EntryPoints/ScoreColumnSelector.cs:22 in df10cb7. [](commit_id = df10cb7, deletion_comment = False)

Copy link
Contributor

@glebuk glebuk left a 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;
Copy link
Contributor

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.

@TomFinley
Copy link
Contributor

Hi @najeeb-kazmi or others, is this being worked on?

@najeeb-kazmi
Copy link
Member Author

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.

@codecov
Copy link

codecov bot commented Jan 25, 2019

Codecov Report

Merging #2124 into master will increase coverage by <.01%.
The diff coverage is 70.46%.

@@            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
Flag Coverage Δ
#Debug 71.17% <70.46%> (ø) ⬆️
#production 67.56% <66.11%> (ø) ⬆️
#test 85.18% <92.85%> (ø) ⬆️

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.

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.

Copy link
Contributor

@glebuk glebuk left a comment

Choose a reason for hiding this comment

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

:shipit:

@artidoro
Copy link
Contributor

            string[] term = null,

Does it make sense to update it here as well?


Refers to: src/Microsoft.ML.Data/Transforms/ValueToKeyMappingTransformer.cs:187 in ac7ee5a. [](commit_id = ac7ee5a, deletion_comment = False)

@artidoro
Copy link
Contributor

Hey @najeeb-kazmi are you still looking into this PR? Would be great to have this in :)

@najeeb-kazmi
Copy link
Member Author

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.

@artidoro
Copy link
Contributor

artidoro commented Feb 1, 2019

Would suggest to remove bin folder, sync with master, and rebuild from command line.

@najeeb-kazmi
Copy link
Member Author

Thanks @artidoro for your help in getting the conflicts merged!

@najeeb-kazmi najeeb-kazmi merged commit 28ae548 into dotnet:master Feb 1, 2019
@najeeb-kazmi najeeb-kazmi deleted the 2040 branch January 30, 2020 01:17
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 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.

7 participants