Hi,
I know this problem have been addressed many times but I cannot find any answers so I’m trying again. I’m building a LSTM classifier to predict a class based on a text. The issue is that my validation accuracy stagnate around 35%.
I’m wondering if it’s my model or my data prepation which is not working. Does my model looks correct for you or do I miss something? Thanks !
class LSTMClassifier(nn.Module):
    def __init__(self, vocab_size, embedding_dim, hidden_dim, label_size, padding_idx, batch_size):
        super(LSTMClassifier, self).__init__()
        self.vocab_size = vocab_size
        self.embedding_dim = embedding_dim
        self.hidden_dim = hidden_dim
        self.label_size = label_size
        self.num_layers = 1
        self.batch_size = batch_size

        self.emb = nn.Embedding(self.vocab_size, self.embedding_dim, padding_idx=padding_idx)
        self.lstm = nn.LSTM(embedding_dim, hidden_dim)#,batch_first=True)
        self.fc = nn.Linear(hidden_dim, label_size)

    def zero_state(self, batch_size): 
        # implement the function, which returns an initial hidden state.
        h0 = torch.zeros(self.num_layers, batch_size, self.hidden_dim).cuda()
        c0 = torch.zeros(self.num_layers, batch_size, self.hidden_dim).cuda()
        return h0, c0
    
    def forward(self, x):
        x = self.emb(x)
        batch_size = x.size(1)
        h0, c0 = self.zero_state(batch_size)
        out, (hn, cn) = self.lstm(x, (h0, c0))
        out = self.fc(hn[-1, :, :])
        return out