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

Sparse losses return nan when there is -inf in the input #9

Open
erickrf opened this issue Sep 30, 2019 · 2 comments
Open

Sparse losses return nan when there is -inf in the input #9

erickrf opened this issue Sep 30, 2019 · 2 comments

Comments

@erickrf
Copy link

erickrf commented Sep 30, 2019

The sparse loss functions (and their equivalent classes) return nans when there is -inf in the input.

Example:

import torch
import numpy as np
from entmax import entmax15_loss, sparsemax_loss
x = torch.rand(10, 5)
y = torch.randint(0, 4, [10])
x[:, 4] = -np.inf
entmax15_loss(x, y) 
# tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

sparsemax_loss(x, y)
# tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])
@bpopeters
Copy link
Collaborator

https://github.com/deep-spin/entmax/blob/master/entmax/losses.py#L44

If anything in X is non-finite, it looks to me like this line will cause problems.

@vene
Copy link
Contributor

vene commented Sep 30, 2019

good catch!

That line was a bit faster in my quick experiments when compared to other approaches but it should be avoidable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants