Creating a part of speech LSTM. Not sure how to shape the data if I am batching sentences of similar length.
X.shape = (100, 60, 4), [batch, length of sentence, features per word]
output.shape = (100, 60, 10) [batch, length of sentences, type of word (10 potential types)]
y.shape = (100, 60)
The error I get: Expected target size (100, 10), got torch.Size([100, 60])
Below the code of my network:
import torch.nn as nn
import torch.nn.functional as F


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()

        self.lstm1 = nn.GRU(input_size = 4, hidden_size = 32, bidirectional= True)
        self.fcn1 = nn.Linear(64, 512)
        self.fcn2 = nn.Linear(512, 512)
        self.fcn3 = nn.Linear(512, 10)
        
        self.softmax = nn.LogSoftmax(dim=2)

    def forward(self, x):
        x, _ = self.lstm1(x)
        x = self.fcn1(x)
        x = self.fcn2(x)
        x = self.fcn3(x)
        x =x.squeeze(1)
  
       
        return x


net = Net()
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(net.parameters(), lr=0.0001)

for epoch in range(5000):
    
    optimizer.zero_grad()
    
    running_loss = 0.0
    outputs = net(X)
    print(outputs.shape, y.shape)
    loss = criterion(outputs, y)
    loss.backward()
    optimizer.step()
    running_loss += loss.item()
        
    if epoch % 100 == 0: 
        print("Epoch: ", epoch, "Loss: " , running_loss) 

Thanks for the help !