Activation for LSTM binary classification

361 views
Skip to first unread message

DSA

unread,
Jul 9, 2016, 6:10:52 PM7/9/16
to Keras-users
Hi all - what LSTM layer activation should I use for binary sequence classification using LSTM?

One Keras example explicitly specifies sigmoid, but another Keras example does not specify activation, meaning the default tanh will be used. 

Thanks!

Sequence classification with LSTM:

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers import Embedding
from keras.layers import LSTM

model = Sequential()
model.add(Embedding(max_features, 256, input_length=maxlen))
model.add(LSTM(output_dim=128, activation='sigmoid', inner_activation='hard_sigmoid'))

Stacked LSTM for sequence classification


from keras.models import Sequential
from keras.layers import LSTM, Dense
import numpy as np

data_dim = 16
timesteps = 8
nb_classes = 10

# expected input data shape: (batch_size, timesteps, data_dim)
model = Sequential()
model.add(LSTM(32, return_sequences=True,
               input_shape=(timesteps, data_dim)))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32, return_sequences=True))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32))  # return a single vector of dimension 32

lins...@gmail.com

unread,
Jul 11, 2016, 4:16:54 AM7/11/16
to Keras-users
I have the same question. My experience is that adjusting the activation function greatly improved my classification performance and convergence rate. I don't know the reason though.
Reply all
Reply to author
Forward
0 new messages