I am training an LSTM in Keras:
iclf = Sequential()
iclf.add(Bidirectional(LSTM(units=10, return_sequences=True, recurrent_dropout=0.3), input_shape=(None,2048)))
iclf.add(TimeDistributed(Dense(1, activation='sigmoid')))
The input to each cell is a 2048 vector which is known and need not to be learned (if you will, they are the ELMo embeddings of the words in the input sentences). Therefore, here I have not the Embedding layer.
Since the input sequences have variable lengths, they are padded using pad_sequences
:
X = pad_sequences(sequences=X, padding='post', truncating='post', value=0.0, dtype='float32')
Now, I want to tell the LSTM to ignore these padded elements. The official way is to use the Embedding layer with mask_zero=True
. But, here there is no Embedding layer. How can I inform the LSTM to mask zero elements?