This error is usually thrown, if your target still contains the class dimension:
criterion = nn.NLLLoss()

N, nb_classes = 2, 3
output = torch.randn(N, nb_classes, requires_grad=True)
target = torch.randint(0, nb_classes, (N,))

loss = criterion(output, target) # works

target = torch.randint(0, nb_classes, (N, nb_classes))
loss = criterion(output, target) # fails with same error

For a multi-label classification (a single sample can contain more than a single valid class), you should use nn.BCEWithLogitsLoss (or the C++ equivalent).