-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Adding CodeGen piece for MatrixFactorization trainer #4391
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
08caa90
e5218a1
7af05e2
d586c62
74e9346
70e7ab3
63d6c47
7eac6cc
8294f2a
f3a695c
8fe4764
78fc9c9
0281c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ internal abstract class TrainerGeneratorBase : ITrainerGenerator | |
private Dictionary<string, object> _arguments; | ||
private bool _hasAdvancedSettings; | ||
private string _seperator; | ||
protected virtual bool IncludeFeatureColumnName => true; | ||
|
||
//abstract properties | ||
internal abstract string OptionsName { get; } | ||
|
@@ -47,7 +48,10 @@ private void Initialize(PipelineNode node) | |
{ | ||
node.Properties.Add("LabelColumnName", "Label"); | ||
} | ||
node.Properties.Add("FeatureColumnName", "Features"); | ||
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. FeatureColumnName gets added for all existing trainer generators. I added IncludeFeatureColumnName which is false for MatrixFactorization trainer generator only. 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. TODO:
|
||
if (IncludeFeatureColumnName) | ||
{ | ||
node.Properties.Add("FeatureColumnName", "Features"); | ||
} | ||
|
||
foreach (var kv in node.Properties) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,5 +577,35 @@ internal override IDictionary<string, string> NamedParameters | |
} | ||
} | ||
} | ||
|
||
internal class MatrixFactorization : TrainerGeneratorBase | ||
{ | ||
//ClassName of the trainer | ||
internal override string MethodName => "MatrixFactorization"; | ||
|
||
internal override string OptionsName => "MatrixFactorizationTrainer.Options"; | ||
protected override bool IncludeFeatureColumnName => false; | ||
|
||
//The named parameters to the trainer. | ||
internal override IDictionary<string, string> NamedParameters | ||
{ | ||
get | ||
{ | ||
return | ||
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. This is a bit of an anti-pattern: to return a new object every time a property is invoked. I see this is already being used in existing code, so you don't need to fix it in this PR. But in general, calling a property is supposed to be fast. https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/property
|
||
new Dictionary<string, string>() | ||
maryamariyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
{ "MatrixColumnIndexColumnName","matrixColumnIndexColumnName" }, | ||
{ "MatrixRowIndexColumnName","matrixRowIndexColumnName" }, | ||
{ "LabelColumnName","labelColumnName" } | ||
}; | ||
} | ||
} | ||
|
||
internal override string[] Usings => new string[] { "using Microsoft.ML.Trainers;\r\n" }; | ||
|
||
public MatrixFactorization(PipelineNode node) : base(node) | ||
{ | ||
} | ||
} | ||
} | ||
} |
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.
@JakeRadMSFT @LittleLittleCloud - what do you think of this approach? It at least removes hard-coded versions from the CodeGenerator assembly, and allows the "app" (CLI and Model Builder) to pick the version they require.