Skip to content
Advertisement

stacking LSTM layer on top of BERT encoder in Keras

I have been trying to stack a single LSTM layer on top of Bert embeddings, but whilst my model starts to train it fails on the last batch and throws the following error message:

JavaScript

This is how I build the model and I honestly cannot figure out what is going wrong here:

JavaScript

this is the full output:

JavaScript

The code runs perfectly fine if I just drop the LSTM and reshape layers – any help is appreciated.

Advertisement

Answer

You should use tf.keras.layers.Reshape in order to reshape bert_output into a 3D tensor and automatically taking into account the batch dimension.

Simply changing:

JavaScript

into:

JavaScript

should work.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement