If your batch size is 12, sequence length is 10 and number of your classes is 3; your output before passing it loss fn should have dimension [batch_size, n_classes, seq_len] and your target should have dimension [batch_size, seq_len]. An example: [12, 3, 10] and [12, 10]. It is okey to pass this to nn.CrossEntropyLoss without any flattening.
If you have batch size at dimension 1; y_pred: [10,12,3] and target: [10,12,1], you can pass it like criterion(y_pred.permute(1,2,0), target.permute(1,2,0).squeeze(1))
print(y_pred.permute(1,2,0).shape)
# torch.Size([12, 3, 10])

print(target.permute(1,2,0).squeeze(1))
# torch.Size([12, 10])

After organizing your shapes, you can get your highest probability classes with
print(y_pred.permute(1,2,0).shape)
# torch.Size([12, 3, 10])

argmax_preds = torch.argmax(y_pred.permute(1,2,0), dim=1)

Then calculate your accuracy:
accuracy = (argmax_preds == target).cpu().numpy().mean() * 100