Skip to content

Commit 3e5b5ed

Browse files
zeahmedeerhardt
authored andcommitted
Comments added to LearningPipeline class to make Intellisense more helpful. (dotnet#50)
* Comments added to LearningPipeline class in accordance with #Bug 240636: Intellisense is not helpful with filling in pipeline components. * Comments added to LearningPipeline class in accordance with #Bug 240636: Intellisense is not helpful with filling in pipeline components. * Fixed a typo in namespace * Addressed reviewers' comments. * Addressed reviewers' comments. * Addressed reviewers' comments.
1 parent 4f9ee89 commit 3e5b5ed

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/Microsoft.ML/LearningPipeline.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,113 @@ public ScorerPipelineStep(Var<IDataView> data, Var<ITransformModel> model)
2626
public Var<ITransformModel> Model { get; }
2727
}
2828

29+
30+
/// <summary>
31+
/// The <see cref="LearningPipeline"/> class is used to define the steps needed to perform a desired machine learning task.<para/>
32+
/// The steps are defined by adding a data loader (e.g. <see cref="TextLoader"/>) followed by zero or more transforms (e.g. <see cref="Microsoft.ML.Transforms.TextFeaturizer"/>)
33+
/// and at most one trainer/learner (e.g. <see cref="Microsoft.ML.Trainers.FastTreeBinaryClassifier"/>) in the pipeline.
34+
///
35+
/// </summary>
36+
/// <example>
37+
/// <para/>
38+
/// For example,<para/>
39+
/// <code>
40+
/// var pipeline = new LearningPipeline();
41+
/// pipeline.Add(new TextLoader &lt;SentimentData&gt; (dataPath, separator: ","));
42+
/// pipeline.Add(new TextFeaturizer("Features", "SentimentText"));
43+
/// pipeline.Add(new FastTreeBinaryClassifier());
44+
///
45+
/// var model = pipeline.Train&lt;SentimentData, SentimentPrediction&gt;();
46+
/// </code>
47+
/// </example>
2948
[DebuggerTypeProxy(typeof(LearningPipelineDebugProxy))]
3049
public class LearningPipeline : ICollection<ILearningPipelineItem>
3150
{
3251
private List<ILearningPipelineItem> Items { get; } = new List<ILearningPipelineItem>();
3352

53+
/// <summary>
54+
/// Construct an empty <see cref="LearningPipeline"/> object.
55+
/// </summary>
3456
public LearningPipeline()
3557
{
3658
}
3759

60+
/// <summary>
61+
/// Get the count of ML components in the <see cref="LearningPipeline"/> object
62+
/// </summary>
3863
public int Count => Items.Count;
3964
public bool IsReadOnly => false;
65+
66+
/// <summary>
67+
/// Add a data loader, transform or trainer into the pipeline.
68+
/// Possible data loader(s), transforms and trainers options are
69+
/// <para>
70+
/// Data Loader:
71+
/// <see cref="Microsoft.ML.TextLoader{TInput}" />
72+
/// etc.
73+
/// </para>
74+
/// <para>
75+
/// Transforms:
76+
/// <see cref="Microsoft.ML.Transforms.Dictionarizer"/>,
77+
/// <see cref="Microsoft.ML.Transforms.CategoricalOneHotVectorizer"/>
78+
/// <see cref="Microsoft.ML.Transforms.MinMaxNormalizer"/>,
79+
/// <see cref="Microsoft.ML.Transforms.ColumnCopier"/>,
80+
/// <see cref="Microsoft.ML.Transforms.ColumnConcatenator"/>,
81+
/// <see cref="Microsoft.ML.Transforms.TextFeaturizer"/>,
82+
/// etc.
83+
/// </para>
84+
/// <para>
85+
/// Trainers:
86+
/// <see cref="Microsoft.ML.Trainers.AveragedPerceptronBinaryClassifier"/>,
87+
/// <see cref="Microsoft.ML.Trainers.LogisticRegressor"/>,
88+
/// <see cref="Microsoft.ML.Trainers.StochasticDualCoordinateAscentClassifier"/>,
89+
/// <see cref="Microsoft.ML.Trainers.FastTreeRegressor"/>,
90+
/// etc.
91+
/// </para>
92+
/// For a complete list of transforms and trainers, please see "Microsoft.ML.Transforms" and "Microsoft.ML.Trainers" namespaces.
93+
/// </summary>
94+
/// <param name="item">Any ML component (data loader, transform or trainer) defined as <see cref="ILearningPipelineItem"/>.</param>
4095
public void Add(ILearningPipelineItem item) => Items.Add(item);
96+
97+
/// <summary>
98+
/// Remove all the loaders/transforms/trainers from the pipeline.
99+
/// </summary>
41100
public void Clear() => Items.Clear();
101+
102+
/// <summary>
103+
/// Check if a specific loader/transform/trainer is in the pipeline?
104+
/// </summary>
105+
/// <param name="item">Any ML component (data loader, transform or trainer) defined as <see cref="ILearningPipelineItem"/>.</param>
106+
/// <returns>true if item is found in the pipeline; otherwise, false.</returns>
42107
public bool Contains(ILearningPipelineItem item) => Items.Contains(item);
108+
109+
/// <summary>
110+
/// Copy the pipeline items into an array.
111+
/// </summary>
112+
/// <param name="array">The one-dimensional Array that is the destination of the elements copied from.</param>
113+
/// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param>
43114
public void CopyTo(ILearningPipelineItem[] array, int arrayIndex) => Items.CopyTo(array, arrayIndex);
44115
public IEnumerator<ILearningPipelineItem> GetEnumerator() => Items.GetEnumerator();
116+
117+
/// <summary>
118+
/// Remove an item from the pipeline.
119+
/// </summary>
120+
/// <param name="item"><see cref="ILearningPipelineItem"/> to remove.</param>
121+
/// <returns>true if item was removed from the pipeline; otherwise, false.</returns>
45122
public bool Remove(ILearningPipelineItem item) => Items.Remove(item);
46123
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
47124

125+
/// <summary>
126+
/// Train the model using the ML components in the pipeline.
127+
/// </summary>
128+
/// <typeparam name="TInput">Type of data instances the model will be trained on. It's a custom type defined by the user according to the structure of data.
129+
/// <para/>
130+
/// Please see https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet/get-started/windows for more details on input type.
131+
/// </typeparam>
132+
/// <typeparam name="TOutput">Ouput type. The prediction will be return based on this type.
133+
/// Please see https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet/get-started/windows for more details on output type.
134+
/// </typeparam>
135+
/// <returns>PredictionModel object. This is the model object used for prediction on new instances. </returns>
48136
public PredictionModel<TInput, TOutput> Train<TInput, TOutput>()
49137
where TInput : class
50138
where TOutput : class, new()

0 commit comments

Comments
 (0)