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

How to use temperature scaling for binary classification using sigmoid? #32

Open
evapachetti opened this issue Jun 14, 2022 · 1 comment

Comments

@evapachetti
Copy link

My network is trained according to a binary classification approach, so the model outputs as a single logit value which I then convert into probability by applying the sigmoid function. How can I modify the temperature scaling code to apply it to my network?

Thank you in advance.

@xchani
Copy link

xchani commented Nov 23, 2022

I think the following approach should work:

  1. Replace the CrossEntropyLoss with BCEWithLogitsLoss
  2. Change the size of self.temperature to number of classes

Sigmoid can be regarded as a special case of softmax where one of the logits is 0: $\frac{e^x}{e^0 + e^x}$. Then we only need to learn the temperature for each class.

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