Let us assume you did not reshape and the original error was about output shape:
Output Batch has a size:
torch.Size([12, 12, 3])
Target Batch has a size
torch.Size([12, 1])
import torch
import torch.nn as nn
ce = nn.CrossEntropyLoss()
a = torch.randn((12,12,3))
b = torch.randn((12,1))
#Expected target size (12, 3), got torch.Size([12, 1])
#print('Input Shape: ', a.shape)
#print('Target Shape: ', b.shape)
#print('Loss: ', ce(a,b))
#This works as I reshape the input batch.
a = torch.randn((12,12,1))
b = torch.randint(0,3,(12,1))
print('Input Shape: ', a.shape)
print('Target Shape: ', b.shape)
print('Loss: ', ce(a,b))
In your original code, can you change “self.out = nn.Linear(hidden_size, 3)” to "self.out = nn.Linear(hidden_size, 1), print the shapes and try?