def loss_function(p, y, b):
—losses = 0
—for i in range(b):
------temp_p = torch.tensor(p[i])
------temp_y = torch.tensor(y[i])
------k = len(temp_y)
------loss1 = -(torch.ones(k).cuda()- temp_y)@((torch.ones(k).cuda()-temp_p).log())
------l = temp_y*(temp_p.log())
------prod = (torch.ones(k).cuda()-temp_y) - l
------loss2 = loss1 + torch.max(torch.ones(k).cuda()-
prod)
------losses = loss1 + loss2
—f = (losses/(b))
—return Variable(torch.FloatTensor([f]))