Skip to content

Commit 1288d1d

Browse files
author
Rayan-Krishnan
authored
Reformatting Test, Projection and TimeSeries of Transform to Width 85 (dotnet#3947)
* transform/text and projection formatted to 85 char * transforms/timeseries formatted to 85 char * minor tab and spacing fixes
1 parent 0153754 commit 1288d1d

29 files changed

+742
-382
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/Projection/VectorWhiten.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ namespace Samples.Dynamic
99
public sealed class VectorWhiten
1010
{
1111

12-
/// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
12+
/// This example requires installation of additional nuget package
13+
/// <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
1314
public static void Example()
1415
{
15-
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging,
16-
// as well as the source of randomness.
16+
// Create a new ML context, for ML.NET operations. It can be used for
17+
// exception tracking and logging, as well as the source of randomness.
1718
var ml = new MLContext();
1819

1920
// Get a small dataset as an IEnumerable and convert it to an IDataView.
@@ -32,20 +33,29 @@ public static void Example()
3233
// 6 7 8 9 0 1 2 3 4 5
3334

3435
// A small printing utility.
35-
Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName, column) =>
36+
Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName,
37+
column) =>
3638
{
37-
Console.WriteLine($"{colName} column obtained post-transformation.");
39+
Console.WriteLine($"{colName} column obtained " +
40+
$"post-transformation.");
41+
3842
foreach (var row in column)
39-
Console.WriteLine($"{string.Join(" ", row.DenseValues().Select(x => x.ToString("f3")))} ");
43+
Console.WriteLine(string.Join(" ", row.DenseValues().Select(x =>
44+
x.ToString("f3")))+" ");
4045
};
4146

4247
// A pipeline to project Features column into white noise vector.
43-
var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(SampleVectorOfNumbersData.Features),
44-
kind: Microsoft.ML.Transforms.WhiteningKind.ZeroPhaseComponentAnalysis);
48+
var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(
49+
SampleVectorOfNumbersData.Features), kind: Microsoft.ML.Transforms
50+
.WhiteningKind.ZeroPhaseComponentAnalysis);
51+
4552
// The transformed (projected) data.
46-
var transformedData = whiteningPipeline.Fit(trainData).Transform(trainData);
53+
var transformedData = whiteningPipeline.Fit(trainData).Transform(
54+
trainData);
55+
4756
// Getting the data of the newly created column, so we can preview it.
48-
var whitening = transformedData.GetColumn<VBuffer<float>>(transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);
57+
var whitening = transformedData.GetColumn<VBuffer<float>>(
58+
transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);
4959

5060
printHelper(nameof(SampleVectorOfNumbersData.Features), whitening);
5161

