Although, I’m not too familiar with the workings of RNNs, your implementation looks correct.
CrossEntropyLoss expects a input of dim = (N, C) and a target of dim = (N,). Additional dimensions are used for “K-dimensional loss” as stated in the docs 2. Since your output batch is of dim (12, 12, 3), the target expected shape is (12, 3), but your targets are (12, 1), which explains your error. You need to perform 2 reshapes:
The first one is
output_batch = output_batch[:, -1, :]

It works, but I have no idea why this specific “reshape”. Here’s a link to an RNN Implementation for MNIST where I looked it up.
The second one is
x_target_batch = x_target_batch.view(-1)

This one is to satisfy the target shape required for the loss function.