import torch y_pred = torch.tensor([ [1, 1, 0, 1, 1, 1] ], dtype=torch.float) y_truth_id = torch.tensor([2], dtype=torch.long) y_truth_id_tmp = y_truth_id.unsqueeze(0) y_truth_one_hot = torch.zeros(y_truth_id_tmp.size(0), 6).scatter_(1, y_truth_id_tmp, 1.) criterion_2 = torch.nn.BCELoss() res_2 = criterion_2(y_pred, y_truth_one_hot) print('BCELoss: ', res_2) # output: BCELoss: tensor(27.6310)