lonePatient / BERT-NER-Pytorch

Chinese NER(Named Entity Recognition) using BERT(Softmax, CRF, Span)
MIT License
2.06k stars 424 forks source link

DiceLoss 这个公式写的对吗,怎么理解呢 #18

Open LLLLLLoki opened 4 years ago

LLLLLLoki commented 4 years ago
def forward(self,input, target):
    '''
    input: [N, C]
    target: [N, ]
    '''
    prob = torch.softmax(input, dim=1)
    prob = torch.gather(prob, dim=1, index=target.unsqueeze(1))
    dsc_i = 1 - ((1 - prob) * prob) / ((1 - prob) * prob + 1)
    dice_loss = dsc_i.mean()
    return dice_loss

论文中是 DSC(Xi)= (2(1-p)p*y + r)/((1-p)p + y +r)

lvjiujin commented 3 years ago
def forward(self,input, target):
    '''
    input: [N, C]
    target: [N, ]
    '''
    prob = torch.softmax(input, dim=1)
    prob = torch.gather(prob, dim=1, index=target.unsqueeze(1))
    dsc_i = 1 - ((1 - prob) * prob) / ((1 - prob) * prob + 1)
    dice_loss = dsc_i.mean()
    return dice_loss

论文中是 DSC(Xi)= (2(1-p)p*y + r)/((1-p)p + y +r)

代码中没看到用diceloss呀,只有focalloss 和label smoothing.