I am now dealing with string classification, and I want to use LSTM, but I have some questions about setting time_step. My data set looks like:
Data ----- Label DKWL----0 FCHN----0 KDQP----0 IHGS----1 ....
then I convert it into binary code:
00011101000001000111-----1 ..... shape:(N,20)
Now I build LSTM:
class RNN(nn.Module): def __init__(self): super(RNN, self).__init__() self.rnn = nn.LSTM( input_size=20, # Each sample has 20 features hidden_size=64, num_layers=1, batch_first=True, ) self.out = nn.Linear(64, 2) # I set output 2, because there are two classes 0 & 1 def forward(self, x): r_out, (h_n, h_c) = self.rnn(x, None) out = self.out(r_out[:, -1, :]) return out
Then I try to train it with following codes:
for epoch in range(EPOCH): for step, (x, b_y) in enumerate(train_loader): # gives batch data b_x = x.view(-1, ?, 20) # at this step I need to reshape x to # (batch, time_step, input_size), but how I set this # time_step? 0 or 1? output = rnn(b_x) loss = loss_func(output, b_y) optimizer.zero_grad() loss.backward() optimizer.step()
Thanks in advance.