Simplify Pipeline Initalization with Append() that returns the pipeline
Issue: Currently we have to use the pipeline instance to append additional items to the pipeline. It looks something like this:
var pipeline = new LearningPipeline();
pipeline.Add(new TextLoader<SentimentData>(dataPath, separator: ","));
pipeline.Add(new TextFeaturizer("Features", "SentimentText"));
We can add the ability to add a pipeline item in a fluent fashion. The benefit would be reduction of typing and cleaner API.
This would require pipeline to add the following method:
public LearningPipeline Append(ILearningPipelineItem item);
The user code will look like this:
var pipeline = new LearningPipeline()
.Append(new TextLoader<SentimentData>(dataPath, separator: ","))
.Append(new TextFeaturizer("Features", "SentimentText"));
(optional) with extension methods, this can be simplified even further to:
var pipeline = new LearningPipeline()
.AddTextLoader<SentimentData>(dataPath, separator: ",")
.AddTextFeaturizer("Features", "SentimentText");
The user code will look like this: var pipeline = new LearningPipeline() .Add(new TextLoader
(dataPath, separator: ",")) .Add(new TextFeaturizer("Features", "SentimentText"));
Did you mean to have .Append instead of .Add?
+1 on this change. However, I wonder whether we should return a new copy of the pipeline after each .Append or .Add call. Otherwise, the following code would be very confusing:
var p1 = new LearningPipeline().Add(A).Add(B);
var p2 = p1.Add(C).Add(D);
var p3 = p1.Add(D);
We should make sure that p1 refers to [A,B], p2 to [A,B,C,D] and p3 to [A,B,D].
It would be also good to make the LearningPipeline a List
closing this issue as the PR has already merged and the API will also be updated in the next release.