In this recipe, we will learn how Keras can be used for sequence padding. Padding is useful when sequences are sent in batches to the LSTM network.Â
Sequence padding
Getting ready
Import the function:
from keras.preprocessing.sequence import pad_sequences
pad_sequences is a function defined as follows:
pad_sequences(sequences, maxlen=None, dtype='int32', padding='pre', truncating='pre', value=0.0)
How to do it...
Let's look at the various padding options.