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

Doe tensorflow has api similar to pytorch's “masked_fill_” #41617

Closed
jason-liew opened this issue Jul 22, 2020 · 9 comments
Closed

Doe tensorflow has api similar to pytorch's “masked_fill_” #41617

jason-liew opened this issue Jul 22, 2020 · 9 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests

Comments

@jason-liew
Copy link

pytorch has squeeze , tf also has squeeze.
pytorch has unsqueeze, tf has expand_dims do the same thing with diff name.
pythorh has masked_fill , tf has ?

Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

System information

  • TensorFlow version (you are using): 2.2.0
  • Are you willing to contribute it (Yes/No): Yes

Describe the feature and the current behavior/state.
masked_fill_ api doc in pytorch
Will this change the current api? How?
Maybe not. It will add a new api.
Who will benefit with this feature?
someone try to migrate from pytorch to tensorflow like me.
Any Other info.

@jason-liew jason-liew added the type:feature Feature requests label Jul 22, 2020
@ravikyram
Copy link
Contributor

ravikyram commented Jul 22, 2020

@jason-liew

Can you please go through tf.boolean_mask and see this is the feature you are looking for?
Thanks!

@ravikyram ravikyram added the stat:awaiting response Status - Awaiting response from author label Jul 22, 2020
@jason-liew
Copy link
Author

No,it's different.

tensorflow:

 t1 = tf.constant([1,2,3])
 t1_mask = numpy.array([1,0,1])
 tf.boolean_mask(t1,t1_mask) # [1, 3]

pytorch:

p1 = torch.tensor([1,2,3])
p1_mask = torch.tensor([1,0,1])
p1.masked_fill_(p1_mask,5) # [5, 2, 5]

@ravikyram
Copy link
Contributor

@jason-liew

Got it.Thanks!
Are you interested to submit a PR?

@ravikyram ravikyram added comp:apis Highlevel API related issues and removed stat:awaiting response Status - Awaiting response from author labels Jul 22, 2020
@ravikyram ravikyram assigned gowthamkpr and unassigned ravikyram Jul 22, 2020
@gowthamkpr gowthamkpr added comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower and removed comp:apis Highlevel API related issues labels Jul 24, 2020
@aavishkarmishra
Copy link
Contributor

aavishkarmishra commented Jul 26, 2020

@gowthamkpr Hi, I would like to work in this. Can anyone help with how and from where I can start ?

@aavishkarmishra
Copy link
Contributor

aavishkarmishra commented Jul 26, 2020

@gowthamkp Should we have to add a new api or we can also override boolean_mask with one more parameter, which one will be better?

@rohan100jain
Copy link
Member

Strawman proposal. Can this be implemented as

def masked_fill(t, mask, value):
return t * (1 - tf.cast(mask, tf.float32)) + value * tf.cast(mask, tf.float32)

Might have to do some dtype handling but roughly should work? What are the performance requirements for this?

@aavishkarmishra
Copy link
Contributor

@ravikyram @gowthamkpr please review this PR #41975

@fsx950223
Copy link
Member

tf.where([True, False, True],5,[1,2,3])

@alextp
Copy link
Contributor

alextp commented Aug 3, 2020

We recommend the tf.where implementation.

@alextp alextp closed this as completed Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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