maxpumperla / hyperas

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization
http://maxpumperla.com/hyperas/
MIT License
2.17k stars 316 forks source link

How to optimize number of LSTM layers using hyperas #215

Closed uttamdhakal closed 5 years ago

uttamdhakal commented 5 years ago

I think the problem lies in return_sequences, if I want to stack LSTM layers return_sequences needs to be True for first LSTM layers but I want to optimize the number of LSTM layers so I don't know how to get around that.

I have this simple model, the program runs for certain iteration(while it checks for other parameters) but throws an error as soon as it tries to test LSTM layers.

    model = Sequential()
    model.add(Embedding(max_words, embedding_dim, input_length=100))
    model.add(LSTM({{choice([16,32,64,128])}}, return_sequences=True))
    model.add(Dropout({{uniform(0, 1)}}))
    if {{choice(['three', 'four'])}} == 'four':
        model.add(LSTM(100))
        model.add(Dropout({{uniform(0, 1)}}))
    model.add(Dense(2, activation='sigmoid'))
maxpumperla commented 5 years ago

so if the choice returns 'three', what you do is connect an LSTM with 3D output to a Dense layer, essentially. try something like

...
else:
    model.add(Flatten())
...

in any case, this isn't really a hyperas problem. I can't take away the work to validate that your network layers "fit together". In any case, next time please provide a stack trace so I can see what fails. better yet, a reproducible example.