Hi all,
I’m trying to implement a text classifier using Conv1d. My dilemma is - how do we construct the linear layer to consume the output from the final CNN/MaxPool layers.
I can pad all the sentences in a batch to have the same length as the longest sentence in that batch and set the input to linear layer accordingly but if the next batch has a different seq_len, then I’ll still get an error.
Eg:
batch_size = 2

Batch 1:
[1, 2, 3, 4, 5]
[1, 2, 3, 0, 0]

Batch 2:
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 0, 0, 0]

# The CNN/Maxpool output for both these batches would be different. 
# As a result, when I flatten this out to feed into the linear layer,
# the number of neurons in the linear layer would have to be different. 

The only idea I have right now is to pad all the sentences in my dataset to have the same length(mean/median of sentence lengths) and pad/remove the words from each sentence according to the length criteria.
Is there any other way to get around this?
Edit:
How would we go about implementing:

CNN -> Linear
CNN -> RNN -> Linear