The input size to an nn.Linear layer is defined in the docs as:

Input: (N,∗,H_in) where *∗ means any number of additional dimensions and H_in=in_features

In your case you would thus pass the input as [batch_size, seq_len, in_features].



 JustAGuysInThailand:

Normally in Keras i just put input_size = (batch, seq_len, no_classes)


Are you sure you are passing the no_classes into the first layer in Keras? This seems like an unneeded limitation unless your model only contains a single layer.



 JustAGuysInThailand:

I think I have to make the target_size as [batch_size, seq_len] so that mean I will not need to convert my level to one-hot encoding as Keras I believe.


Yes, the shape is correct and also one-hot encoded targets are not needed, but the target should contain the class indices.



 JustAGuysInThailand:

But can you so me how to determine the number of sample for each batch? With Keras I just declare the batch_size = no_samples per batch only.


The batch size is not determined in the model (as it’s not depending on the number of samples passed to it) and you could set the desired batch_size in the DataLoader.