Variable length in each batch

i have a dummy data with 2 batches. After padding using pad_sequence, the first batch size was (5,10) however, the second batch size was (5,12) according to the max sequence length in padding.
but, when I use the Linear layer the model expects to find the input_size. In my case, I have a variable input size so what should I do?

Since your first layer seems to be a nn.Linear, I assume you’re implementing a basic MLP model. MLPs – in contrast to RNNs – are not designed to handle sequential data.

You can still use a MLP, though. The common approach would be to push your batch through an nn.Embedding layer, and the average the embedding vectors across each sentence in your batch. Of course, approach treats your input not as a sequence but as a bag of words.

But maybe I’m making the wrong assumption. What exactly are you trying to do?