-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Smoke test for F# #600
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
Smoke test for F# #600
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/Microsoft.ML.FSharp.Tests/Microsoft.ML.FSharp.Tests.fsproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.0</TargetFrameworks> | ||
<TargetFrameworks Condition="'$(OS)' != 'Unix'">$(TargetFrameworks); net461</TargetFrameworks> | ||
<NoWarn>2003;$(NoWarn)</NoWarn> | ||
<PublicSign>false</PublicSign> | ||
<SourceLink></SourceLink> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="SmokeTests.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- Future updates to this test will check use with F# type providers, so --> | ||
<!-- leaving this here for now. --> | ||
<!-- <PackageReference Include="FSharp.Data" Version="3.0.0-beta4" /> --> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- More projects are referenced than are currently tested. Future updates to --> | ||
<!-- these tests will test more of the surface area from F#, so leaving these references --> | ||
<!-- here for now. --> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Api\Microsoft.ML.Api.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Core\Microsoft.ML.Core.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.CpuMath\Microsoft.ML.CpuMath.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Data\Microsoft.ML.Data.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Ensemble\Microsoft.ML.Ensemble.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.FastTree\Microsoft.ML.FastTree.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.KMeansClustering\Microsoft.ML.KMeansClustering.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.LightGBM\Microsoft.ML.LightGBM.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Onnx\Microsoft.ML.Onnx.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Parquet\Microsoft.ML.Parquet.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.PCA\Microsoft.ML.PCA.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.PipelineInference\Microsoft.ML.PipelineInference.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.ResultProcessor\Microsoft.ML.ResultProcessor.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.StandardLearners\Microsoft.ML.StandardLearners.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Sweeper\Microsoft.ML.Sweeper.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML.Transforms\Microsoft.ML.Transforms.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.ML\Microsoft.ML.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<NativeAssemblyReference Include="FastTreeNative" /> | ||
<NativeAssemblyReference Include="CpuMathNative" /> | ||
<NativeAssemblyReference Include="FactorizationMachineNative" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Microsoft.ML.FSharp.Tests | ||
|
||
#if NETCOREAPP2_0 | ||
module Program = | ||
|
||
[<EntryPoint>] | ||
let main _ = 0 | ||
#endif | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
|
||
//================================================================================================= | ||
// This test can be run either as a compiled test with .NET Core (on any platform) or | ||
// manually in script form (to help debug it and also check that F# scripting works with ML.NET). | ||
// Running as a script requires using F# Interactive on Windows, and the explicit references below. | ||
// The references would normally be created by a package loader for the scripting | ||
// environment, e.g. see https://github.com/isaacabraham/ml-test-experiment/, but | ||
// here we list them explicitly to avoid the dependency on a package loader, | ||
// | ||
// You should build Microsoft.ML.FSharp.Tests in Debug mode for framework net461 | ||
// before running this as a script with F# Interactive by editing the project | ||
// file to have: | ||
// <TargetFrameworks>netcoreapp2.0; net461</TargetFrameworks> | ||
|
||
#if INTERACTIVE | ||
#r "netstandard" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.Core.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Google.Protobuf.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Newtonsoft.Json.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/System.CodeDom.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/System.Threading.Tasks.Dataflow.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.CpuMath.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.Data.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.Transforms.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.ResultProcessor.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.PCA.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.KMeansClustering.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.FastTree.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.Api.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.Sweeper.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.StandardLearners.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/Microsoft.ML.PipelineInference.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/xunit.core.dll" | ||
#r @"../../bin/AnyCPU.Debug/Microsoft.ML.FSharp.Tests/net461/xunit.assert.dll" | ||
#r "System" | ||
#r "System.ComponentModel.Composition" | ||
#r "System.Core" | ||
#r "System.Xml.Linq" | ||
|
||
// Later tests will add data import using F# type providers: | ||
//#r @"../../packages/fsharp.data/3.0.0-beta4/lib/netstandard2.0/FSharp.Data.dll" // this must be referenced from its package location | ||
|
||
#endif | ||
|
||
//================================================================================ | ||
// The tests proper start here | ||
|
||
#if !INTERACTIVE | ||
namespace Microsoft.ML.FSharp.Tests | ||
#endif | ||
|
||
open System | ||
open Microsoft.ML | ||
open Microsoft.ML.Data | ||
open Microsoft.ML.Transforms | ||
open Microsoft.ML.Trainers | ||
open Microsoft.ML.Runtime.Api | ||
open Xunit | ||
|
||
module SmokeTest1 = | ||
|
||
type SentimentData() = | ||
[<Column(ordinal = "0"); DefaultValue>] | ||
val mutable SentimentText : string | ||
[<Column(ordinal = "1", name = "Label"); DefaultValue>] | ||
val mutable Sentiment : float32 | ||
|
||
type SentimentPrediction() = | ||
[<ColumnName "PredictedLabel"; DefaultValue>] | ||
val mutable Sentiment : bool | ||
|
||
[<Fact>] | ||
let ``FSharp-Sentiment-Smoke-Test`` () = | ||
|
||
// See https://github.com/dotnet/machinelearning/issues/401: forces the loading of ML.NET component assemblies | ||
|
||
let _load = | ||
[ typeof<Microsoft.ML.Runtime.Transforms.TextAnalytics>; | ||
typeof<Microsoft.ML.Runtime.FastTree.FastTree> ] | ||
|
||
let testDataPath = __SOURCE_DIRECTORY__ + @"/../data/wikipedia-detox-250-line-data.tsv" | ||
|
||
let pipeline = LearningPipeline() | ||
|
||
pipeline.Add( | ||
TextLoader(testDataPath).CreateFrom<SentimentData>( | ||
Arguments = | ||
TextLoaderArguments( | ||
HasHeader = true, | ||
Column = [| TextLoaderColumn(Name = "Label", Source = [| TextLoaderRange(0) |], Type = Nullable (Data.DataKind.Num)) | ||
TextLoaderColumn(Name = "SentimentText", Source = [| TextLoaderRange(1) |], Type = Nullable (Data.DataKind.Text)) |] | ||
))) | ||
|
||
pipeline.Add( | ||
TextFeaturizer( | ||
"Features", [| "SentimentText" |], | ||
KeepDiacritics = false, | ||
KeepPunctuations = false, | ||
TextCase = TextNormalizerTransformCaseNormalizationMode.Lower, | ||
OutputTokens = true, | ||
VectorNormalizer = TextTransformTextNormKind.L2 | ||
)) | ||
|
||
pipeline.Add( | ||
FastTreeBinaryClassifier( | ||
NumLeaves = 5, | ||
NumTrees = 5, | ||
MinDocumentsInLeafs = 2 | ||
)) | ||
|
||
let model = pipeline.Train<SentimentData, SentimentPrediction>() | ||
|
||
let predictions = | ||
[ SentimentData(SentimentText = "This is a gross exaggeration. Nobody is setting a kangaroo court. There was a simple addition.") | ||
SentimentData(SentimentText = "Sort of ok") | ||
SentimentData(SentimentText = "Joe versus the Volcano Coffee Company is a great film.") ] | ||
|> model.Predict | ||
|
||
let predictionResults = [ for p in predictions -> p.Sentiment ] | ||
Assert.Equal<bool list>(predictionResults, [ false; true; true ]) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's this for? Is this necessary?
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.
I just got a build error when building from the IDE using VS 15.7 because for .NET 4.6.1 compilation "full" PDB symbols (not portable) were being produced), I can reproduce if I build with
msbuild
notdotnet
. Full PDB are not compatible with sourcelink. It doesn't go away even if you set DebugType to "portable".I think it is an F# build targets bug fixed in 15.8. Anyway for now seemed sensible to turn of SourceLink for the test project