[go: nahoru, domu]

Skip to content
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

Method Chaining in Tensorflow #37311

Open
najibghadri opened this issue Mar 4, 2020 · 2 comments
Open

Method Chaining in Tensorflow #37311

najibghadri opened this issue Mar 4, 2020 · 2 comments
Assignees
Labels
comp:apis Highlevel API related issues comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests

Comments

@najibghadri
Copy link
najibghadri commented Mar 4, 2020

I have posted a question about this in stackoverflow. https://stackoverflow.com/questions/60528238/why-no-method-chaining-in-tensorflow

Aka. named parameter idiom. I did a simple Nearest Neighbor algorithm in TF and I ended up writing the whole NN algorithm in one line. You can argue that I should take it apart, but I think this happens often anyways (in coding in general too):

tf.math.argmin(tf.math.reduce_sum(tf.math.abs(tf.math.subtract(Xtrain_set, Xtest_row)), axis=1), output_type=tf.int32)

# returns the minimum train set indices for each X predictable row based on L1 (in a for cycle) but this is not important

It could be much more readable and simple to write:

tf.subtract(Xtrain_set, Xtest_row).abs().reduce_sum(axis=1).argmin(output_type=tf.int32)

I think it really follows the "Tensor-flow" thinking too.
Thanks.

@najibghadri najibghadri added the type:feature Feature requests label Mar 4, 2020
@gadagashwini-zz gadagashwini-zz added the comp:apis Highlevel API related issues label Mar 5, 2020
@gowthamkpr gowthamkpr added comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Mar 5, 2020
@bersbersbers
Copy link

I have a similar idea for the Keras interface: instead of

model = vgg16.VGG16()
model.compile(loss="mse")
model.fit(...)

it would be nice to be able to do

vgg16.VGG16().compile(loss="mse").fit(...)

And I think all it takes in this examples is a simple return(self) here:

def compile(self,
optimizer='rmsprop',
loss=None,
metrics=None,
loss_weights=None,
weighted_metrics=None,
run_eagerly=None,
**kwargs):
"""Configures the model for training.

self.loss = loss or {} # Backwards compat.
def _get_optimizer(self, optimizer):

@amahendrakar amahendrakar assigned ravikyram and unassigned gowthamkpr Jan 15, 2021
@ravikyram ravikyram assigned ymodak and unassigned ravikyram Jan 18, 2021
@OrigamiDream
Copy link
OrigamiDream commented May 26, 2023

I've just made an extension for TensorFlow that creates simple proxies for method chaining in Tensors via few lines of code.
This repo can do what you wanted to do.

https://github.com/OrigamiDream/flowchain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

7 participants