@@ -68,11 +78,16 @@ private class SampleVectorOfNumbersData
6878
/// <summary>
6979
/// Returns a few rows of the infertility dataset.
7080
/// </summary>
71-
private static IEnumerable<SampleVectorOfNumbersData> GetVectorOfNumbersData()
81+
private static IEnumerable<SampleVectorOfNumbersData>
82+
GetVectorOfNumbersData()
7283
{
7384
var data = new List<SampleVectorOfNumbersData>();
74-
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } });
75-
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } });
85+
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 0,
86+
1, 2, 3, 4, 5, 6, 7, 8, 9 } });
87+
88+
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 1,
89+
2, 3, 4, 5, 6, 7, 8, 9, 0 } });
90+
7691
data.Add(new SampleVectorOfNumbersData
7792
{
7893
Features = new float[10] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/Projection/VectorWhitenWithOptions.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ namespace Samples.Dynamic
88
{
99
public sealed class VectorWhitenWithOptions
1010
{
11-
/// This example requires installation of additional nuget package <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
11+
/// This example requires installation of additional nuget package
12+
/// <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
1213
public static void Example()
1314
{
14-
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging,
15-
// as well as the source of randomness.
15+
// Create a new ML context, for ML.NET operations. It can be used for
16+
// exception tracking and logging, as well as the source of randomness.
1617
var ml = new MLContext();
1718

1819
// Get a small dataset as an IEnumerable and convert it to an IDataView.
@@ -31,20 +32,30 @@ public static void Example()
3132
// 6 7 8 9 0 1 2 3 4 5
3233

3334
// A small printing utility.
34-
Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName, column) =>
35+
Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName,
36+
column) =>
3537
{
36-
Console.WriteLine($"{colName} column obtained post-transformation.");
38+
Console.WriteLine($"{colName} column obtained" +
39+
$"post-transformation.");
40+
3741
foreach (var row in column)
38-
Console.WriteLine($"{string.Join(" ", row.DenseValues().Select(x => x.ToString("f3")))} ");
42+
Console.WriteLine(string.Join(" ", row.DenseValues().Select(x =>
43+
x.ToString("f3")))+" ");
3944
};
4045

4146

4247
// A pipeline to project Features column into white noise vector.
43-
var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(SampleVectorOfNumbersData.Features), kind: Microsoft.ML.Transforms.WhiteningKind.PrincipalComponentAnalysis, rank: 4);
48+
var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(
49+
SampleVectorOfNumbersData.Features), kind: Microsoft.ML.Transforms
50+
.WhiteningKind.PrincipalComponentAnalysis, rank: 4);
51+
4452
// The transformed (projected) data.
45-
var transformedData = whiteningPipeline.Fit(trainData).Transform(trainData);
53+
var transformedData = whiteningPipeline.Fit(trainData).Transform(
54+
trainData);
55+
4656
// Getting the data of the newly created column, so we can preview it.
47-
var whitening = transformedData.GetColumn<VBuffer<float>>(transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);
57+
var whitening = transformedData.GetColumn<VBuffer<float>>(
58+
transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);
4859

4960
printHelper(nameof(SampleVectorOfNumbersData.Features), whitening);
5061

@@ -66,11 +77,16 @@ private class SampleVectorOfNumbersData
6677
/// <summary>
6778
/// Returns a few rows of the infertility dataset.
6879
/// </summary>
69-
private static IEnumerable<SampleVectorOfNumbersData> GetVectorOfNumbersData()
80+
private static IEnumerable<SampleVectorOfNumbersData>
81+
GetVectorOfNumbersData()
7082
{
7183
var data = new List<SampleVectorOfNumbersData>();
72-
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } });
73-
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } });
84+
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 0,
85+
1, 2, 3, 4, 5, 6, 7, 8, 9 } });
86+
87+
data.Add(new SampleVectorOfNumbersData { Features = new float[10] { 1,
88+
2, 3, 4, 5, 6, 7, 8, 9, 0 } });
89+
7490
data.Add(new SampleVectorOfNumbersData
7591
{
7692
Features = new float[10] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/Text/ApplyCustomWordEmbedding.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ public static class ApplyCustomWordEmbedding
99
{
1010
public static void Example()
1111
{
12-
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging,
13-
// as well as the source of randomness.
12+
// Create a new ML context, for ML.NET operations. It can be used for
13+
// exception tracking and logging, as well as the source of randomness.
1414
var mlContext = new MLContext();
1515

16-
// Create an empty list as the dataset. The 'ApplyWordEmbedding' does not require training data as
17-
// the estimator ('WordEmbeddingEstimator') created by 'ApplyWordEmbedding' API is not a trainable estimator.
16+
// Create an empty list as the dataset. The 'ApplyWordEmbedding' does
17+
// not require training data as the estimator ('WordEmbeddingEstimator')
18+
// created by 'ApplyWordEmbedding' API is not a trainable estimator.
1819
// The empty list is only needed to pass input schema to the pipeline.
1920
var emptySamples = new List<TextData>();
2021

@@ -33,25 +34,33 @@ public static void Example()
3334
file.WriteLine("buy 0 0 20");
3435
}
3536

36-
// A pipeline for converting text into a 9-dimension word embedding vector using the custom word embedding model.
37-
// The 'ApplyWordEmbedding' computes the minimum, average and maximum values for each token's embedding vector.
38-
// Tokens in 'custommodel.txt' model are represented as 3-dimension vector.
39-
// Therefore, the output is of 9-dimension [min, avg, max].
37+
// A pipeline for converting text into a 9-dimension word embedding
38+
// vector using the custom word embedding model. The
39+
// 'ApplyWordEmbedding' computes the minimum, average and maximum values
40+
// for each token's embedding vector. Tokens in 'custommodel.txt' model
41+
// are represented as 3-dimension vector. Therefore, the output is of
42+
// 9 -dimension [min, avg, max].
4043
//
4144
// The 'ApplyWordEmbedding' API requires vector of text as input.
42-
// The pipeline first normalizes and tokenizes text then applies word embedding transformation.
45+
// The pipeline first normalizes and tokenizes text then applies word
46+
// embedding transformation.
4347
var textPipeline = mlContext.Transforms.Text.NormalizeText("Text")
44-
.Append(mlContext.Transforms.Text.TokenizeIntoWords("Tokens", "Text"))
45-
.Append(mlContext.Transforms.Text.ApplyWordEmbedding("Features", pathToCustomModel, "Tokens"));
48+
.Append(mlContext.Transforms.Text.TokenizeIntoWords("Tokens",
49+
"Text"))
50+
.Append(mlContext.Transforms.Text.ApplyWordEmbedding("Features",
51+
pathToCustomModel, "Tokens"));
4652

4753
// Fit to data.
4854
var textTransformer = textPipeline.Fit(emptyDataView);
4955

50-
// Create the prediction engine to get the embedding vector from the input text/string.
51-
var predictionEngine = mlContext.Model.CreatePredictionEngine<TextData, TransformedTextData>(textTransformer);
56+
// Create the prediction engine to get the embedding vector from the
57+
// input text/string.
58+
var predictionEngine = mlContext.Model.CreatePredictionEngine<TextData,
59+
TransformedTextData>(textTransformer);
5260

5361
// Call the prediction API to convert the text into embedding vector.
54-
var data = new TextData() { Text = "This is a great product. I would like to buy it again." };
62+
var data = new TextData() { Text = "This is a great product. I would " +
63+
"like to buy it again." };
5564
var prediction = predictionEngine.Predict(data);
5665

5766
// Print the length of the embedding vector.

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/Text/ApplyWordEmbedding.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,48 @@ public static class ApplyWordEmbedding
99
{
1010
public static void Example()
1111
{
12-
// Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging,
13-
// as well as the source of randomness.
12+
// Create a new ML context, for ML.NET operations. It can be used for
13+
// exception tracking and logging, as well as the source of randomness.
1414
var mlContext = new MLContext();
1515

16-
// Create an empty list as the dataset. The 'ApplyWordEmbedding' does not require training data as
17-
// the estimator ('WordEmbeddingEstimator') created by 'ApplyWordEmbedding' API is not a trainable estimator.
16+
// Create an empty list as the dataset. The 'ApplyWordEmbedding' does
17+
// not require training data as the estimator ('WordEmbeddingEstimator')
18+
// created by 'ApplyWordEmbedding' API is not a trainable estimator.
1819
// The empty list is only needed to pass input schema to the pipeline.
1920
var emptySamples = new List<TextData>();
2021

2122
// Convert sample list to an empty IDataView.
2223
var emptyDataView = mlContext.Data.LoadFromEnumerable(emptySamples);
2324

24-
// A pipeline for converting text into a 150-dimension embedding vector using pretrained 'SentimentSpecificWordEmbedding' model.
25-
// The 'ApplyWordEmbedding' computes the minimum, average and maximum values for each token's embedding vector.
26-
// Tokens in 'SentimentSpecificWordEmbedding' model are represented as 50-dimension vector.
27-
// Therefore, the output is of 150-dimension [min, avg, max].
25+
// A pipeline for converting text into a 150-dimension embedding vector
26+
// using pretrained 'SentimentSpecificWordEmbedding' model. The
27+
// 'ApplyWordEmbedding' computes the minimum, average and maximum values
28+
// for each token's embedding vector. Tokens in
29+
// 'SentimentSpecificWordEmbedding' model are represented as
30+
// 50 -dimension vector. Therefore, the output is of 150-dimension [min,
31+
// avg, max].
2832
//
2933
// The 'ApplyWordEmbedding' API requires vector of text as input.
30-
// The pipeline first normalizes and tokenizes text then applies word embedding transformation.
34+
// The pipeline first normalizes and tokenizes text then applies word
35+
// embedding transformation.
3136
var textPipeline = mlContext.Transforms.Text.NormalizeText("Text")
32-
.Append(mlContext.Transforms.Text.TokenizeIntoWords("Tokens", "Text"))
33-
.Append(mlContext.Transforms.Text.ApplyWordEmbedding("Features", "Tokens",
34-
WordEmbeddingEstimator.PretrainedModelKind.SentimentSpecificWordEmbedding));
37+
.Append(mlContext.Transforms.Text.TokenizeIntoWords("Tokens",
38+
"Text"))
39+
.Append(mlContext.Transforms.Text.ApplyWordEmbedding("Features",
40+
"Tokens", WordEmbeddingEstimator.PretrainedModelKind
41+
.SentimentSpecificWordEmbedding));
3542

3643
// Fit to data.
3744
var textTransformer = textPipeline.Fit(emptyDataView);
3845

39-
// Create the prediction engine to get the embedding vector from the input text/string.
40-
var predictionEngine = mlContext.Model.CreatePredictionEngine<TextData, TransformedTextData>(textTransformer);
46+
// Create the prediction engine to get the embedding vector from the
47+
// input text/string.
48+
var predictionEngine = mlContext.Model.CreatePredictionEngine<TextData,
49+
TransformedTextData>(textTransformer);
4150

4251
// Call the prediction API to convert the text into embedding vector.
43-
var data = new TextData() { Text = "This is a great product. I would like to buy it again." };
52+
var data = new TextData() { Text = "This is a great product. I would " +
53+
"like to buy it again." };
4454
var prediction = predictionEngine.Predict(data);
4555

4656
// Print the length of the embedding vector.

0 commit comments

Comments
 (0)