That looks incorrect. The easiest way to solve it is to reshape your output and target to tensors to (bs * n, c) and (bs *n) where bs is the batch size, n the same as your n and c the number of classes:
labels = labels.reshape(-1)
outputs = outputs.reshape(outputs.shape[0] * outputs.shape[1], -1)

Then you compute the normal cross entropy loss:
loss_fn = CrossEntropyLoss()
loss = loss_fn(outputs, labels)

There is also a multi-dimensional version of CrossEntropyLoss, but unless your dimensions are in the order it expects, the ordinary one is easier to use.