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

数值不稳定问题 #7

Closed
yangwei-nlp opened this issue Sep 28, 2020 · 1 comment
Closed

数值不稳定问题 #7

yangwei-nlp opened this issue Sep 28, 2020 · 1 comment

Comments

@yangwei-nlp
Copy link

由于数值溢出问题,当preds中错误类别的数值绝对值特别大的时候,loss容易计算得到inf

建议不要采用softmax+log,采用log_softmax+exp会更好。

preds_softmax = F.softmax(preds, dim=1) # 这里并没有直接使用log_softmax, 因为后面会用到softmax的结果(当然你也可以使用log_softmax,然后进行exp操作)
preds_logsoft = torch.log(preds_softmax)

@yatengLG
Copy link
Owner

好的,谢谢。

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

2 participants