I have a multi-label classification problem, the total number of labels are extremely huge which is 111,556, so I am planning to use sparse vector to save the one-hot version of labels. However, I find that there is no multi-label loss function which is supporting sparse vector. Below is example code.
So how to solve this problems? Thanks.
import torch
i = torch.LongTensor([[0,1],[0,12]])
v = torch.FloatTensor([1, 1])
i_predict = torch.LongTensor([[0,2],[0,12]])
v_predict = torch.FloatTensor([1, 1])
predict = torch.sparse.FloatTensor(i_predict.t(), v_predict, torch.Size([1,111556]))
target = torch.sparse.FloatTensor(i.t(), v, torch.Size([1, 111556]))
criterion = torch.nn.BCELoss()
loss = criterion(predict, target)
print loss
if input.nelement() != target.nelement():
1476         raise ValueError("Target and input must have the same number of elements. target nelement ({}) "
1477                          “!= input nelement ({})”.format(target.nelement(), input.nelement()))
RuntimeError: numel is not implemented for type torch.sparse.FloatTensor