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

Logits vs Log-softmax scores in LearnedMixin implementation #1

Open
erobic opened this issue May 22, 2020 · 1 comment
Open

Logits vs Log-softmax scores in LearnedMixin implementation #1

erobic opened this issue May 22, 2020 · 1 comment

Comments

@erobic
Copy link

erobic commented May 22, 2020

Hi,

I had a question regarding the PyTorch implementation of LearnedMixin.

class LearnedMixin(ClfDebiasLossFunction):

def forward(self, hidden, logits, bias, labels):
    logits = logits.float()  # In case we were in fp16 mode
    logits = F.log_softmax(logits, 1)

    factor = self.bias_lin.forward(hidden)
    factor = factor.float()
    factor = F.softplus(factor)

    bias = bias * factor

    bias_lp = F.log_softmax(bias, 1)
    entropy = -(torch.exp(bias_lp) * bias_lp).sum(1).mean(0)

    loss = F.cross_entropy(logits + bias, labels) + self.penalty*entropy
    return loss

The forward function adds logits and bias variables, however, logits has been log-softmaxed whereas bias is not (bias seems to be raw logits from bias-only model). Should we really apply log-softmax to logits before sending into cross_entropy loss? Could you explain the reasoning behind this?

@ddemszky
Copy link

ddemszky commented Oct 1, 2020

Following up, as I have the same question. :) Thanks!

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