v-mipeng / LexiconNER

Lexicon-based Named Entity Recognition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

about the bnPU loss

YangXuefeng opened this issue · comments

Thanks for the paper and code !

The calculation of risk in bnPU setup is a little confusing.
In the paper, the non-negative makes the Risk = Pi * Prisk + max(0, nRisk)
However, when the nRisk < self.beta, the risk = -self.gamma * nRisk in following code.
Could you please explain why the risk is calculated as this when the nRisk is smaller than a small beta ? I can not match the code with the equations in paper

hP = result.masked_select(torch.from_numpy(postive).byte().cuda()).contiguous().view(-1, 2)
hU = result.masked_select(torch.from_numpy(unlabeled).byte().cuda()).contiguous().view(-1, 2)
if len(hP) > 0:
pRisk = self.model.loss_func(1, hP, args.type)
else:
pRisk = torch.FloatTensor([0]).cuda()
uRisk = self.model.loss_func(0, hU, args.type)
nRisk = uRisk - self.prior * (1 - pRisk)
risk = self.m * pRisk + nRisk

    if args.type == 'bnpu':
        if nRisk < self.beta:
            risk = -self.gamma * nRisk

I think this paper may help.