Samuel_Adu:

labels


Thank you very much Raghul.
I have the following:
]:
​
print(inputs.shape)
print(labels.shape)
print(outputs.shape)
torch.Size([100, 4])
torch.Size([100, 1])
torch.Size([100, 1])
Please any suggestion on how to for about this?
input_dim = 4
hidden_dim = 10
output_dim = 1
model = FeedforwardNeuralNetModel(input_dim, hidden_dim, output_dim)
criterion = nn.CrossEntropyLoss()
learning_rate = 0.01
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
#return model, loss_fnc, optimizer

#load_model(0.01)
for epoch in range(num_epochs):
for i, (inputs, labels) in enumerate(train_loader):
# Load inputs as Variable
inputs = Variable(torch.Tensor(inputs.view(-1, 4).float()))
labels = Variable(torch.Tensor(labels.float()))#.type(torch.LongTensor)
    # Clear gradients w.r.t. parameters
    optimizer.zero_grad()
    
    # Forward pass to get output/logits
    outputs = model(inputs.float())
    
    # Calclate Loss: softmax --> cross entropy loss
    
    loss = criterion(outputs.view(-1, 1), labels.type(torch.LongTensor))
    
    # Getting gradients w.r.t. parameters
    loss.backward()
    #loss.backward()
    
    # Updating parameters
    optimizer.step()


RuntimeError                              Traceback (most recent call last)
 in 
97         # Calclate Loss: softmax --> cross entropy loss
98
—> 99         loss = criterion(outputs.view(-1, 1), labels.type(torch.LongTensor))
100
101         # Getting gradients w.r.t. parameters
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
491             result = self._slow_forward(*input, **kwargs)
492         else:
–> 493             result = self.forward(*input, **kwargs)
494         for hook in self._forward_hooks.values():
495             hook_result = hook(self, input, result)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
940     def forward(self, input, target):
941         return F.cross_entropy(input, target, weight=self.weight,
–> 942                                ignore_index=self.ignore_index, reduction=self.reduction)
943
944
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
2054     if size_average is not None or reduce is not None:
2055         reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2056     return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
2057
2058
~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
1869                          .format(input.size(0), target.size(0)))
1870     if dim == 2:
-> 1871         ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
1872     elif dim == 4:
1873         ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: multi-target not supported at …\aten\src\THNN/generic/ClassNLLCriterion.c:20