@@ -26,8 +26,8 @@ public static void NgramTransform()
26
26
// A pipeline to tokenize text as characters and then combine them together into ngrams
27
27
// The pipeline uses the default settings to featurize.
28
28
29
- var charsPipeline = ml . Transforms . Text . TokenizeCharacters ( "Chars" , "SentimentText" , useMarkerCharacters : false ) ;
30
- var ngramOnePipeline = ml . Transforms . Text . ProduceNgrams ( "CharsUnigrams" , "Chars" , ngramLength : 1 ) ;
29
+ var charsPipeline = ml . Transforms . Text . TokenizeCharacters ( "Chars" , "SentimentText" , useMarkerCharacters : false ) ;
30
+ var ngramOnePipeline = ml . Transforms . Text . ProduceNgrams ( "CharsUnigrams" , "Chars" , ngramLength : 1 ) ;
31
31
var ngramTwpPipeline = ml . Transforms . Text . ProduceNgrams ( "CharsTwograms" , "Chars" ) ;
32
32
var oneCharsPipeline = charsPipeline . Append ( ngramOnePipeline ) ;
33
33
var twoCharsPipeline = charsPipeline . Append ( ngramTwpPipeline ) ;
@@ -38,30 +38,30 @@ public static void NgramTransform()
38
38
39
39
// Small helper to print the text inside the columns, in the console.
40
40
Action < string , IEnumerable < VBuffer < float > > , VBuffer < ReadOnlyMemory < char > > > printHelper = ( columnName , column , names ) =>
41
- {
42
- Console . WriteLine ( $ "{ columnName } column obtained post-transformation.") ;
43
- var slots = names . GetValues ( ) ;
44
- foreach ( var featureRow in column )
45
- {
46
- foreach ( var item in featureRow . Items ( ) )
47
- Console . Write ( $ "'{ slots [ item . Key ] } ' - { item . Value } ") ;
48
- Console . WriteLine ( "" ) ;
49
- }
41
+ {
42
+ Console . WriteLine ( $ "{ columnName } column obtained post-transformation.") ;
43
+ var slots = names . GetValues ( ) ;
44
+ foreach ( var featureRow in column )
45
+ {
46
+ foreach ( var item in featureRow . Items ( ) )
47
+ Console . Write ( $ "'{ slots [ item . Key ] } ' - { item . Value } ") ;
48
+ Console . WriteLine ( "" ) ;
49
+ }
50
50
51
- Console . WriteLine ( "===================================================" ) ;
52
- } ;
51
+ Console . WriteLine ( "===================================================" ) ;
52
+ } ;
53
53
// Preview of the CharsUnigrams column obtained after processing the input.
54
54
VBuffer < ReadOnlyMemory < char > > slotNames = default ;
55
55
transformedData_onechars . Schema [ "CharsUnigrams" ] . GetSlotNames ( ref slotNames ) ;
56
- var charsOneGramColumn = transformedData_onechars . GetColumn < VBuffer < float > > ( ml , "CharsUnigrams" ) ;
56
+ var charsOneGramColumn = transformedData_onechars . GetColumn < VBuffer < float > > ( transformedData_onechars . Schema [ "CharsUnigrams" ] ) ;
57
57
printHelper ( "CharsUnigrams" , charsOneGramColumn , slotNames ) ;
58
58
59
59
// CharsUnigrams column obtained post-transformation.
60
60
// 'B' - 1 'e' - 6 's' - 1 't' - 1 '<?>' - 4 'g' - 1 'a' - 2 'm' - 1 'I' - 1 ''' - 1 'v' - 2 ...
61
61
// 'e' - 1 '<?>' - 2 'd' - 1 '=' - 4 'R' - 1 'U' - 1 'D' - 2 'E' - 1 'u' - 1 ',' - 1 '2' - 1
62
62
// 'B' - 0 'e' - 6 's' - 3 't' - 6 '<?>' - 9 'g' - 2 'a' - 2 'm' - 2 'I' - 0 ''' - 0 'v' - 0 ...
63
63
// Preview of the CharsTwoGrams column obtained after processing the input.
64
- var charsTwoGramColumn = transformedData_twochars . GetColumn < VBuffer < float > > ( ml , "CharsTwograms" ) ;
64
+ var charsTwoGramColumn = transformedData_twochars . GetColumn < VBuffer < float > > ( transformedData_onechars . Schema [ "CharsUnigrams" ] ) ;
65
65
transformedData_twochars . Schema [ "CharsTwograms" ] . GetSlotNames ( ref slotNames ) ;
66
66
printHelper ( "CharsTwograms" , charsTwoGramColumn , slotNames ) ;
67
67
0 commit comments