8
8
using Microsoft . ML . Runtime . RunTests ;
9
9
using Microsoft . ML . Runtime . Tools ;
10
10
using System . IO ;
11
- using System . Text ;
12
11
13
12
namespace Microsoft . ML . Benchmarks
14
13
{
15
- // Adding this class to not print anything to the console.
16
- // This is required for the current version of BenchmarkDotNet
17
- internal class EmptyWriter : TextWriter
18
- {
19
- internal static readonly EmptyWriter Instance = new EmptyWriter ( ) ;
20
- public override Encoding Encoding => null ;
21
- }
22
-
23
14
public class MultiClassClassification
24
15
{
25
16
private string _dataPath_Wiki ;
@@ -35,40 +26,59 @@ public void SetupTrainingSpeedTests()
35
26
_dataPath_Wiki = Path . GetFullPath ( TestDatasets . WikiDetox . trainFilename ) ;
36
27
37
28
if ( ! File . Exists ( _dataPath_Wiki ) )
38
- {
39
- throw new FileNotFoundException ( $ "Could not find { _dataPath_Wiki } Please ensure you have run 'build.cmd -- /t:DownloadExternalTestFiles /p:IncludeBenchmarkData=true' from the root") ;
40
- }
29
+ throw new FileNotFoundException ( string . Format ( Helpers . DatasetNotFound , _dataPath_Wiki ) ) ;
41
30
}
42
31
43
32
[ GlobalSetup ( Target = nameof ( Test_Multiclass_WikiDetox_BigramsAndTrichar_OVAAveragedPerceptron ) ) ]
44
33
public void SetupScoringSpeedTests ( )
45
34
{
46
35
SetupTrainingSpeedTests ( ) ;
47
36
_modelPath_Wiki = Path . Combine ( Directory . GetCurrentDirectory ( ) , @"WikiModel.zip" ) ;
48
- string cmd = @"CV k=5 data=" + _dataPath_Wiki + " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}} xf=Concat{col=Features:FeaturesText,logged_in,ns} tr=OVA{p=AveragedPerceptron{iter=10}} out={" + _modelPath_Wiki + "}" ;
49
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
37
+
38
+ string cmd = @"CV k=5 data=" + _dataPath_Wiki +
39
+ " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} xf=Convert{col=logged_in type=R4}" +
40
+ " xf=CategoricalTransform{col=ns}" +
41
+ " xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}}" +
42
+ " xf=Concat{col=Features:FeaturesText,logged_in,ns}" +
43
+ " tr=OVA{p=AveragedPerceptron{iter=10}}" +
44
+ " out={" + _modelPath_Wiki + "}" ;
45
+
46
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
50
47
{
51
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
48
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
52
49
}
53
50
}
54
51
55
52
[ Benchmark ]
56
53
public void CV_Multiclass_WikiDetox_BigramsAndTrichar_OVAAveragedPerceptron ( )
57
54
{
58
- string cmd = @"CV k=5 data=" + _dataPath_Wiki + " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}} xf=Concat{col=Features:FeaturesText,logged_in,ns} tr=OVA{p=AveragedPerceptron{iter=10}}" ;
59
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
55
+ string cmd = @"CV k=5 data=" + _dataPath_Wiki +
56
+ " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+}" +
57
+ " xf=Convert{col=logged_in type=R4}" +
58
+ " xf=CategoricalTransform{col=ns}" +
59
+ " xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}}" +
60
+ " xf=Concat{col=Features:FeaturesText,logged_in,ns}" +
61
+ " tr=OVA{p=AveragedPerceptron{iter=10}}" ;
62
+
63
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
60
64
{
61
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
65
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
62
66
}
63
67
}
64
68
65
69
[ Benchmark ]
66
70
public void CV_Multiclass_WikiDetox_BigramsAndTrichar_LightGBMMulticlass ( )
67
71
{
68
- string cmd = @"CV k=5 data=" + _dataPath_Wiki + " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}} xf=Concat{col=Features:FeaturesText,logged_in,ns} tr=LightGBMMulticlass{}" ;
69
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
72
+ string cmd = @"CV k=5 data=" + _dataPath_Wiki +
73
+ " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+}" +
74
+ " xf=Convert{col=logged_in type=R4}" +
75
+ " xf=CategoricalTransform{col=ns}" +
76
+ " xf=TextTransform{col=FeaturesText:comment wordExtractor=NGramExtractorTransform{ngram=2}}" +
77
+ " xf=Concat{col=Features:FeaturesText,logged_in,ns} tr=LightGBMMulticlass{}" ;
78
+
79
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
70
80
{
71
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
81
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
72
82
}
73
83
}
74
84
@@ -78,29 +88,45 @@ public void Test_Multiclass_WikiDetox_BigramsAndTrichar_OVAAveragedPerceptron()
78
88
// This benchmark is profiling bulk scoring speed and not training speed.
79
89
string modelpath = Path . Combine ( Directory . GetCurrentDirectory ( ) , @"WikiModel.fold000.zip" ) ;
80
90
string cmd = @"Test data=" + _dataPath_Wiki + " in=" + modelpath ;
81
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
91
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
82
92
{
83
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
93
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
84
94
}
85
95
}
86
96
87
97
[ Benchmark ]
88
98
public void CV_Multiclass_WikiDetox_WordEmbeddings_OVAAveragedPerceptron ( )
89
99
{
90
- string cmd = @"CV tr=OVA{p=AveragedPerceptron{iter=10}} k=5 loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} data=" + _dataPath_Wiki + " xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor=NGramExtractorTransform{ngram=2}} xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D} xf=Concat{col=Features:FeaturesText,FeaturesWordEmbedding,logged_in,ns}" ;
91
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
100
+ string cmd = @"CV k=5 data=" + _dataPath_Wiki +
101
+ " tr=OVA{p=AveragedPerceptron{iter=10}}" +
102
+ " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+}" +
103
+ " xf=Convert{col=logged_in type=R4}" +
104
+ " xf=CategoricalTransform{col=ns}" +
105
+ " xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor=NGramExtractorTransform{ngram=2}}" +
106
+ " xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D}" +
107
+ " xf=Concat{col=Features:FeaturesText,FeaturesWordEmbedding,logged_in,ns}" ;
108
+
109
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
92
110
{
93
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
111
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
94
112
}
95
113
}
96
114
97
115
[ Benchmark ]
98
116
public void CV_Multiclass_WikiDetox_WordEmbeddings_SDCAMC ( )
99
117
{
100
- string cmd = @"CV tr=SDCAMC k=5 loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+} data=" + _dataPath_Wiki + " xf=Convert{col=logged_in type=R4} xf=CategoricalTransform{col=ns} xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor={} charExtractor={}} xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D} xf=Concat{col=Features:FeaturesWordEmbedding,logged_in,ns}" ;
101
- using ( var tlc = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
118
+ string cmd = @"CV k=5 data=" + _dataPath_Wiki +
119
+ " tr=SDCAMC" +
120
+ " loader=TextLoader{quote=- sparse=- col=Label:R4:0 col=rev_id:TX:1 col=comment:TX:2 col=logged_in:BL:4 col=ns:TX:5 col=sample:TX:6 col=split:TX:7 col=year:R4:3 header=+}" +
121
+ " xf=Convert{col=logged_in type=R4}" +
122
+ " xf=CategoricalTransform{col=ns}" +
123
+ " xf=TextTransform{col=FeaturesText:comment tokens=+ wordExtractor={} charExtractor={}}" +
124
+ " xf=WordEmbeddingsTransform{col=FeaturesWordEmbedding:FeaturesText_TransformedText model=FastTextWikipedia300D}" +
125
+ " xf=Concat{col=Features:FeaturesWordEmbedding,logged_in,ns}" ;
126
+
127
+ using ( var environment = new ConsoleEnvironment ( verbose : false , sensitivity : MessageSensitivity . None , outWriter : EmptyWriter . Instance ) )
102
128
{
103
- Maml . MainCore ( tlc , cmd , alwaysPrintStacktrace : false ) ;
129
+ Maml . MainCore ( environment , cmd , alwaysPrintStacktrace : false ) ;
104
130
}
105
131
}
106
132
}
0 commit comments