-
Notifications
You must be signed in to change notification settings - Fork 1.9k
API 'getting started' examples #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
// It currently doesn't compile, let alone work, but we still can discuss and improve the syntax. | ||
|
||
// Initialize the environment. | ||
using (var env = new TlcEnvironment()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using (var env = new TlcEnvironment()) [](start = 12, length = 38)
If it's aspirational I kind of feel like we ought to not make env
disposable. :D :D #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how env
only shows up in a single call now. Can we move it to the end of the arg list, and add an overload that doesn't take it and uses some default? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we change the environment class name? TlcEnvironment with "Tlc" might sound strange to users. I mean, end users shouldn't know what TLS is, right? - THey might wonder what "Tlc" is.. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CESARDELATORRE #541 we have issue for this. #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I think I'll rework it to the further extreme: make 'pigsty-starting' lines accept env as optional (and create it if not provided), and then propagate further.
In reply to: 207425107 [](ancestors = 207425107)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I intentionally left it as 'TLC' to trigger the naming discussion.
In reply to: 207607770 [](ancestors = 207607770)
string dataPath = "iris-data.txt"; | ||
var data = TextReader.FitAndRead(env, dataPath, c => (Label: c.LoadString(0), Features: c.LoadFloat(1, 4))); | ||
|
||
// Convert string label to integer for training. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
integer [](start = 43, length = 7)
key #Resolved
{ | ||
// Load the data into the system. | ||
string dataPath = "iris-data.txt"; | ||
var data = TextReader.FitAndRead(env, dataPath, c => (Label: c.LoadString(0), Features: c.LoadFloat(1, 4))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name will need to be something else so that it doesn't collide with System.IO.TextReader, TextDataReader or something like that. Also ReadAndFit
seems more natural to me.
What sort of object is c
? an you point me to the code methods that do Load*
so I can understand this better? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextDataReader sounds OK.
'ReadAndFit': well, the code as written is actually a shorthand for
.Fit(dataPath).Read(dataPath)
, so ReadAndFit would be incorrect
the methods of c
are the ones Tom is in the process of writing (TomFinley@0c516eb#diff-2b73db3f78ce6eb358eb2a7ef9bed2eb)
In reply to: 207608639 [](ancestors = 207608639)
{ | ||
// Load the data into the system. | ||
string dataPath = "iris-data.txt"; | ||
var data = TextReader.FitAndRead(env, dataPath, c => (Label: c.LoadString(0), Features: c.LoadFloat(1, 4))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Features: [](start = 94, length = 9)
Do we have to use the term Features
or could you break it into SepalLength, SepalWidth, PetalLength, PetalWidth? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either is doable. Do you think breaking it down is preferable? I made it into 'Features' because I wanted to demonstrate that you don't HAVE to bring in features as scalars. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice thing about breaking it apart is in your inference code.
You don't have to say
engine.Predict(new IrisExample { Features = new[] { 3.3f, 1.6f, 0.2f, 5.1f } })
Which one was SepalLength
, and which one was SepalWidth
? Oops - I accidentally put Petal properties first in the array, and Sepal properties 2nd.
Where if you have them broken apart you can say:
engine.Predict(new IrisExample
{
SepalWidth = 3.3f,
SepalLength = 1.6f,
PetalWidth = 0.2f,
PetalLength = 5.1f
});
Which makes for much more readable and maintainable code IMO. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true when you have 4 features, but I observed that a more common case is to have a dozen to a hundred. In this case, demonstrating that we CAN handle this with a vector column without explicitly naming them all is valuable. But I will rework the example to have separate scalars for features.
In reply to: 207697383 [](ancestors = 207697383)
|
||
// Load the data into the system. | ||
string dataPath = "iris-data.txt"; | ||
var data = TextReader.FitAndRead(env, dataPath, row => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to be concerned about asynchronous I/O? Should methods that are I/O bound return Task<T>
? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they should have an async analogy, but async-only - I'm not sure
In reply to: 208417516 [](ancestors = 208417516)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sort of remember the discussion, but why do we need to expose FitAndRead to users here? Do we also have a Read case without Fit? Can we simply have something like env.TextReader.Read(datapath, row => ...)? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our existing TextLoader is trainable: it scans the schema of the file and determines number of features under certain conditions.
So, we are essentially calling:
TextReader.CreateEstimator(row=>...).Fit(dataPath).Read(dataPath)
(and discarding the estimator and the reader in the process.
I suppose if we want to discard the reader anyway, we might just as well rename FitAndRead
to Read
. But technically, it would still call the above code, so I was reluctant to hide what we are actually doing.
In reply to: 208640305 [](ancestors = 208640305)
PetalLength: row.ReadFloat(4))); | ||
|
||
|
||
var preprocess = data.Schema.MakeEstimator(row => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to expose Schema to users here? Can we simply do data.MakeExtimator(row => ...) #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how I originally phrased it, but it makes an appearance that the data itself is being 'used' and somehow 'remembered' by the estimator. Hence the 'Schema' in the middle.
In reply to: 208640562 [](ancestors = 208640562)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Now that I think about that, the flow looks a little bit odd in my opinion. You start from the data, then you create an estimator from the data (without using the data) and then you call fit over the data again. In principle you only really need the data at the beginning when you create the reader, right? Or you can actually call fit over different datasets? If the later is true, why do you need to create a reader over a specific dataset at the beginnig? In the current API data and pipeline creations are entangled in multiple places and I think it create confusion a bit. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can actually call Fit
over different datasets, of course.
The only thing we really need to MakeEstimator
is to have the input schema. We sort-of piggy-backed on the TextReader
here to define the schema and simultaneously define how to read the data file.
We could instead do
var preprocess = PigstyPipeline.WithSchema(row=>
row => (
Label: row.String(),
SepalWidth: row.Float(),
SepalLength: row.Float(),
PetalWidth: row.Float(),
PetalLength: row.Float())
.MakeEstimator(row => (Label: row.Label.DictionarizeLabel() ...)
in this case, there is no need to read data
until whenever you want.
But at SOME point you will have to define HOW to read these columns, so lines 30-34 are still needed
In reply to: 208660933 [](ancestors = 208660933)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed: at some point you will need to create a reader and define the schema, but I think that separating the 2 (data creation from pipeline creation) is definitely cleaner. Additionally, for the datasets you could only define the schema on the pipeline, and do env.TextReader.Read(dataPath)
and the validation of the schema will be done on the pipeline at fit time. Basically you could reverse the pattern you have now: define the schema on the pipeline and have the dataset schema matched at fit time, instead of define the schema on the dataset and have the data.Schema
thing to pass the schema to the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is going to work. You cannot just take an ISchema
and make text reader configuration of out it: you need to tell what column indices go where. Note the ReadFloat(0)
and other arguments to ReadXXX
In reply to: 208726028 [](ancestors = 208726028)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well but that is a problem of the dataset, not of the pipeline nor of the schema. In theory one would do something like data.map(row => row._2, row._1, row._0)
if there is the need to change column orders for example. Even because if you have many possible input dataset, some with the right order and some not, it is verbose to repeat the schema definition for all of them, where verbosity == more chances or errors.
Just letting everyone know: the window to making 'arbitrary' changes to the 'getting started' examples is going to last until about late August. After that, we will finalize the amount of required work to make these happen, and begin implementation. At that point, the only changes we can freely make is renaming existing members and adding convenience extension methods. |
Thanks for the comments |
These examples currently do not compile, they depend on both Estimators and static type checks, but let's at least agree that we can all stand behind them in terms of simplicity.
Do not merge, this is a discussion-only PR.