0

I'm working my way through this Keras tutorial Text classification with movie reviews on the Keras website.

They use a variable max_length which they set to 256. I'm not sure I understand where this is coming from. When I check the max length of all the train_data, I get 2494

max(len(l) for l in train_data) 2494

This tutorial also uses a GlobalAveragePooling1D as its second layer, which I'm also not understanding, since the input if fixed to 256.

If anyone can offer insight, it would be much appreciated.

1 Answer 1

1

Here's a SO question addressing the pad_sequences function that may be helpful. What does Keras.io.preprocessing.sequence.pad_sequences do?

As far as why they chose 256 as the max length...it's arbitrary. They need all the sequences the same length so they selected a reasonable value. And, yes, some will end up being truncated. A histogram of the lengths would give you an idea how many will be truncated. A quick google yields a histogram:

enter image description here

My advice is to work through the tutorial as-is...then try a few different values of that max-length and see how it affects the results. In practice, a value must be selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.