Hi,
I am a newbie in PyTorch.
I am trying to implement a multi-label classifier using MultiLabelMarginLoss() as the loss function.

INPUT_DIM = 74255
NUM_OF_CATEGORIES = 20
NUM_OF_HIDDEN_NODE = 64


class HDNet(nn.Module):

def _init_(self):

super(HDNet, self)._init_()
self.hidden_1 = nn.Linear(INPUT_DIM, NUM_OF_HIDDEN_NODE)
self.out_1   = nn.Linear(NUM_OF_HIDDEN_NODE, NUM_OF_CATEGORIES)





def forward(self, x):

x = F.relu(self.hidden_1(x))
y_out = F.softmax(self.out_1(x))
return y_out




model = HDNet()
loss_function = nn.MultiLabelMarginLoss()
optimizer = optim.SGD(model.parameters(), lr=0.01)
for input_vec, y_true in training_data:

model.zero_grad()
input_vec = torch.from_numpy(input_vec).float()
input_vec = autograd.Variable(input_vec.view(1,-1))
y_true = autograd.Variable(torch.LongTensor([y_true]))
y_pred = model(input_vec)
loss = loss_function(y_pred, y_true)
loss.backward()
optimizer.step()


y_true is a 1X2 variable
Variable containing:
4  8
[torch.LongTensor of size 1x2]
y_pred is a 1 X 20 variable
Variable containing:
Columns 0 to 9
1.00000e-02 *
4.9148  4.8022  4.5980  4.6124  5.1000  5.4152  4.8912  5.4974  4.4172  5.2499
Columns 10 to 19
1.00000e-02 *
5.0587  4.4383  4.9150  5.5286  5.0351  5.4916  5.1233  4.4147  4.8744  5.6221
[torch.FloatTensor of size 1x20]
I’m getting the following error:

Traceback (most recent call last):
File “training_hierarchy_v3.py”, line 139, in 
loss = loss_function(y_pred, y_true)
File “/Library/Python/2.7/site-packages/torch/nn/modules/module.py”, line 224, in call
result = self.forward(*input, **kwargs)
File “/Library/Python/2.7/site-packages/torch/nn/modules/loss.py”, line 384, in forward
return F.multilabel_margin_loss(input, target, size_average=self.size_average)
File “/Library/Python/2.7/site-packages/torch/nn/functional.py”, line 831, in multilabel_margin_loss
return _functions.thnn.MultiLabelMarginLoss.apply(input, target, size_average)
File “/Library/Python/2.7/site-packages/torch/nn/_functions/thnn/auto.py”, line 47, in forward
output, *ctx.additional_args)
RuntimeError: invalid argument 3: inconsistent target size at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/THNN/generic/MultiLabelMarginCriterion.c:35