-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Smoke test for F# #600
Smoke test for F# #600
Changes from 1 commit
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 | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||||
<Project Sdk="Microsoft.NET.Sdk"> | ||||||||
|
||||||||
<PropertyGroup> | ||||||||
<TargetFrameworks>netcoreapp2.0</TargetFrameworks> | ||||||||
<NoWarn>2003;$(NoWarn)</NoWarn> | ||||||||
<TargetFrameworks Condition="'$(OS)' != 'Unix'">$(TargetFrameworks); net461</TargetFrameworks> | ||||||||
<PublicSign>false</PublicSign> | ||||||||
</PropertyGroup> | ||||||||
|
||||||||
<ItemGroup> | ||||||||
<Compile Include="SmokeTests.fs" /> | ||||||||
</ItemGroup> | ||||||||
|
||||||||
<ItemGroup> | ||||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" /> | ||||||||
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. These 3 PackageReferences are not needed, since all projects under the machinelearning/test/Directory.Build.props Lines 24 to 26 in dcc8ae8
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. ok, thanks! |
||||||||
<PackageReference Include="xunit" Version="2.3.1" /> | ||||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||||||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||||||||
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 line can be removed all together, since it is not needed. 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. okey dokey |
||||||||
<!-- 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// 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 | ||
|
||
let _load = | ||
// See https://github.com/dotnet/machinelearning/issues/401: forces the loading of ML.NET assemblies | ||
[ typeof<Microsoft.ML.Runtime.Transforms.TextAnalytics>; | ||
typeof<Microsoft.ML.Runtime.FastTree.FastTree> ] | ||
|
||
#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`` () = | ||
|
||
let testDataPath = __SOURCE_DIRECTORY__ + @"/../data/wikipedia-detox-250-line-data.tsv" | ||
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. Does 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. yes it does |
||
|
||
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 ]) | ||
|
||
#if NETCOREAPP2_0 | ||
module Program = | ||
|
||
[<EntryPoint>] | ||
let main _ = 0 | ||
#endif | ||
|
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.
(nit) I'd keep this line next to the other
TargetFrameworks
declaration.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.
thanks!