Reputation: 16587
I have different length input texts, from few character to hundred words so I decided to use different MAX_LENGTH for each batch instead of fix MAX_LENGTH for all batches (obviously shorter MAX_LENGTH for smaller text).
After googling I saw this thread in Keras github page which gave the following solution:
Sequences should be grouped together by length, and segmented manually into batches by that length before being sent to Keras.
If I use this trick, I'll guess there is no way to shuffle data at training time and it might lead to overfitting.
I saw many disscution in Kaggle that use this trick. I want to know is there any other solution for this problem?
Upvotes: 1
Views: 1440
Reputation: 86600
There is the solution of padding your data with a dummy value, so all your input sequences have the same length.
Suppose you have these two sequences:
Then you start your model with a Masking layer.
This will automatically ignore the additional length in the samples.
Upvotes: 4