Skip to content

Add Code Gen piece for Recommendation task #4360

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
part1
  • Loading branch information
maryamariyan committed Oct 21, 2019
commit 2d6e19bc6bb9ba10a9a26b02585ba36d8179672a
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json;
https://devdiv.pkgs.visualstudio.com/_packaging/MachineLearning/nuget/v3/index.json;
</RestoreSources>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion pkg/Microsoft.ML.AutoML/Microsoft.ML.AutoML.nupkgproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>netstandard2.0</TargetFramework>
<PackageDescription>ML.NET AutoML: Optimizes an ML pipeline for your dataset, by automatically locating the best feature engineering, model, and hyperparameters</PackageDescription>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="1.3.1" />
<PackageReference Include="Microsoft.ML.LightGBM" Version="1.3.1" />
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it be LightGbm ?

Expand Down
11 changes: 7 additions & 4 deletions src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="$(MlDotNetPackageVersion)" />
<PackageReference Include="Microsoft.ML.LightGBM" Version="$(MlDotNetPackageVersion)" />
<PackageReference Include="Microsoft.ML.Mkl.Components" Version="$(MlDotNetPackageVersion)" />
<PackageReference Include="Microsoft.ML.Recommender" Version="$(MlDotNetPackageVersion)" />
<PackageReference Include="Microsoft.ML" Version="1.4.0-preview3-28218-2" />
<PackageReference Include="Microsoft.ML.LightGBM" Version="1.4.0-preview3-28218-2" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be LightGbm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: LightGbm in all uppercasing is also in nupkgproj files (pkg..AutoML and pkg\mlnet)

<PackageReference Include="Microsoft.ML.Mkl.Components" Version="1.4.0-preview3-28218-2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.Recommender\Microsoft.ML.Recommender.csproj" />
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't you using a PackageReference to Recommender here, same as the other 3?

</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ internal static ITrainerGenerator GetInstance(PipelineNode node)
return new SymbolicSgdLogisticRegressionBinary(node);
case TrainerName.Ova:
return new OneVersusAll(node);
case TrainerName.MatrixFactorization:
return new MatrixFactorization(node);
default:
throw new ArgumentException($"The trainer '{trainer}' is not handled currently.");
}
Expand Down
30 changes: 30 additions & 0 deletions src/Microsoft.ML.CodeGen/CodeGenerator/CSharp/TrainerGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,5 +556,35 @@ public override string[] GenerateUsings()
return _binaryTrainerUsings;
}
}

internal class MatrixFactorization : TrainerGeneratorBase
{
//ClassName of the trainer
internal override string MethodName => "MatrixFactorization";

internal override string OptionsName => "MatrixFactorizationTrainer.Options";

//The named parameters to the trainer.
internal override IDictionary<string, string> NamedParameters
{
get
{
return
new Dictionary<string, string>()
{
{"MatrixColumnIndexColumnName","matrixColumnIndexColumnName" },
{"MatrixRowIndexColumnName","matrixRowIndexColumnName" },
{"FeatureColumnName","featureColumnName" },
Copy link
Member

Choose a reason for hiding this comment

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

I don't see a FeatureColumnName on MatrixFactorization

{"LabelColumnName","labelColumnName" }
};
}
}

internal override string[] Usings => new string[] { "using Microsoft.ML.Trainers;\r\n" };

public MatrixFactorization(PipelineNode node) : base(node)
{
}
}
}
}
91 changes: 3 additions & 88 deletions src/Microsoft.ML.CodeGen/Microsoft.ML.CodeGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />
<!--<PackageReference Include="Microsoft.ML.AutoML" Version="0.16.0-preview3-28218-2" />-->
<PackageReference Include="Microsoft.ML" Version="1.4.0-preview3-28218-2" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need Microsoft.ML package in CodeGen.

Please remove comment BTW


<PackageReference Include="NLog" Version="4.5.11" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
Expand All @@ -15,98 +18,10 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.AutoML\Microsoft.ML.AutoML.csproj" />
</ItemGroup>

<ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you want these to be removed, do you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bringing back

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we remove tt file in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bringing back

<None Update="Templates\Console\Annotation.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Annotation.txt</LastGenOutput>
</None>
<None Update="Templates\Console\Annotation.txt">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Annotation.tt</DependentUpon>
</None>
<None Update="Templates\Console\ConsumeModel.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>ConsumeModel.cs</LastGenOutput>
</None>
<None Update="Templates\Console\ModelBuilder.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>ModelBuilder.cs</LastGenOutput>
</None>
<None Update="Templates\Console\ModelInputClass.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>ModelInputClass.cs</LastGenOutput>
</None>
<None Update="Templates\Console\ModelOutputClass.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>ModelOutputClass.cs</LastGenOutput>
</None>
<None Update="Templates\Console\ModelProject.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>ModelProject.cs</LastGenOutput>
</None>
<None Update="Templates\Console\PredictProgram.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>PredictProgram.cs</LastGenOutput>
</None>
<None Update="Templates\Console\PredictProject.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>PredictProject.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup>
<Compile Update="Templates\Console\ConsumeModel.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ConsumeModel.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\ModelBuilder.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelBuilder.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\ModelInputClass.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelInputClass.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\ModelOutputClass.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelOutputClass.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\ModelProject.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelProject.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\PredictProgram.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>PredictProgram.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Console\PredictProject.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>PredictProject.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Templates\Console\ModelInputClass.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelInputClass.tt</DependentUpon>
</Compile>
<Compile Update="Templates\Templates\Console\ModelOutputClass.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelOutputClass.tt</DependentUpon>
</Compile>
</ItemGroup>

<Import Project="..\mlnet\mlnet.Build.props" />

Expand Down
19 changes: 19 additions & 0 deletions test/mlnet.Tests/TrainerGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ public void SgdCalibratedBinaryBasicTest()

}

[TestMethod]
public void MatrixFactorizationTest()
{
var context = new MLContext();
var elementProperties = new Dictionary<string, object>()
{
{"MatrixColumnIndexColumnName","userId" },
{"MatrixRowIndexColumnName","movieId" },
{"LabelColumnName","rating" },
};
PipelineNode node = new PipelineNode("MatrixFactorization", PipelineNodeType.Trainer, default(string[]), default(string), elementProperties);
Pipeline pipeline = new Pipeline(new PipelineNode[] { node });
CodeGenerator codeGenerator = new CodeGenerator(pipeline, null, null);
var actual = codeGenerator.GenerateTrainerAndUsings();
string expectedTrainerString = "MatrixFactorization(matrixColumnIndexColumnName:\"userId\",matrixRowIndexColumnName:\"movieId\",labelColumnName:\"rating\",featureColumnName:\"Features\")";
Assert.AreEqual(expectedTrainerString, actual.Item1);
Assert.IsNull(actual.Item2);
}

[TestMethod]
public void SgdCalibratedBinaryAdvancedParameterTest()
{
Expand Down