machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

Simplify Pipeline Initalization with Append() that returns the pipeline

Open glebuk opened this issue 8 years ago • 4 comments

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");

glebuk avatar May 04 '18 20:05 glebuk

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?

eerhardt avatar May 04 '18 20:05 eerhardt

+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].

markusweimer avatar May 04 '18 23:05 markusweimer

It would be also good to make the LearningPipeline a List instead of Collection. This way it would be easy to manipulate the pipeline by adding and replacing items in the arbitrary location. Example of the scenario is sweep of different learners.

glebuk avatar May 29 '18 22:05 glebuk

closing this issue as the PR has already merged and the API will also be updated in the next release.

shauheen avatar Jun 26 '18 17:06 shauheen