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

Improve Numerical Stability of Function calc_loss #23

Open
ZaydH opened this issue Jan 23, 2021 · 1 comment · May be fixed by #24
Open

Improve Numerical Stability of Function calc_loss #23

ZaydH opened this issue Jan 23, 2021 · 1 comment · May be fixed by #24

Comments

@ZaydH
Copy link
Contributor

ZaydH commented Jan 23, 2021

Summary: We can improve the numerical stability/accuracy of the calc_loss method.

The current implementation uses the following:

def calc_loss(y, t):
    y = torch.nn.functional.log_softmax(y)
    loss = torch.nn.functional.nll_loss(
        y, t, weight=None, reduction='mean')
    return loss

PyTorch includes a single functional that is numerically more stable cross_entropy. It would also simplify the above code to:

def calc_loss(y, t):
    loss = torch.nn.functional.cross_entropy(y, t, weight=None, reduction="mean")
    return loss
@ZaydH ZaydH changed the title Improve Numerical Stability of calc_loss Improve Numerical Stability of Function calc_loss Jan 23, 2021
ZaydH added a commit to ZaydH/pytorch_influence_functions that referenced this issue Jan 23, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…tropy.
@pomonam
Copy link

pomonam commented Jan 23, 2021

I thought cross_entropy just combines log_softmax and nll_loss.

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