NLLLoss function wrt to getting a error of "bool value of tensor with more than one value is ambiguous"

In PyTorch nn.NLLLoss() function, when we apply it directly to calculate loss value wrt input and Target value, we get a error mentioning “bool value of Tensor with more than one value is ambiguous”.
When we mention something like criterion=nn.NLLLoss() and then apply criterion (input,Target) we get the loss tensor output. Any idea why this happens?

Hi Bhargava!

Without seeing you code, I’m only guessing. However …

NLLLoss is a class, instances of which are callable function objects.

(nll_loss is a function.)

My guess is that you are calling the constructor of NLLLoss with your
input and Target tensors. The second argument, size_average to
NLLLoss's constructor is a bool, hence your error.

nn.NLLLoss (input, Target)   # bad -- calling constructor incorrectly
nn.NLLLoss() (input, Target)   # good -- calling a default-constructed function object correctly
nn.functional.nll_loss (input, Target)   # good -- calling ordinary function

Good luck!

K. Frank