I don’t think you can use the index  approach with the current nn.BCE(WithLogits)Loss implementation, since the target is a FloatTensor and thus contains the target for each data sample.
Would you be able to create the right target using scatter?
output = torch.tensor([[0.3416, 0.6336, 0.3775, 0.2556, 0.6288]])
target = torch.zeros_like(output)
target_indices = torch.tensor([[0,2,4]])
target.scatter_(1, target_indices, 1)