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

label smoothing inf err #109

Open
jerett opened this issue Apr 10, 2023 · 2 comments
Open

label smoothing inf err #109

jerett opened this issue Apr 10, 2023 · 2 comments

Comments

@jerett
Copy link

jerett commented Apr 10, 2023

when running label smoothing section, I found the code 'crit(x=predict, target=torch.LongTensor([2, 1, 0, 3, 3]))' return inf.
I think the var predict shouldn't add log, for log(0) is -inf. and the loss section draws nothing.

20230410-152051
20230410-152158

@satya400
Copy link

Hi jerett - we need the inputs of KLDivLoss to be in log space. Hence we need to apply log() - The -inf issue is because we have zeros in the tensor. So the log() applied to the predict tensor is creating issue with LabelSmoothing().

Hence I propose to use softmax_log() instead of log()

I also raised a pr.

Thanks
Satya

@alaneuler
Copy link

Same problem here, but i don't think we should use softmax_log instead of log because the predict is already defined as probabilities.

Rather, I changed the predict tensor to:

predict = torch.FloatTensor([[1e-9, x/d - 1e-9, 1/d, 1/d, 1/d]])

to avoid the inf.

The result I get is the same to the example provided:

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