Search code examples
pythonmachine-learninglstm

name 'Bidirectional' is not defined


Im following this tutorial and right when I want to initialize a sequential keras, like the code below:

model = keras.Sequential()
model.add(Bidirectional(
    CuDNNLSTM(Win_size, return_sequences=True),
    input_shape=(Win_size, X_train.shape[-1])))

I get an error saying :

NameError: name 'Bidirectional' is not defined

What is the problem ? it is the exact same code as in the tutorial.


Solution

  • You’re most likely missing the import statement from the tensorflow package.

    It appears that’s there is a link to the source code in that article which shows the full import statement.

    from tensorflow.keras.layers import Bidirectional
    

    Keep in mind that the source code linked includes more imports but this would be directly related to the error you mentioned.